[llvm] r346686 - Fix MachineInstr::findRegisterUseOperandIdx subreg checks
Stanislav Mekhanoshin via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 12 10:12:28 PST 2018
Author: rampitec
Date: Mon Nov 12 10:12:28 2018
New Revision: 346686
URL: http://llvm.org/viewvc/llvm-project?rev=346686&view=rev
Log:
Fix MachineInstr::findRegisterUseOperandIdx subreg checks
The function only checks that instruction reads a super-register
containing requested physical register. In case if a sub-register
if being read that is also a use of a super-reg, so added the check.
In particular MI->readsRegister() is broken because of the missing
check. The resulting check is essentially regsOverlap().
Differential Revision: https://reviews.llvm.org/D54128
Modified:
llvm/trunk/lib/CodeGen/MachineInstr.cpp
llvm/trunk/test/CodeGen/AMDGPU/optimize-if-exec-masking.mir
Modified: llvm/trunk/lib/CodeGen/MachineInstr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineInstr.cpp?rev=346686&r1=346685&r2=346686&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineInstr.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineInstr.cpp Mon Nov 12 10:12:28 2018
@@ -933,9 +933,7 @@ int MachineInstr::findRegisterUseOperand
unsigned MOReg = MO.getReg();
if (!MOReg)
continue;
- if (MOReg == Reg || (TRI && TargetRegisterInfo::isPhysicalRegister(MOReg) &&
- TargetRegisterInfo::isPhysicalRegister(Reg) &&
- TRI->isSubRegister(MOReg, Reg)))
+ if (MOReg == Reg || (TRI && Reg && MOReg && TRI->regsOverlap(MOReg, Reg)))
if (!isKill || MO.isKill())
return i;
}
Modified: llvm/trunk/test/CodeGen/AMDGPU/optimize-if-exec-masking.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AMDGPU/optimize-if-exec-masking.mir?rev=346686&r1=346685&r2=346686&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AMDGPU/optimize-if-exec-masking.mir (original)
+++ llvm/trunk/test/CodeGen/AMDGPU/optimize-if-exec-masking.mir Mon Nov 12 10:12:28 2018
@@ -112,6 +112,17 @@
ret void
}
+ define amdgpu_kernel void @if_and_xor_read_exec_copy_subreg() {
+ main_body:
+ br i1 undef, label %if, label %end
+
+ if: ; preds = %main_body
+ br label %end
+
+ end: ; preds = %if, %main_body
+ ret void
+ }
+
...
---
# CHECK-LABEL: name: optimize_if_and_saveexec_xor{{$}}
@@ -501,3 +512,41 @@ body: |
S_ENDPGM
...
+---
+# A read from exec copy subreg prevents optimization
+# CHECK-LABEL: name: if_and_xor_read_exec_copy_subreg{{$}}
+# CHECK: $sgpr0_sgpr1 = COPY $exec
+# CHECK-NEXT: $sgpr4 = S_MOV_B32 $sgpr1
+name: if_and_xor_read_exec_copy_subreg
+liveins:
+ - { reg: '$vgpr0' }
+body: |
+ bb.0.main_body:
+ liveins: $vgpr0
+
+ $sgpr0_sgpr1 = COPY $exec
+ $sgpr4 = S_MOV_B32 $sgpr1
+ $vcc = V_CMP_EQ_I32_e64 0, killed $vgpr0, implicit $exec
+ $vgpr0 = V_MOV_B32_e32 4, implicit $exec
+ $sgpr2_sgpr3 = S_AND_B64 $sgpr0_sgpr1, killed $vcc, implicit-def $scc
+ $sgpr0_sgpr1 = S_XOR_B64 $sgpr2_sgpr3, killed $sgpr0_sgpr1, implicit-def $scc
+ $exec = S_MOV_B64_term killed $sgpr2_sgpr3
+ SI_MASK_BRANCH %bb.2, implicit $exec
+ S_BRANCH %bb.1
+
+ bb.1.if:
+ liveins: $sgpr0_sgpr1
+
+ $sgpr7 = S_MOV_B32 61440
+ $sgpr6 = S_MOV_B32 -1
+ $vgpr0 = BUFFER_LOAD_DWORD_OFFSET $sgpr4_sgpr5_sgpr6_sgpr7, 0, 0, 0, 0, 0, implicit $exec
+
+ bb.2.end:
+ liveins: $vgpr0, $sgpr0_sgpr1
+
+ $exec = S_OR_B64 $exec, killed $sgpr0_sgpr1, implicit-def $scc
+ $sgpr3 = S_MOV_B32 61440
+ $sgpr2 = S_MOV_B32 -1
+ BUFFER_STORE_DWORD_OFFSET killed $vgpr0, $sgpr0_sgpr1_sgpr2_sgpr3, 0, 0, 0, 0, 0, implicit $exec
+ S_ENDPGM
+...
More information about the llvm-commits
mailing list