[PATCH] D97131: [AVR] Fix expansion of NEGW
Ayke via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 20 16:39:15 PST 2021
aykevl created this revision.
aykevl added reviewers: dylanmckay, benshi001.
Herald added subscribers: Jim, hiraditya.
aykevl requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The previous expansion used SBCI, which is incorrect because the NEGW pseudo instruction accepts a DREGS operand (2xGPR8) and SBCI only allows LD8 registers. One solution could be to correct the NEGW pseudo instruction, but another solution is to use a different instruction (sbc) that does accept a GPR8 register and therefore allows more freedom to the register allocator.
The output now matches avr-gcc for the following code:
c
int foo(int n) {
return -n;
}
I've found this issue using the machine instruction verifier: it was complaining about the wrong register class in NEGWRd.mir.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D97131
Files:
llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp
llvm/lib/Target/AVR/AVRInstrInfo.td
llvm/test/CodeGen/AVR/neg.ll
llvm/test/CodeGen/AVR/pseudo/NEGWRd.mir
Index: llvm/test/CodeGen/AVR/pseudo/NEGWRd.mir
===================================================================
--- llvm/test/CodeGen/AVR/pseudo/NEGWRd.mir
+++ llvm/test/CodeGen/AVR/pseudo/NEGWRd.mir
@@ -19,7 +19,7 @@
; CHECK: $r15 = NEGRd $r15, implicit-def dead $sreg
; CHECK-NEXT: $r14 = NEGRd $r14
- ; CHECK-NEXT: $r15 = SBCIRdK $r15, 0, implicit-def $sreg, implicit killed $sreg
+ ; CHECK-NEXT: $r15 = SBCRdRr $r15, $r1, implicit-def $sreg, implicit killed $sreg
$r15r14 = NEGWRd $r15r14, implicit-def $sreg
...
Index: llvm/test/CodeGen/AVR/neg.ll
===================================================================
--- llvm/test/CodeGen/AVR/neg.ll
+++ llvm/test/CodeGen/AVR/neg.ll
@@ -15,7 +15,7 @@
; CHECK: ; %bb.0:
; CHECK-NEXT: neg r25
; CHECK-NEXT: neg r24
-; CHECK-NEXT: sbci r25, 0
+; CHECK-NEXT: sbc r25, r1
; CHECK-NEXT: ret
%sub = sub i16 0, %x
ret i16 %sub
Index: llvm/lib/Target/AVR/AVRInstrInfo.td
===================================================================
--- llvm/lib/Target/AVR/AVRInstrInfo.td
+++ llvm/lib/Target/AVR/AVRInstrInfo.td
@@ -757,7 +757,7 @@
// Expands to:
// neg Rd+1
// neg Rd
- // sbci Rd+1, 0
+ // sbc Rd+1, r1
def NEGWRd : Pseudo<(outs DREGS:$rd),
(ins DREGS:$src),
"negw\t$rd",
Index: llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp
===================================================================
--- llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp
+++ llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp
@@ -438,12 +438,12 @@
.addReg(DstLoReg, RegState::Define | getDeadRegState(DstIsDead))
.addReg(DstLoReg, getKillRegState(DstIsKill));
- // Do an extra SBCI.
+ // Do an extra SBC.
auto MISBCI =
- buildMI(MBB, MBBI, AVR::SBCIRdK)
+ buildMI(MBB, MBBI, AVR::SBCRdRr)
.addReg(DstHiReg, RegState::Define | getDeadRegState(DstIsDead))
.addReg(DstHiReg, getKillRegState(DstIsKill))
- .addImm(0);
+ .addReg(ZERO_REGISTER);
if (ImpIsDead)
MISBCI->getOperand(3).setIsDead();
// SREG is always implicitly killed
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97131.325258.patch
Type: text/x-patch
Size: 2151 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210221/92cccb91/attachment-0001.bin>
More information about the llvm-commits
mailing list