]> granicus.if.org Git - llvm/commitdiff
AMDGPU/GlobalISel: Avoid creating shift of 0 in arg lowering
authorMatt Arsenault <Matthew.Arsenault@amd.com>
Tue, 1 Oct 2019 01:44:46 +0000 (01:44 +0000)
committerMatt Arsenault <Matthew.Arsenault@amd.com>
Tue, 1 Oct 2019 01:44:46 +0000 (01:44 +0000)
This is sort of papering over the fact that we don't run a combiner
anywhere, but avoiding creating 2 instructions in the first place is
easy.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@373293 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.workitem.id.ll

index 40d95dcef0cb937ab9f49ffcaa834e2880e70dc8..e289e8e689a5d6e0ed2293949f37e0c187465ceb 100644 (file)
@@ -1717,9 +1717,14 @@ bool AMDGPULegalizerInfo::loadInputValue(Register DstReg, MachineIRBuilder &B,
     const unsigned Mask = Arg->getMask();
     const unsigned Shift = countTrailingZeros<unsigned>(Mask);
 
-    auto ShiftAmt = B.buildConstant(S32, Shift);
-    auto LShr = B.buildLShr(S32, LiveIn, ShiftAmt);
-    B.buildAnd(DstReg, LShr, B.buildConstant(S32, Mask >> Shift));
+    Register AndMaskSrc = LiveIn;
+
+    if (Shift != 0) {
+      auto ShiftAmt = B.buildConstant(S32, Shift);
+      AndMaskSrc = B.buildLShr(S32, LiveIn, ShiftAmt).getReg(0);
+    }
+
+    B.buildAnd(DstReg, AndMaskSrc, B.buildConstant(S32, Mask >> Shift));
   } else
     B.buildCopy(DstReg, LiveIn);
 
index fb5f881ad85318afae057868cdedd181126c48cf..946a138bee4f2305bf866f82ff21feb8274ed384 100644 (file)
@@ -89,7 +89,7 @@ bb2:
 }
 
 ; ALL-LABEL: {{^}}test_workitem_id_x_func:
-; ALL: v_lshrrev_b32_e32 v2, 0, v2
+; ALL: s_waitcnt
 ; ALL-NEXT: v_and_b32_e32 v2, 0x3ff, v2
 define void @test_workitem_id_x_func(i32 addrspace(1)* %out) #1 {
   %id = call i32 @llvm.amdgcn.workitem.id.x()