[llvm] [VPlan] Fix sentinel assertion when broadcasting invoke results (PR #210464)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 17 16:50:39 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Krisitan Erik Olsen (Kristianerik)

<details>
<summary>Changes</summary>

VPTransformState::get broadcasts a scalar value by inserting after the last scalarized instruction using std::next(BasicBlock::iterator(LastInst)). When LastInst is a terminator like invoke, std::next advances past the end of the block, hitting the !isKnownSentinel() assertion.
Use Instruction::getInsertionPointAfterDef which correctly handles PHIs, invokes, and regular instructions, matching the pattern already used in VectorCombine.cpp.
Fixes #<!-- -->210342

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


2 Files Affected:

- (modified) llvm/lib/Transforms/Vectorize/VPlan.cpp (+5-6) 
- (added) llvm/test/Transforms/LoopVectorize/pr210342.ll (+28) 


``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index 7d69b3453cba9..7c9d528804049 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -337,12 +337,11 @@ Value *VPTransformState::get(const VPValue *Def, bool NeedsScalar) {
   VPLane LastLane = VPLane::getLastLaneForVF(VF);
   IRBuilderBase::InsertPointGuard Guard(Builder);
   if (auto *LastInst = dyn_cast<Instruction>(get(Def, LastLane)))
-    // Set the insert point after the last scalarized instruction or after the
-    // last PHI, if LastInst is a PHI. This ensures the insertelement sequence
-    // will directly follow the scalar definitions.
-    Builder.SetInsertPoint(isa<PHINode>(LastInst)
-                               ? LastInst->getParent()->getFirstNonPHIIt()
-                               : std::next(BasicBlock::iterator(LastInst)));
+    // Set the insert point after the last scalarized instruction. This
+    // ensures the insertelement sequence will directly follow the scalar
+    // definitions.
+    if (auto InsertPt = LastInst->getInsertionPointAfterDef())
+      Builder.SetInsertPoint(*InsertPt);
   Value *VectorValue = GetBroadcastInstrs(ScalarValue);
   set(Def, VectorValue);
   return VectorValue;
diff --git a/llvm/test/Transforms/LoopVectorize/pr210342.ll b/llvm/test/Transforms/LoopVectorize/pr210342.ll
new file mode 100644
index 0000000000000..16109410f7c18
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/pr210342.ll
@@ -0,0 +1,28 @@
+; RUN: opt -passes=loop-vectorize -S < %s -o /dev/null
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @wombat() #0 gc "statepoint-example" personality ptr null {
+bb:
+  %invoke = invoke i32 null(i32 0)
+          to label %bb2 unwind label %bb1
+
+bb1:
+  %landingpad = landingpad { ptr, i32 }
+          cleanup
+  ret void
+
+bb2:
+  %phi = phi i32 [ %mul, %bb2 ], [ 0, %bb ]
+  %phi3 = phi i64 [ %add, %bb2 ], [ 0, %bb ]
+  %mul = mul i32 %phi, %invoke
+  %add = add i64 %phi3, 4
+  %icmp = icmp ugt i64 %phi3, 139
+  br i1 %icmp, label %bb4, label %bb2
+
+bb4:
+  %phi5 = phi i32 [ %mul, %bb2 ]
+  ret void
+}
+
+attributes #0 = { "target-cpu"="skylake-avx512" }

``````````

</details>


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


More information about the llvm-commits mailing list