[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:02 PDT 2025
https://github.com/AZero13 updated https://github.com/llvm/llvm-project/pull/147068
>From c486dafa5451da961e437efb8248543bda9f03b6 Mon Sep 17 00:00:00 2001
From: Rose <gfunni234 at gmail.com>
Date: Fri, 4 Jul 2025 10:31:10 -0400
Subject: [PATCH] [TargetLowering] Add and (rot X, Y), Z ==/!= -1 --> (and X,
Z) ==/!= -1 to foldSetCCWithRotate
---
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
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();
}
More information about the llvm-commits
mailing list