[llvm] goldstein/select and zext (PR #66793)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 19 10:17:52 PDT 2023
================
@@ -6294,6 +6294,37 @@ static SDValue foldAndOrOfSETCC(SDNode *LogicOp, SelectionDAG &DAG) {
return SDValue();
}
+// Combine `(select c, (X & 1), 0)` -> `(and (zext c), X)`.
+// We canonicalize to the `select` form in the middle end, but the `and` form
+// gets better codegen and all tested targets (arm, x86, riscv)
+static SDValue combineSelectAsExtAnd(SDValue Cond, SDValue T, SDValue F,
+ const SDLoc &DL, SelectionDAG &DAG) {
+ const TargetLowering &TLI = DAG.getTargetLoweringInfo();
+ auto *FC = dyn_cast<ConstantSDNode>(F);
+ if (FC == nullptr || !FC->isZero())
+ return SDValue();
+
+ EVT CondVT = Cond.getValueType();
+ ISD::NodeType BoolExtOpc =
+ TLI.getExtendForContent(TLI.getBooleanContents(CondVT));
+ if (BoolExtOpc != ISD::ZERO_EXTEND)
+ return SDValue();
+
+ if (T.getOpcode() != ISD::AND)
+ return SDValue();
+
+ auto *TC1 = dyn_cast<ConstantSDNode>(T.getOperand(1));
+ if (TC1 == nullptr || !TC1->isOne())
----------------
topperc wrote:
!isOneConstant(T)?
https://github.com/llvm/llvm-project/pull/66793
More information about the llvm-commits
mailing list