[llvm] [VectorCombine] Fix crash when folding select of bitcast (PR #177183)

Mitch Briles via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 21 11:55:06 PST 2026


================
@@ -1651,7 +1651,38 @@ bool VectorCombine::foldSelectsFromBitcast(Instruction &I) {
     }
 
     // Create the vector select and bitcast once for this condition.
-    Builder.SetInsertPoint(BC->getNextNode());
+    // Insert in a block that dominates all selects and after any local defs.
+    BasicBlock *InsertBB = Selects.front()->getParent();
+    for (SelectInst *Sel : Selects)
+      InsertBB = DT.findNearestCommonDominator(InsertBB, Sel->getParent());
----------------
MitchBriles wrote:

Yes. Added a test for cross-block case.

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


More information about the llvm-commits mailing list