Skip to content

Commit

Permalink
AMDGPU: Implement computeKnownBitsForTargetNode for mbcnt
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318100 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
arsenm committed Nov 13, 2017
1 parent 438d60f commit 12d09b0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
14 changes: 14 additions & 0 deletions lib/Target/AMDGPU/AMDGPUISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4084,6 +4084,20 @@ void AMDGPUTargetLowering::computeKnownBitsForTargetNode(
Known.Zero.setHighBits(32 - MaxValBits);
break;
}
case ISD::INTRINSIC_WO_CHAIN: {
unsigned IID = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
switch (IID) {
case Intrinsic::amdgcn_mbcnt_lo:
case Intrinsic::amdgcn_mbcnt_hi: {
// These return at most the wavefront size - 1.
unsigned Size = Op.getValueType().getSizeInBits();
Known.Zero.setHighBits(Size - Subtarget->getWavefrontSizeLog2());
break;
}
default:
break;
}
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions lib/Target/AMDGPU/AMDGPUSubtarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ class AMDGPUSubtarget : public AMDGPUGenSubtargetInfo {
return WavefrontSize;
}

unsigned getWavefrontSizeLog2() const {
return Log2_32(WavefrontSize);
}

int getLocalMemorySize() const {
return LocalMemorySize;
}
Expand Down
4 changes: 2 additions & 2 deletions test/CodeGen/AMDGPU/array-ptr-calc-i64.ll
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ declare i32 @llvm.amdgcn.mbcnt.lo(i32, i32) #0
declare i32 @llvm.amdgcn.mbcnt.hi(i32, i32) #0

; SI-LABEL: {{^}}test_array_ptr_calc:
; SI-DAG: v_mul_lo_i32
; SI-DAG: v_mul_hi_i32
; SI-DAG: v_mul_u32_u24
; SI-DAG: v_mul_hi_u32_u24
; SI: s_endpgm
define amdgpu_kernel void @test_array_ptr_calc(i32 addrspace(1)* noalias %out, [1025 x i32] addrspace(1)* noalias %inA, i32 addrspace(1)* noalias %inB) {
%mbcnt.lo = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0)
Expand Down
18 changes: 18 additions & 0 deletions test/CodeGen/AMDGPU/llvm.amdgcn.mbcnt.ll
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ main_body:
ret void
}

; GCN-LABEL: {{^}}mbcnt_lo_known_bits:
; GCN: v_mbcnt_lo_u32_b32
; GCN-NOT: and
define i32 @mbcnt_lo_known_bits(i32 %x, i32 %y) #0 {
%lo = call i32 @llvm.amdgcn.mbcnt.lo(i32 %x, i32 %y)
%mask = and i32 %lo, 63
ret i32 %mask
}

; GCN-LABEL: {{^}}mbcnt_hi_known_bits:
; GCN: v_mbcnt_hi_u32_b32
; GCN-NOT: and
define i32 @mbcnt_hi_known_bits(i32 %x, i32 %y) #0 {
%hi = call i32 @llvm.amdgcn.mbcnt.hi(i32 %x, i32 %y)
%mask = and i32 %hi, 63
ret i32 %mask
}

declare i32 @llvm.amdgcn.mbcnt.lo(i32, i32) #0
declare i32 @llvm.amdgcn.mbcnt.hi(i32, i32) #0
declare void @llvm.amdgcn.exp.f32(i32, i32, float, float, float, float, i1, i1) #1
Expand Down

0 comments on commit 12d09b0

Please sign in to comment.