[llvm] [DAGCombiner] Inverse transform `(select c, (and X, 1), 0)` -> `(and (zext c), X)` (PR #66793)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 21 07:04:25 PDT 2023
================
@@ -6299,6 +6299,35 @@ 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();
+ if (!isNullConstant(F))
+ return SDValue();
+
+ EVT CondVT = Cond.getValueType();
+ ISD::NodeType BoolExtOpc =
+ TLI.getExtendForContent(TLI.getBooleanContents(CondVT));
+ if (BoolExtOpc != ISD::ZERO_EXTEND)
----------------
RKSimon wrote:
Why not just use TLI.getBooleanContents(CondVT) != ZeroOrOneBooleanContent?
https://github.com/llvm/llvm-project/pull/66793
More information about the llvm-commits
mailing list