Skip to content

Commit 1304d34

Browse files
committed
[RISCV] Remove artificial restriction on ShAmt from (shl (and X, C2), C) -> (slli (srliw X, C3), C3+C) fold.
1 parent ab27127 commit 1304d34

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ define i64 @and_0xfff_shl_33(i64 %x) {
8989
; RV64I-LABEL: and_0xfff_shl_33:
9090
; RV64I: # %bb.0:
9191
; RV64I-NEXT: slli a0, a0, 52
92-
; RV64I-NEXT: srli a0, a0, 52
93-
; RV64I-NEXT: slli a0, a0, 33
92+
; RV64I-NEXT: srli a0, a0, 19
9493
; RV64I-NEXT: ret
9594
%a = and i64 %x, 4095
9695
%s = shl i64 %a, 33

0 commit comments

Comments
 (0)