[llvm] c33dbc2 - [SDAG] refactor foldSetCCWithRotate; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 2 13:43:39 PST 2022
Author: Sanjay Patel
Date: 2022-03-02T16:42:05-05:00
New Revision: c33dbc2a2dfcdaed22f156efdc38e4ff215c972f
URL: https://github.com/llvm/llvm-project/commit/c33dbc2a2dfcdaed22f156efdc38e4ff215c972f
DIFF: https://github.com/llvm/llvm-project/commit/c33dbc2a2dfcdaed22f156efdc38e4ff215c972f.diff
LOG: [SDAG] refactor foldSetCCWithRotate; NFC
There are more potential optimizations to make here,
so rearrange to make it easier to append those.
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index 49ae7354a3127..18016e93fbdd0 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -3819,17 +3819,23 @@ static SDValue foldSetCCWithRotate(EVT VT, SDValue N0, SDValue N1,
if (Cond != ISD::SETEQ && Cond != ISD::SETNE)
return SDValue();
- if (N0.getOpcode() != ISD::ROTL && N0.getOpcode() != ISD::ROTR)
- return SDValue();
-
auto *C1 = isConstOrConstSplat(N1, /* AllowUndefs */ true);
if (!C1 || !(C1->isZero() || C1->isAllOnes()))
return SDValue();
+ auto getRotateSource = [](SDValue X) {
+ if (X.getOpcode() == ISD::ROTL || X.getOpcode() == ISD::ROTR)
+ return X.getOperand(0);
+ return SDValue();
+ };
+
// Peek through a rotated value compared against 0 or -1:
// (rot X, Y) == 0/-1 --> X == 0/-1
// (rot X, Y) != 0/-1 --> X != 0/-1
- return DAG.getSetCC(dl, VT, N0.getOperand(0), N1, Cond);
+ if (SDValue R = getRotateSource(N0))
+ return DAG.getSetCC(dl, VT, R, N1, Cond);
+
+ return SDValue();
}
/// Try to simplify a setcc built with the specified operands and cc. If it is
More information about the llvm-commits
mailing list