Skip to content

Commit 32f6a15

Browse files
committed
[RISCV] Add more tests that can be improved by D99042.
1 parent 4f9c61e commit 32f6a15

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

llvm/test/CodeGen/RISCV/alu32.ll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,29 @@ define i32 @srli(i32 %a) nounwind {
129129
ret i32 %1
130130
}
131131

132+
; FIXME: This should use srliw on RV64, but SimplifyDemandedBits breaks the
133+
; (and X, 0xffffffff) that type legalization inserts.
134+
define i32 @srli_demandedbits(i32 %0) {
135+
; RV32I-LABEL: srli_demandedbits:
136+
; RV32I: # %bb.0:
137+
; RV32I-NEXT: srli a0, a0, 3
138+
; RV32I-NEXT: ori a0, a0, 1
139+
; RV32I-NEXT: ret
140+
;
141+
; RV64I-LABEL: srli_demandedbits:
142+
; RV64I: # %bb.0:
143+
; RV64I-NEXT: addi a1, zero, 1
144+
; RV64I-NEXT: slli a1, a1, 32
145+
; RV64I-NEXT: addi a1, a1, -16
146+
; RV64I-NEXT: and a0, a0, a1
147+
; RV64I-NEXT: srli a0, a0, 3
148+
; RV64I-NEXT: ori a0, a0, 1
149+
; RV64I-NEXT: ret
150+
%2 = lshr i32 %0, 3
151+
%3 = or i32 %2, 1
152+
ret i32 %3
153+
}
154+
132155
define i32 @srai(i32 %a) nounwind {
133156
; RV32I-LABEL: srai:
134157
; RV32I: # %bb.0:

llvm/test/CodeGen/RISCV/rv64zba.ll

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,40 @@ define i64 @zextw_i64(i64 %a) nounwind {
126126
ret i64 %and
127127
}
128128

129+
; FIXME: This can use zext.w, but we need targetShrinkDemandedConstant to
130+
; to adjust the immediate.
131+
define i64 @zextw_demandedbits_i64(i64 %0) {
132+
; RV64I-LABEL: zextw_demandedbits_i64:
133+
; RV64I: # %bb.0:
134+
; RV64I-NEXT: addi a1, zero, 1
135+
; RV64I-NEXT: slli a1, a1, 32
136+
; RV64I-NEXT: addi a1, a1, -2
137+
; RV64I-NEXT: and a0, a0, a1
138+
; RV64I-NEXT: ori a0, a0, 1
139+
; RV64I-NEXT: ret
140+
;
141+
; RV64IB-LABEL: zextw_demandedbits_i64:
142+
; RV64IB: # %bb.0:
143+
; RV64IB-NEXT: addi a1, zero, 1
144+
; RV64IB-NEXT: slli a1, a1, 32
145+
; RV64IB-NEXT: addi a1, a1, -2
146+
; RV64IB-NEXT: and a0, a0, a1
147+
; RV64IB-NEXT: ori a0, a0, 1
148+
; RV64IB-NEXT: ret
149+
;
150+
; RV64IBA-LABEL: zextw_demandedbits_i64:
151+
; RV64IBA: # %bb.0:
152+
; RV64IBA-NEXT: addi a1, zero, 1
153+
; RV64IBA-NEXT: slli a1, a1, 32
154+
; RV64IBA-NEXT: addi a1, a1, -2
155+
; RV64IBA-NEXT: and a0, a0, a1
156+
; RV64IBA-NEXT: ori a0, a0, 1
157+
; RV64IBA-NEXT: ret
158+
%2 = and i64 %0, 4294967294
159+
%3 = or i64 %2, 1
160+
ret i64 %3
161+
}
162+
129163
define signext i16 @sh1add(i64 %0, i16* %1) {
130164
; RV64I-LABEL: sh1add:
131165
; RV64I: # %bb.0:

0 commit comments

Comments
 (0)