[llvm] [VectorCombine] Fix trunc generated between PHINodes (PR #108228)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 12 03:00:31 PDT 2024


================
@@ -2652,8 +2652,12 @@ bool VectorCombine::shrinkType(llvm::Instruction &I) {
     return false;
 
   Value *Op0 = ZExted;
-  if (auto *OI = dyn_cast<Instruction>(OtherOperand))
-    Builder.SetInsertPoint(OI->getNextNode());
+  if (auto *OI = dyn_cast<Instruction>(OtherOperand)) {
+    if (isa<PHINode>(OI))
+      Builder.SetInsertPoint(OI->getParent()->getFirstInsertionPt());
+    else
+      Builder.SetInsertPoint(OI->getNextNode());
+  }
----------------
nikic wrote:

You need to use getInsertionPointAfterDef() to handle all the edge cases correctly (I'd expect you will handle invoke and catchswitch incorrectly right now). Or even better yet, just don't do this and create all the instructions at `&I`. From a cursory look I don't see a need to create this instruction in a different place.

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


More information about the llvm-commits mailing list