[PATCH] D151180: [RISCV] select(C0, x, select(C1, x, y)) -> select(C0|C1, x, y)
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 23 00:06:08 PDT 2023
- Previous message: [PATCH] D151180: [RISCV] select(C0, x, select(C1, x, y)) -> select(C0|C1, x, y)
- Next message: [PATCH] D151180: [RISCV] select(C0, x, select(C1, x, y)) -> select(C0|C1, x, y)
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
craig.topper added a comment.
In D151180#4363315 <https://reviews.llvm.org/D151180#4363315>, @craig.topper wrote:
> I'm not sure this is even the simplest form for these cases. I'm going to post an alternative patch in a minute.
Scratch that. We do get to the simpler answer. In all the tests here C0|C1 <https://reviews.llvm.org/C1> and C0&C1 <https://reviews.llvm.org/C1> can be simplified because they are 2 setccs with the same operands like (seteq X, -1)|(setlt X, -1).
Here's my patch to special case directly in ExpandIntRes_MINMAX.
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
index 7e85a2ea0f97..b756f2b0fbfc 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -2936,6 +2936,22 @@ void DAGTypeLegalizer::ExpandIntRes_MINMAX(SDNode *N,
// Hi part is always the same op
Hi = DAG.getNode(N->getOpcode(), DL, NVT, {LHSH, RHSH});
+ // The Lo of smin(X, -1) is LHSL if X is negative. Otherwise it's -1.
+ if (N->getOpcode() == ISD::SMIN && isAllOnesConstant(RHS)) {
+ SDValue HiNeg = DAG.getSetCC(DL, CCT, LHSH, DAG.getConstant(0, DL, NVT),
+ ISD::SETLT);
+ Lo = DAG.getSelect(DL, NVT, HiNeg, LHSL, DAG.getConstant(-1, DL, NVT));
+ return;
+ }
+
+ // The Lo of smax(X, 0) is 0 if X is negative. Otherwise it's LHSL.
+ if (N->getOpcode() == ISD::SMAX && isNullConstant(RHS)) {
+ SDValue HiNeg = DAG.getSetCC(DL, CCT, LHSH, DAG.getConstant(0, DL, NVT),
+ ISD::SETLT);
+ Lo = DAG.getSelect(DL, NVT, HiNeg, DAG.getConstant(0, DL, NVT), LHSL);
+ return;
+ }
+
// We need to know whether to select Lo part that corresponds to 'winning'
// Hi part or if Hi parts are equal.
SDValue IsHiLeft = DAG.getSetCC(DL, CCT, LHSH, RHSH, CondC);
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D151180/new/
https://reviews.llvm.org/D151180
- Previous message: [PATCH] D151180: [RISCV] select(C0, x, select(C1, x, y)) -> select(C0|C1, x, y)
- Next message: [PATCH] D151180: [RISCV] select(C0, x, select(C1, x, y)) -> select(C0|C1, x, y)
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the llvm-commits
mailing list