[PATCH] D140206: [RISCV] Omit SRA in case of setlt or setge with zero constant
Anton Afanasyev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 21 03:20:58 PST 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3a3f725a3cdc: [RISCV] Omit SRA in case of setlt or setge with zero constant (authored by eklepilkina, committed by anton-afanasyev).
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
@@ -9550,6 +9550,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.484516.patch
Type: text/x-patch
Size: 1774 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221221/95c6be61/attachment.bin>
More information about the llvm-commits
mailing list