Skip to content

Commit 7cd01af

Browse files
committed
[RISCV][GISel] Add test showing missed opportunity to use X0 for the LHS of sub for negate.
I had to disable the late copy propagation pass that can see through the ADDI we were previously emitting. We really want to get this in the register coalescer if not even earlier.
1 parent 12ee3a6 commit 7cd01af

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

llvm/test/CodeGen/RISCV/GlobalISel/alu-roundtrip.ll

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
22
; RUN: llc -mtriple=riscv32 -mattr=+m -global-isel -verify-machineinstrs < %s \
3-
; RUN: | FileCheck %s --check-prefix=RV32IM
3+
; RUN: -riscv-enable-copy-propagation=false | FileCheck %s --check-prefix=RV32IM
44
; RUN: llc -mtriple=riscv64 -mattr=+m -global-isel -verify-machineinstrs < %s \
5-
; RUN: | FileCheck %s --check-prefix=RV64IM
5+
; RUN: -riscv-enable-copy-propagation=false | FileCheck %s --check-prefix=RV64IM
66

77
; Extends to 32 bits exhaustively tested for add only.
88

@@ -130,6 +130,23 @@ entry:
130130
ret i32 %0
131131
}
132132

133+
define i32 @neg_i32(i32 %a) {
134+
; RV32IM-LABEL: neg_i32:
135+
; RV32IM: # %bb.0: # %entry
136+
; RV32IM-NEXT: li a1, 0
137+
; RV32IM-NEXT: sub a0, a1, a0
138+
; RV32IM-NEXT: ret
139+
;
140+
; RV64IM-LABEL: neg_i32:
141+
; RV64IM: # %bb.0: # %entry
142+
; RV64IM-NEXT: li a1, 0
143+
; RV64IM-NEXT: subw a0, a1, a0
144+
; RV64IM-NEXT: ret
145+
entry:
146+
%0 = sub i32 0, %a
147+
ret i32 %0
148+
}
149+
133150
define i32 @sll_i32(i32 %a, i32 %b) {
134151
; RV32IM-LABEL: sll_i32:
135152
; RV32IM: # %bb.0: # %entry
@@ -461,6 +478,27 @@ entry:
461478
ret i64 %0
462479
}
463480

481+
define i64 @neg_i64(i64 %a) {
482+
; RV32IM-LABEL: neg_i64:
483+
; RV32IM: # %bb.0: # %entry
484+
; RV32IM-NEXT: li a3, 0
485+
; RV32IM-NEXT: sub a2, a3, a0
486+
; RV32IM-NEXT: sltu a0, a3, a0
487+
; RV32IM-NEXT: sub a1, a3, a1
488+
; RV32IM-NEXT: sub a1, a1, a0
489+
; RV32IM-NEXT: mv a0, a2
490+
; RV32IM-NEXT: ret
491+
;
492+
; RV64IM-LABEL: neg_i64:
493+
; RV64IM: # %bb.0: # %entry
494+
; RV64IM-NEXT: li a1, 0
495+
; RV64IM-NEXT: sub a0, a1, a0
496+
; RV64IM-NEXT: ret
497+
entry:
498+
%0 = sub i64 0, %a
499+
ret i64 %0
500+
}
501+
464502
; TODO: Handle G_SELECT, which is needed to have i64 shifts working on RV32.
465503

466504
define i64 @and_i64(i64 %a, i64 %b) {

0 commit comments

Comments
 (0)