[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())
----------------
topperc wrote:

!isNullConstant(F)?

https://github.com/llvm/llvm-project/pull/66793


More information about the llvm-commits mailing list