Skip to content

Commit 7647f88

Browse files
authored
[RISCV] Add isel special case for (and (srl X, c2), c1) -> (slli_uw (srli x, c2+c3), c3). (llvm#100966)
Where c1 is a shifted mask with 32 set bits and c3 trailing zeros. Fixes llvm#100936.
1 parent 0a1ce1a commit 7647f88

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,18 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
13931393
ReplaceNode(Node, SLLI);
13941394
return;
13951395
}
1396+
// If we have 32 bits in the mask, we can use SLLI_UW instead of SLLI.
1397+
if (Trailing > 0 && Leading + Trailing == 32 && C2 + Trailing < XLen &&
1398+
OneUseOrZExtW && Subtarget->hasStdExtZba()) {
1399+
SDNode *SRLI = CurDAG->getMachineNode(
1400+
RISCV::SRLI, DL, VT, X,
1401+
CurDAG->getTargetConstant(C2 + Trailing, DL, VT));
1402+
SDNode *SLLI_UW = CurDAG->getMachineNode(
1403+
RISCV::SLLI_UW, DL, VT, SDValue(SRLI, 0),
1404+
CurDAG->getTargetConstant(Trailing, DL, VT));
1405+
ReplaceNode(Node, SLLI_UW);
1406+
return;
1407+
}
13961408
}
13971409

13981410
// Turn (and (shl x, c2), c1) -> (slli (srli x, c3-c2), c3) if c1 is a

llvm/test/CodeGen/RISCV/rv64zba.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2962,8 +2962,7 @@ define i64 @srli_slliuw_2(i64 %1) {
29622962
;
29632963
; RV64ZBA-LABEL: srli_slliuw_2:
29642964
; RV64ZBA: # %bb.0: # %entry
2965-
; RV64ZBA-NEXT: srli a0, a0, 15
2966-
; RV64ZBA-NEXT: srli a0, a0, 3
2965+
; RV64ZBA-NEXT: srli a0, a0, 18
29672966
; RV64ZBA-NEXT: slli.uw a0, a0, 3
29682967
; RV64ZBA-NEXT: ret
29692968
entry:
@@ -2985,8 +2984,7 @@ define i64 @srli_slliuw_canonical_2(i64 %0) {
29852984
;
29862985
; RV64ZBA-LABEL: srli_slliuw_canonical_2:
29872986
; RV64ZBA: # %bb.0: # %entry
2988-
; RV64ZBA-NEXT: srli a0, a0, 15
2989-
; RV64ZBA-NEXT: srli a0, a0, 3
2987+
; RV64ZBA-NEXT: srli a0, a0, 18
29902988
; RV64ZBA-NEXT: slli.uw a0, a0, 3
29912989
; RV64ZBA-NEXT: ret
29922990
entry:

0 commit comments

Comments
 (0)