[PATCH] D140206: [RISCV] Omit SRA in case of setlt or setge with zero constant
Elena Lepilkina via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 18 23:51:55 PST 2022
eklepilkina updated this revision to Diff 483865.
eklepilkina added a comment.
Test on bge
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D140206/new/
https://reviews.llvm.org/D140206
Files:
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/branch_zero.ll
Index: llvm/test/CodeGen/RISCV/branch_zero.ll
===================================================================
--- llvm/test/CodeGen/RISCV/branch_zero.ll
+++ llvm/test/CodeGen/RISCV/branch_zero.ll
@@ -8,7 +8,6 @@
; CHECK-NEXT: .LBB0_1: # %for.body
; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
; CHECK-NEXT: slli a0, a0, 48
-; CHECK-NEXT: srai a0, a0, 48
; CHECK-NEXT: bltz a0, .LBB0_4
; CHECK-NEXT: # %bb.2: # %while.cond.preheader.i
; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
@@ -50,7 +49,6 @@
; CHECK-NEXT: .LBB1_1: # %for.body
; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
; CHECK-NEXT: slli a0, a0, 48
-; CHECK-NEXT: srai a0, a0, 48
; CHECK-NEXT: bgez a0, .LBB1_4
; CHECK-NEXT: # %bb.2: # %while.cond.preheader.i
; CHECK-NEXT: # in Loop: Header=BB1_1 Depth=1
Index: llvm/lib/Target/RISCV/RISCVISelLowering.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -9527,6 +9527,19 @@
static bool combine_CC(SDValue &LHS, SDValue &RHS, SDValue &CC, const SDLoc &DL,
SelectionDAG &DAG, const RISCVSubtarget &Subtarget) {
ISD::CondCode CCVal = cast<CondCodeSDNode>(CC)->get();
+
+ // As far as arithmetic right shift always saves the sign,
+ // shift can be omitted.
+ // Fold setlt (sra X, N), 0 -> setlt X, 0 and
+ // setge (sra X, N), 0 -> setge X, 0
+ if (auto *RHSConst = dyn_cast<ConstantSDNode>(RHS.getNode())) {
+ if ((CCVal == ISD::SETGE || CCVal == ISD::SETLT) &&
+ LHS.getOpcode() == ISD::SRA && RHSConst->isZero()) {
+ LHS = LHS.getOperand(0);
+ return true;
+ }
+ }
+
if (!ISD::isIntEqualitySetCC(CCVal))
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140206.483865.patch
Type: text/x-patch
Size: 1774 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221219/9179d56a/attachment.bin>
More information about the llvm-commits
mailing list