[llvm] [indvars] Missing variables at Og: (PR #69920)

Stephen Tozer via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 15 09:33:33 PDT 2024


================
@@ -0,0 +1,129 @@
+; RUN: opt -passes="loop(indvars)" \
+; RUN:     --experimental-debuginfo-iterators=false -S -o - < %s | \
+; RUN: FileCheck --implicit-check-not="call void @llvm.dbg" \
+; RUN:           --check-prefix=ALL-CHECK --check-prefix=PRE-CHECK %s
+; RUN: opt -passes="loop(indvars,loop-deletion)" \
+; RUN:     --experimental-debuginfo-iterators=false -S -o - < %s | \
+; RUN: FileCheck --implicit-check-not="call void @llvm.dbg" \
+; RUN:           --check-prefix=ALL-CHECK --check-prefix=POST-CHECK %s
+
+; Check what happens to a modified but otherwise unused variable in a loop
+; that gets deleted. The assignment in the loop is 'forgotten' by LLVM and
+; doesn't appear in the debugging information. This behaviour is suboptimal,
+; but we want to know if it changes
+
+; For all cases, LLDB shows
+;   Var = <no location, value may have been optimized out>
+
+;  1	__attribute__((optnone)) int nop() {
+;  2	  return 0;
+;  3	}
+;  4
+;  5	void bar() {
+;  6    int End = 777;
+;  7	  int Index = 27;
+;  8	  char Var = 1;
+;  9	  for (; Index < End; ++Index) {
+; 10      if (Index == 666) {
+; 11        ++Var;
+; 12      }
+; 13    }
+; 14	  nop();
+; 15	}
+
+; ALL-CHECK: entry:
+; ALL-CHECK:   call void @llvm.dbg.value(metadata i32 1, metadata ![[DBG:[0-9]+]], {{.*}}
+
+; Only the 'indvars' pass is executed.
+; PRE-CHECK: for.cond:
+; PRE-CHECK:   call void @llvm.dbg.value(metadata i32 %Var.0, metadata ![[DBG]], {{.*}}
----------------
SLTozer wrote:

This and a lot of the other check lines may fail in a build without assertions enabled, as the SSA values won't necessarily be printed with the same names (they may become numbered values, e.g. `%5`, `%6`, etc). Usually the way to test these would then be to use capture variables for them, e.g. `i32 %[[SSA_VAR0:.+]],`. This gets tedious if you have to use it for every variable, so I'd recommend removing the unrelated CHECK lines, which would be most of the lines that don't need to be tested for and don't produce a value that we want to check; or instead of removing them, you could cut out actual SSA values, i.e. you could just test for `= icmp eq`.

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


More information about the llvm-commits mailing list