[llvm] [ValueTracking] Support scalable vector splats of ConstantInt in isGuaranteedNotToBeUndefOrPoison. (PR #142894)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 5 14:12:44 PDT 2025


================
@@ -7579,16 +7579,23 @@ static bool isGuaranteedNotToBeUndefOrPoison(
     if (isa<UndefValue>(C))
       return !includesUndef(Kind);
 
-    if (isa<ConstantInt>(C) || isa<GlobalVariable>(C) || isa<ConstantFP>(V) ||
+    if (isa<ConstantInt>(C) || isa<GlobalVariable>(C) || isa<ConstantFP>(C) ||
         isa<ConstantPointerNull>(C) || isa<Function>(C))
       return true;
 
-    if (C->getType()->isVectorTy() && !isa<ConstantExpr>(C)) {
-      if (includesUndef(Kind) && C->containsUndefElement())
-        return false;
-      if (includesPoison(Kind) && C->containsPoisonElement())
-        return false;
-      return !C->containsConstantExpression();
+    if (C->getType()->isVectorTy()) {
+      if (isa<ConstantExpr>(C)) {
+        // Scalable vectors can use a ConstantExpr to build a splat.
+        if (Constant *SplatC = C->getSplatValue())
+          if (isa<ConstantInt>(SplatC))
+            return true;
----------------
topperc wrote:

I added ConstantFP and an Attributor test was changed so that has some coverage.

Will a splat of ConstantPointerNull be folded to ConstantAggregateZero at creation?

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


More information about the llvm-commits mailing list