[llvm] 7647f88 - [RISCV] Add isel special case for (and (srl X, c2), c1) -> (slli_uw (srli x, c2+c3), c3). (#100966)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 29 09:08:44 PDT 2024
Author: Craig Topper
Date: 2024-07-29T09:08:39-07:00
New Revision: 7647f88234cadf0aed019abb1fc723c6708b871c
URL: https://github.com/llvm/llvm-project/commit/7647f88234cadf0aed019abb1fc723c6708b871c
DIFF: https://github.com/llvm/llvm-project/commit/7647f88234cadf0aed019abb1fc723c6708b871c.diff
LOG: [RISCV] Add isel special case for (and (srl X, c2), c1) -> (slli_uw (srli x, c2+c3), c3). (#100966)
Where c1 is a shifted mask with 32 set bits and c3 trailing zeros.
Fixes #100936.
Added:
Modified:
llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
llvm/test/CodeGen/RISCV/rv64zba.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
index eef6ae677ac85..01b2bc08d3ba0 100644
--- a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
@@ -1393,6 +1393,18 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
ReplaceNode(Node, SLLI);
return;
}
+ // If we have 32 bits in the mask, we can use SLLI_UW instead of SLLI.
+ if (Trailing > 0 && Leading + Trailing == 32 && C2 + Trailing < XLen &&
+ OneUseOrZExtW && Subtarget->hasStdExtZba()) {
+ SDNode *SRLI = CurDAG->getMachineNode(
+ RISCV::SRLI, DL, VT, X,
+ CurDAG->getTargetConstant(C2 + Trailing, DL, VT));
+ SDNode *SLLI_UW = CurDAG->getMachineNode(
+ RISCV::SLLI_UW, DL, VT, SDValue(SRLI, 0),
+ CurDAG->getTargetConstant(Trailing, DL, VT));
+ ReplaceNode(Node, SLLI_UW);
+ return;
+ }
}
// Turn (and (shl x, c2), c1) -> (slli (srli x, c3-c2), c3) if c1 is a
diff --git a/llvm/test/CodeGen/RISCV/rv64zba.ll b/llvm/test/CodeGen/RISCV/rv64zba.ll
index 61be5ee458e9d..20a0484464018 100644
--- a/llvm/test/CodeGen/RISCV/rv64zba.ll
+++ b/llvm/test/CodeGen/RISCV/rv64zba.ll
@@ -2962,8 +2962,7 @@ define i64 @srli_slliuw_2(i64 %1) {
;
; RV64ZBA-LABEL: srli_slliuw_2:
; RV64ZBA: # %bb.0: # %entry
-; RV64ZBA-NEXT: srli a0, a0, 15
-; RV64ZBA-NEXT: srli a0, a0, 3
+; RV64ZBA-NEXT: srli a0, a0, 18
; RV64ZBA-NEXT: slli.uw a0, a0, 3
; RV64ZBA-NEXT: ret
entry:
@@ -2985,8 +2984,7 @@ define i64 @srli_slliuw_canonical_2(i64 %0) {
;
; RV64ZBA-LABEL: srli_slliuw_canonical_2:
; RV64ZBA: # %bb.0: # %entry
-; RV64ZBA-NEXT: srli a0, a0, 15
-; RV64ZBA-NEXT: srli a0, a0, 3
+; RV64ZBA-NEXT: srli a0, a0, 18
; RV64ZBA-NEXT: slli.uw a0, a0, 3
; RV64ZBA-NEXT: ret
entry:
More information about the llvm-commits
mailing list