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

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 26 22:28:20 PDT 2025


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

>From 5ace973dc97f7b899c436d541f9f3e07d028e170 Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Sun, 27 Apr 2025 13:23:04 +0800
Subject: [PATCH] [VPlan] Use correct constructor when cloning
 VPWidenIntrinsicRecipe without underlying CallInst

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.
---
 llvm/lib/Transforms/Vectorize/VPlan.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index bd6e15d3fb7a5..78b761e64bbff 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -1347,8 +1347,11 @@ class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
   ~VPWidenIntrinsicRecipe() override = default;
 
   VPWidenIntrinsicRecipe *clone() override {
-    return new VPWidenIntrinsicRecipe(*cast<CallInst>(getUnderlyingValue()),
-                                      VectorIntrinsicID, {op_begin(), op_end()},
+    if (Value *CI = getUnderlyingValue())
+      return new VPWidenIntrinsicRecipe(*cast<CallInst>(CI), VectorIntrinsicID,
+                                        {op_begin(), op_end()}, ResultTy,
+                                        getDebugLoc());
+    return new VPWidenIntrinsicRecipe(VectorIntrinsicID, {op_begin(), op_end()},
                                       ResultTy, getDebugLoc());
   }
 



More information about the llvm-commits mailing list