[llvm] [LLVM][ConstantFolding] Extend constantFoldVectorReduce to include scalable vectors. (PR #165437)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 29 01:23:32 PDT 2025


================
@@ -2163,18 +2163,39 @@ Constant *ConstantFoldBinaryFP(double (*NativeFP)(double, double),
 }
 
 Constant *constantFoldVectorReduce(Intrinsic::ID IID, Constant *Op) {
-  FixedVectorType *VT = dyn_cast<FixedVectorType>(Op->getType());
-  if (!VT)
-    return nullptr;
-
-  // This isn't strictly necessary, but handle the special/common case of zero:
-  // all integer reductions of a zero input produce zero.
-  if (isa<ConstantAggregateZero>(Op))
-    return ConstantInt::get(VT->getElementType(), 0);
+  auto *OpVT = cast<VectorType>(Op->getType());
 
   // This is the same as the underlying binops - poison propagates.
   if (isa<PoisonValue>(Op) || Op->containsPoisonElement())
----------------
david-arm wrote:

Interestingly, `containsUndefinedElement` doesn't try as hard as it could to find poison values in scalable vectors. For example, it could check if there is an insert of poison somewhere.

This is just an observation - no expectation from you to do anything!

However, it looks like the additional call to `isa<PoisonValue>(Op)` is redundant since `containsPoisonElement` asks the same question. Since you're here perhaps worth removing?

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


More information about the llvm-commits mailing list