[LV] Ensure fixNonInductionPHIs uses a valid insertion point.
authorFlorian Hahn <flo@fhahn.com>
Tue, 23 Feb 2021 17:46:22 +0000 (17:46 +0000)
committerFlorian Hahn <flo@fhahn.com>
Tue, 23 Feb 2021 18:51:05 +0000 (18:51 +0000)
In some cases, Builder's insertion point may be invalidated before using
it in VPTransformState::get. Make sure the insertion point is
up-to-date.

This should fix various sanitizer errors, like
https://lab.llvm.org/buildbot/#/builders/5/builds/4933/steps/9/logs/stdio

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

index cebb8ec..5594cb9 100644 (file)
@@ -4374,6 +4374,8 @@ void InnerLoopVectorizer::fixNonInductionPHIs(VPTransformState &State) {
     VPWidenPHIRecipe *VPPhi =
         cast<VPWidenPHIRecipe>(State.Plan->getVPValue(OrigPhi));
     PHINode *NewPhi = cast<PHINode>(State.get(VPPhi, 0));
+    // Make sure the builder has a valid insert point.
+    Builder.SetInsertPoint(NewPhi);
     for (unsigned i = 0; i < VPPhi->getNumOperands(); ++i) {
       VPValue *Inc = VPPhi->getIncomingValue(i);
       VPBasicBlock *VPBB = VPPhi->getIncomingBlock(i);