[llvm] [TargetLowering] Add and (rot X, Y), Z ==/!= -1 --> (and X, Z) ==/!= -1 to foldSetCCWithRotate (PR #147068)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 4 07:32:19 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-selectiondag
Author: AZero13 (AZero13)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/147068.diff
1 Files Affected:
- (modified) llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp (+15-1)
``````````diff
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index 000f8cc6786a5..f552104072405 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -4567,7 +4567,6 @@ static SDValue foldSetCCWithRotate(EVT VT, SDValue N0, SDValue N1,
// or (rot X, Y), Z ==/!= 0 --> (or X, Z) ==/!= 0
// or Z, (rot X, Y) ==/!= 0 --> (or X, Z) ==/!= 0
//
- // TODO: Add the 'and' with -1 sibling.
// TODO: Recurse through a series of 'or' ops to find the rotate.
EVT OpVT = N0.getValueType();
if (N0.hasOneUse() && N0.getOpcode() == ISD::OR && C1->isZero()) {
@@ -4581,6 +4580,21 @@ static SDValue foldSetCCWithRotate(EVT VT, SDValue N0, SDValue N1,
}
}
+ // and (rot X, Y), Z ==/!= -1 --> (and X, Z) ==/!= -1
+ // and Z, (rot X, Y) ==/!= -1 --> (and X, Z) ==/!= -1
+ //
+ // TODO: Recursively peek through a series of 'and' ops to find the rotate.
+ if (N0.hasOneUse() && N0.getOpcode() == ISD::AND && C1->isAllOnes()) {
+ if (SDValue R = getRotateSource(N0.getOperand(0))) {
+ SDValue NewAnd = DAG.getNode(ISD::AND, dl, OpVT, R, N0.getOperand(1));
+ return DAG.getSetCC(dl, VT, NewAnd, N1, Cond);
+ }
+ if (SDValue R = getRotateSource(N0.getOperand(1))) {
+ SDValue NewAnd = DAG.getNode(ISD::AND, dl, OpVT, R, N0.getOperand(0));
+ return DAG.getSetCC(dl, VT, NewAnd, N1, Cond);
+ }
+ }
+
return SDValue();
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/147068
More information about the llvm-commits
mailing list