[VPlan] Preserve debug location when creating branch.
authorFlorian Hahn <flo@fhahn.com>
Fri, 8 Apr 2022 15:22:38 +0000 (17:22 +0200)
committerFlorian Hahn <flo@fhahn.com>
Fri, 8 Apr 2022 15:22:53 +0000 (17:22 +0200)
Update createEmptyBasicBlock to preserve the debug location of the
previous terminator.

llvm/lib/Transforms/Vectorize/VPlan.cpp
llvm/test/Transforms/LoopVectorize/debugloc.ll

index 73b2a86..64d582c 100644 (file)
@@ -280,8 +280,10 @@ VPBasicBlock::createEmptyBasicBlock(VPTransformState::CFGState &CFG) {
     if (isa<UnreachableInst>(PredBBTerminator)) {
       assert(PredVPSuccessors.size() == 1 &&
              "Predecessor ending w/o branch must have single successor.");
+      DebugLoc DL = PredBBTerminator->getDebugLoc();
       PredBBTerminator->eraseFromParent();
-      BranchInst::Create(NewBB, PredBB);
+      auto *Br = BranchInst::Create(NewBB, PredBB);
+      Br->setDebugLoc(DL);
     } else {
       assert(PredVPSuccessors.size() == 2 &&
              "Predecessor ending with branch must have two successors.");
index 9c72232..c639ebf 100644 (file)
@@ -70,8 +70,7 @@ define i32 @test_debug_loc_on_branch_in_loop(i32* noalias %src, i32* noalias %ds
 ; CHECK-NEXT: pred.store.if:
 ; CHECK-NEXT:   [[GEP:%.+]] = getelementptr inbounds i32, i32* %dst, i64 {{.+}}, !dbg [[LOC3]]
 ; CHECK-NEXT:   store i32 0, i32* [[GEP]], align 4, !dbg [[LOC3]]
-; CHECK-NEXT:   br label %pred.store.continue
-; CHECK-NOT:  !dbg
+; CHECK-NEXT:   br label %pred.store.continue, !dbg [[LOC3]]
 ; CHECK-EMPTY:
 ;
 entry: