Skip to content

Commit 9769026

Browse files
committed
[RISCV] Add (i32 (and GPR:, TrailingOnesMask:)) pattern for RV64 with legal i32.
1 parent 7667723 commit 9769026

File tree

6 files changed

+16
-18
lines changed

6 files changed

+16
-18
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,6 +2042,10 @@ def : Pat<(i32 (xor GPR:$rs1, simm12i32:$imm)),
20422042
def : PatGprImm<shl, SLLIW, uimm5, i32>;
20432043
def : PatGprImm<srl, SRLIW, uimm5, i32>;
20442044
def : PatGprImm<sra, SRAIW, uimm5, i32>;
2045+
2046+
def : Pat<(i32 (and GPR:$rs, TrailingOnesMask:$mask)),
2047+
(SRLI (SLLI $rs, (i64 (XLenSubTrailingOnes $mask))),
2048+
(i64 (XLenSubTrailingOnes $mask)))>;
20452049
}
20462050

20472051
let Predicates = [IsRV64, NotHasStdExtZba] in {

llvm/test/CodeGen/RISCV/rv64-legal-i32/div.ll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,8 @@ define i16 @udiv16_constant_lhs(i16 %a) nounwind {
301301
;
302302
; RV64IM-LABEL: udiv16_constant_lhs:
303303
; RV64IM: # %bb.0:
304-
; RV64IM-NEXT: lui a1, 16
305-
; RV64IM-NEXT: addi a1, a1, -1
306-
; RV64IM-NEXT: and a0, a0, a1
304+
; RV64IM-NEXT: slli a0, a0, 48
305+
; RV64IM-NEXT: srli a0, a0, 48
307306
; RV64IM-NEXT: li a1, 10
308307
; RV64IM-NEXT: divuw a0, a1, a0
309308
; RV64IM-NEXT: ret

llvm/test/CodeGen/RISCV/rv64-legal-i32/rem.ll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,8 @@ define i16 @urem16_constant_lhs(i16 %a) nounwind {
330330
;
331331
; RV64IM-LABEL: urem16_constant_lhs:
332332
; RV64IM: # %bb.0:
333-
; RV64IM-NEXT: lui a1, 16
334-
; RV64IM-NEXT: addi a1, a1, -1
335-
; RV64IM-NEXT: and a0, a0, a1
333+
; RV64IM-NEXT: slli a0, a0, 48
334+
; RV64IM-NEXT: srli a0, a0, 48
336335
; RV64IM-NEXT: li a1, 10
337336
; RV64IM-NEXT: remuw a0, a1, a0
338337
; RV64IM-NEXT: ret

llvm/test/CodeGen/RISCV/rv64-legal-i32/rv64xtheadbb.ll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -749,9 +749,8 @@ define i64 @no_sexth_i64(i64 %a) nounwind {
749749
define i32 @zexth_i32(i32 %a) nounwind {
750750
; RV64I-LABEL: zexth_i32:
751751
; RV64I: # %bb.0:
752-
; RV64I-NEXT: lui a1, 16
753-
; RV64I-NEXT: addiw a1, a1, -1
754-
; RV64I-NEXT: and a0, a0, a1
752+
; RV64I-NEXT: slli a0, a0, 48
753+
; RV64I-NEXT: srli a0, a0, 48
755754
; RV64I-NEXT: ret
756755
;
757756
; RV64XTHEADBB-LABEL: zexth_i32:

llvm/test/CodeGen/RISCV/rv64-legal-i32/rv64zbb.ll

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -944,16 +944,14 @@ define i64 @abs_i64(i64 %x) {
944944
define i32 @zexth_i32(i32 %a) nounwind {
945945
; RV64I-LABEL: zexth_i32:
946946
; RV64I: # %bb.0:
947-
; RV64I-NEXT: lui a1, 16
948-
; RV64I-NEXT: addiw a1, a1, -1
949-
; RV64I-NEXT: and a0, a0, a1
947+
; RV64I-NEXT: slli a0, a0, 48
948+
; RV64I-NEXT: srli a0, a0, 48
950949
; RV64I-NEXT: ret
951950
;
952951
; RV64ZBB-LABEL: zexth_i32:
953952
; RV64ZBB: # %bb.0:
954-
; RV64ZBB-NEXT: lui a1, 16
955-
; RV64ZBB-NEXT: addiw a1, a1, -1
956-
; RV64ZBB-NEXT: and a0, a0, a1
953+
; RV64ZBB-NEXT: slli a0, a0, 48
954+
; RV64ZBB-NEXT: srli a0, a0, 48
957955
; RV64ZBB-NEXT: ret
958956
%and = and i32 %a, 65535
959957
ret i32 %and

llvm/test/CodeGen/RISCV/rv64-legal-i32/rv64zbs.ll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,8 @@ define signext i32 @bclri_i32_30(i32 signext %a) nounwind {
474474
define signext i32 @bclri_i32_31(i32 signext %a) nounwind {
475475
; RV64I-LABEL: bclri_i32_31:
476476
; RV64I: # %bb.0:
477-
; RV64I-NEXT: lui a1, 524288
478-
; RV64I-NEXT: addiw a1, a1, -1
479-
; RV64I-NEXT: and a0, a0, a1
477+
; RV64I-NEXT: slli a0, a0, 33
478+
; RV64I-NEXT: srli a0, a0, 33
480479
; RV64I-NEXT: ret
481480
;
482481
; RV64ZBS-LABEL: bclri_i32_31:

0 commit comments

Comments
 (0)