Skip to content

Commit a23bd17

Browse files
authored
[RISCV] Remove artificial restriction on ShAmt from (shl (and X, C2), C) -> (srli (slli X, C4), C4-C) isel. (#143010)
This code unnecessarily inherited a `ShAmt <= 32` check from an earlier pattern.
1 parent 7730093 commit a23bd17

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,11 +1051,11 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
10511051
unsigned ShAmt = N1C->getZExtValue();
10521052
uint64_t Mask = N0.getConstantOperandVal(1);
10531053

1054-
if (ShAmt <= 32 && isShiftedMask_64(Mask)) {
1054+
if (isShiftedMask_64(Mask)) {
10551055
unsigned XLen = Subtarget->getXLen();
10561056
unsigned LeadingZeros = XLen - llvm::bit_width(Mask);
10571057
unsigned TrailingZeros = llvm::countr_zero(Mask);
1058-
if (TrailingZeros > 0 && LeadingZeros == 32) {
1058+
if (ShAmt <= 32 && TrailingZeros > 0 && LeadingZeros == 32) {
10591059
// Optimize (shl (and X, C2), C) -> (slli (srliw X, C3), C3+C)
10601060
// where C2 has 32 leading zeros and C3 trailing zeros.
10611061
SDNode *SRLIW = CurDAG->getMachineNode(

llvm/test/CodeGen/RISCV/and-shl.ll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,21 @@ define i32 @and_0xfff_shl_2_multi_use(i32 %x) {
7777
%r = add i32 %a, %s
7878
ret i32 %r
7979
}
80+
81+
define i64 @and_0xfff_shl_33(i64 %x) {
82+
; RV32I-LABEL: and_0xfff_shl_33:
83+
; RV32I: # %bb.0:
84+
; RV32I-NEXT: slli a0, a0, 20
85+
; RV32I-NEXT: srli a1, a0, 19
86+
; RV32I-NEXT: li a0, 0
87+
; RV32I-NEXT: ret
88+
;
89+
; RV64I-LABEL: and_0xfff_shl_33:
90+
; RV64I: # %bb.0:
91+
; RV64I-NEXT: slli a0, a0, 52
92+
; RV64I-NEXT: srli a0, a0, 19
93+
; RV64I-NEXT: ret
94+
%a = and i64 %x, 4095
95+
%s = shl i64 %a, 33
96+
ret i64 %s
97+
}

0 commit comments

Comments
 (0)