[PATCH] D132211: [RISCV] Optimize x > 1 ? x : 1 -> x > 0 ? x : 1
Liao Chunyu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 21 05:25:21 PDT 2022
liaolucy updated this revision to Diff 454301.
liaolucy added a comment.
Update comment to 1 < x ? x : 1 -> 0 < x ? x : 1
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132211/new/
https://reviews.llvm.org/D132211
Files:
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/forced-atomics.ll
Index: llvm/test/CodeGen/RISCV/forced-atomics.ll
===================================================================
--- llvm/test/CodeGen/RISCV/forced-atomics.ll
+++ llvm/test/CodeGen/RISCV/forced-atomics.ll
@@ -995,9 +995,8 @@
; RV32-NO-ATOMIC-NEXT: bnez a0, .LBB23_4
; RV32-NO-ATOMIC-NEXT: .LBB23_2: # %atomicrmw.start
; RV32-NO-ATOMIC-NEXT: # =>This Inner Loop Header: Depth=1
-; RV32-NO-ATOMIC-NEXT: li a0, 1
; RV32-NO-ATOMIC-NEXT: mv a2, a1
-; RV32-NO-ATOMIC-NEXT: blt a0, a1, .LBB23_1
+; RV32-NO-ATOMIC-NEXT: bgtz a1, .LBB23_1
; RV32-NO-ATOMIC-NEXT: # %bb.3: # %atomicrmw.start
; RV32-NO-ATOMIC-NEXT: # in Loop: Header=BB23_2 Depth=1
; RV32-NO-ATOMIC-NEXT: li a2, 1
@@ -1183,9 +1182,8 @@
; RV32-NO-ATOMIC-NEXT: bnez a0, .LBB25_4
; RV32-NO-ATOMIC-NEXT: .LBB25_2: # %atomicrmw.start
; RV32-NO-ATOMIC-NEXT: # =>This Inner Loop Header: Depth=1
-; RV32-NO-ATOMIC-NEXT: li a0, 1
; RV32-NO-ATOMIC-NEXT: mv a2, a1
-; RV32-NO-ATOMIC-NEXT: bltu a0, a1, .LBB25_1
+; RV32-NO-ATOMIC-NEXT: bltu zero, a1, .LBB25_1
; RV32-NO-ATOMIC-NEXT: # %bb.3: # %atomicrmw.start
; RV32-NO-ATOMIC-NEXT: # in Loop: Header=BB25_2 Depth=1
; RV32-NO-ATOMIC-NEXT: li a2, 1
@@ -2563,9 +2561,8 @@
; RV64-NO-ATOMIC-NEXT: bnez a0, .LBB49_4
; RV64-NO-ATOMIC-NEXT: .LBB49_2: # %atomicrmw.start
; RV64-NO-ATOMIC-NEXT: # =>This Inner Loop Header: Depth=1
-; RV64-NO-ATOMIC-NEXT: li a0, 1
; RV64-NO-ATOMIC-NEXT: mv a2, a1
-; RV64-NO-ATOMIC-NEXT: blt a0, a1, .LBB49_1
+; RV64-NO-ATOMIC-NEXT: bgtz a1, .LBB49_1
; RV64-NO-ATOMIC-NEXT: # %bb.3: # %atomicrmw.start
; RV64-NO-ATOMIC-NEXT: # in Loop: Header=BB49_2 Depth=1
; RV64-NO-ATOMIC-NEXT: li a2, 1
@@ -2756,9 +2753,8 @@
; RV64-NO-ATOMIC-NEXT: bnez a0, .LBB51_4
; RV64-NO-ATOMIC-NEXT: .LBB51_2: # %atomicrmw.start
; RV64-NO-ATOMIC-NEXT: # =>This Inner Loop Header: Depth=1
-; RV64-NO-ATOMIC-NEXT: li a0, 1
; RV64-NO-ATOMIC-NEXT: mv a2, a1
-; RV64-NO-ATOMIC-NEXT: bltu a0, a1, .LBB51_1
+; RV64-NO-ATOMIC-NEXT: bltu zero, a1, .LBB51_1
; RV64-NO-ATOMIC-NEXT: # %bb.3: # %atomicrmw.start
; RV64-NO-ATOMIC-NEXT: # in Loop: Header=BB51_2 Depth=1
; RV64-NO-ATOMIC-NEXT: li a2, 1
Index: llvm/lib/Target/RISCV/RISCVISelLowering.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -4019,6 +4019,12 @@
}
translateSetCCForBranch(DL, LHS, RHS, CCVal, DAG);
+ // 1 < x ? x : 1 -> 0 < x ? x : 1
+ if (isOneConstant(LHS) && !isa<ConstantSDNode>(RHS) &&
+ (CCVal == ISD::SETLT || CCVal == ISD::SETULT) && RHS == TrueV &&
+ isOneConstant(FalseV)) {
+ LHS = DAG.getConstant(0, DL, VT);
+ }
SDValue TargetCC = DAG.getCondCode(CCVal);
SDValue Ops[] = {LHS, RHS, TargetCC, TrueV, FalseV};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132211.454301.patch
Type: text/x-patch
Size: 2883 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220821/bc364460/attachment.bin>
More information about the llvm-commits
mailing list