Skip to content

[RISCV] Limit (and (sra x, c2), c1) -> (srli (srai x, c2-c3), c3) isel in some cases. #102034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,12 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {

SDValue X = N0.getOperand(0);

if (isMask_64(C1)) {
// Prefer SRAIW + ANDI when possible.
bool Skip = C2 > 32 && isInt<12>(N1C->getSExtValue()) &&
X.getOpcode() == ISD::SHL &&
isa<ConstantSDNode>(X.getOperand(1)) &&
X.getConstantOperandVal(1) == 32;
if (isMask_64(C1) && !Skip) {
unsigned Leading = XLen - llvm::bit_width(C1);
if (C2 > Leading) {
SDNode *SRAI = CurDAG->getMachineNode(
Expand Down
5 changes: 2 additions & 3 deletions llvm/test/CodeGen/RISCV/selectcc-to-shiftand.ll
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,8 @@ define i64 @sraiw_andi(i32 signext %0, i32 signext %1) nounwind {
; RV64-LABEL: sraiw_andi:
; RV64: # %bb.0: # %entry
; RV64-NEXT: add a0, a0, a1
; RV64-NEXT: slli a0, a0, 32
; RV64-NEXT: srai a0, a0, 2
; RV64-NEXT: srli a0, a0, 61
; RV64-NEXT: sraiw a0, a0, 31
; RV64-NEXT: andi a0, a0, 7
; RV64-NEXT: ret
entry:
%3 = add i32 %0, %1
Expand Down
Loading