[llvm] [VPlan] Use correct constructor when cloning VPWidenIntrinsicRecipe without underlying CallInst (PR #137493)

via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 26 22:27:14 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-vectorizers

Author: Luke Lau (lukel97)

<details>
<summary>Changes</summary>

I noticed this when working on a patch downstream, and I don't think this is an issue upstream yet.

But if a VPWidenIntrinsicRecipe is created without an underlying CallInst, e.g. in createEVLRecipe, it will crash if you try to clone it because it assumes the CallInst always exists.

This fixes it by using the CallInst-less constructor in this case.


---
Full diff: https://github.com/llvm/llvm-project/pull/137493.diff


1 Files Affected:

- (modified) llvm/lib/Transforms/Vectorize/VPlan.h (+7-3) 


``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index bd6e15d3fb7a5..925e0b6c68d45 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -1347,9 +1347,13 @@ class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
   ~VPWidenIntrinsicRecipe() override = default;
 
   VPWidenIntrinsicRecipe *clone() override {
-    return new VPWidenIntrinsicRecipe(*cast<CallInst>(getUnderlyingValue()),
-                                      VectorIntrinsicID, {op_begin(), op_end()},
-                                      ResultTy, getDebugLoc());
+    if (auto *CI = getUnderlyingValue())
+      return new VPWidenIntrinsicRecipe(*cast<CallInst>(CI), VectorIntrinsicID,
+                                        {op_begin(), op_end()}, ResultTy,
+                                        getDebugLoc());
+    else
+      return new VPWidenIntrinsicRecipe(
+          VectorIntrinsicID, {op_begin(), op_end()}, ResultTy, getDebugLoc());
   }
 
   VP_CLASSOF_IMPL(VPDef::VPWidenIntrinsicSC)

``````````

</details>


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


More information about the llvm-commits mailing list