Skip to content

Commit 4dd5d96

Browse files
authored
[RISCV] Don't call use_nodbg_operands for physical registers in RISCVOptWInstrs hasAllNBitUsers. (#77032)
The ADDIW in the new test case was incorrectly removed due to incorrectly following the x10 register from the return value back to the argument. This is due to use_nodbg_operands returning every instruction that uses a physical register regardless of the data flow.
1 parent c49965b commit 4dd5d96

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

llvm/lib/Target/RISCV/RISCVOptWInstrs.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ static bool hasAllNBitUsers(const MachineInstr &OrigMI,
126126
if (MI->getNumExplicitDefs() != 1)
127127
return false;
128128

129-
for (auto &UserOp : MRI.use_nodbg_operands(MI->getOperand(0).getReg())) {
129+
Register DestReg = MI->getOperand(0).getReg();
130+
if (!DestReg.isVirtual())
131+
return false;
132+
133+
for (auto &UserOp : MRI.use_nodbg_operands(DestReg)) {
130134
const MachineInstr *UserMI = UserOp.getParent();
131135
unsigned OpIdx = UserOp.getOperandNo();
132136

llvm/test/CodeGen/RISCV/opt-w-instrs.mir

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,23 @@ body: |
2828
$x11 = COPY %4
2929
PseudoRET
3030
...
31+
32+
---
33+
name: physreg
34+
tracksRegLiveness: true
35+
body: |
36+
bb.0.entry:
37+
liveins: $x10, $x11
38+
39+
; CHECK-ZFA-LABEL: name: physreg
40+
; CHECK-ZFA: liveins: $x10, $x11
41+
; CHECK-ZFA-NEXT: {{ $}}
42+
; CHECK-ZFA-NEXT: [[COPY:%[0-9]+]]:gpr = COPY $x10
43+
; CHECK-ZFA-NEXT: [[ADDIW:%[0-9]+]]:gpr = ADDIW [[COPY]], 0
44+
; CHECK-ZFA-NEXT: $x10 = COPY [[ADDIW]]
45+
; CHECK-ZFA-NEXT: PseudoRET
46+
%0:gpr = COPY $x10
47+
%1:gpr = ADDIW %0, 0
48+
$x10 = COPY %1
49+
PseudoRET
50+
...

0 commit comments

Comments
 (0)