[llvm] [DAGCombiner] Fold select into partial.reduce.add operands. (PR #167857)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 16 19:25:38 PST 2025


================
@@ -13068,6 +13083,20 @@ SDValue DAGCombiner::foldPartialReduceMLAMulOp(SDNode *N) {
   SDValue LHSExtOp = LHS->getOperand(0);
   EVT LHSExtOpVT = LHSExtOp.getValueType();
 
+  // Sets Op = select(P, Op, splat(0)) if P is nonzero, or Op otherwise.
+  // Set ToFreezeOp = freeze(ToFreezeOp) if the value may be poison, to
+  // keep the same semantics.
+  auto ApplyPredicate = [&](SDValue P, SDValue &Op, SDValue &ToFreezeOp) {
+    if (!P)
+      return;
+    if (!DAG.isGuaranteedNotToBePoison(ToFreezeOp))
----------------
lukel97 wrote:

I think a freeze should automatically be folded away in DAGCombine if it's not poison or undef.

Can we just always emit the freeze and let visitFREEZE handle optimizing it away? 

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


More information about the llvm-commits mailing list