Files
clang-p2996/llvm/test/CodeGen/AVR/neg.ll
Ayke van Laethem bbfef8ac95 [AVR] Fix expansion of NEGW
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:

    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.

Differential Revision: https://reviews.llvm.org/D97131
2021-03-03 15:36:05 +01:00

23 lines
492 B
LLVM

; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple=avr | FileCheck %s
define i8 @neg8(i8 %x) {
; CHECK-LABEL: neg8:
; CHECK: ; %bb.0:
; CHECK-NEXT: neg r24
; CHECK-NEXT: ret
%sub = sub i8 0, %x
ret i8 %sub
}
define i16 @neg16(i16 %x) {
; CHECK-LABEL: neg16:
; CHECK: ; %bb.0:
; CHECK-NEXT: neg r25
; CHECK-NEXT: neg r24
; CHECK-NEXT: sbc r25, r1
; CHECK-NEXT: ret
%sub = sub i16 0, %x
ret i16 %sub
}