[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:26:40 PDT 2025


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

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.


>From cececf51079bb475df940a6a5f32e9034c55fe50 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 | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

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)



More information about the llvm-commits mailing list