Skip to content

Commit

Permalink
Fix MachineInstr::findRegisterUseOperandIdx subreg checks
Browse files Browse the repository at this point in the history
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

llvm-svn: 346686
  • Loading branch information
rampitec committed Nov 12, 2018
1 parent dbf552c commit 5f95131
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
4 changes: 1 addition & 3 deletions llvm/lib/CodeGen/MachineInstr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -933,9 +933,7 @@ int MachineInstr::findRegisterUseOperandIdx(
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;
}
Expand Down
49 changes: 49 additions & 0 deletions llvm/test/CodeGen/AMDGPU/optimize-if-exec-masking.mir
Original file line number Diff line number Diff line change
Expand Up @@ -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{{$}}
Expand Down Expand Up @@ -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
...

0 comments on commit 5f95131

Please sign in to comment.