[llvm] [DebugInfo][SimpleLoopUnswitch] Fix missing debug location updates (PR #97662)

Orlando Cazalet-Hyams via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 9 06:17:48 PDT 2024


================
@@ -0,0 +1,75 @@
+; RUN: opt -passes='simple-loop-unswitch<nontrivial>' -S < %s | FileCheck %s
+
+define i32 @basic(i32 %N, i1 %cond, i32 %select_input) !dbg !5 {
+; CHECK-LABEL: define i32 @basic(
+
+; Check that SimpleLoopUnswitch's unswitchNontrivialInvariants() drops the
+; debug location of the hoisted terminator and doesn't give any debug location
+; to the new freeze, since it's inserted in a hoist block.
+; Also check that in unswitchNontrivialInvariants(), the new br instruction
+; inherits the debug location of the old terminator in the same block.
+
+; CHECK:       entry:
+; CHECK-NEXT:    [[COND_FR:%.*]] = freeze i1 [[COND:%.*]]{{$}}
+; CHECK-NEXT:    br i1 [[COND_FR]], label %[[ENTRY_SPLIT_US:.*]], label %[[ENTRY_SPLIT:.*]]{{$}}
----------------
OCHyams wrote:

Thanks for digging in and confirming - this all makes sense and sounds right to me.

Just one thing:

> Actually, the new cond branch did not get the location of uncond branch. Before the dropping, there is no location propagation from the uncond branch to the new cond branch. See the following snippets ([godbolt](https://godbolt.org/z/3qa8PxoTc)). (Hope I understand the old branch right.)

In the two snippets you posted at the end of the last comment it looks like the unconditional branch's location `!8` (`br label %for.cond, !dbg !8`) gets propagated to the conditional branch `br i1 %cond.fr, label %entry.split.us, label %entry.split, !dbg !8` which seems to oppose what you're saying - I must've missed something here, are we talking about a different unconditional branch?


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


More information about the llvm-commits mailing list