Skip to content

Commit aa1bfb3

Browse files
mikolaj-pirogclingfei
authored andcommitted
[SDAG] Use useDebugInstrRef instead of shouldUseDebugInstrRef (llvm#160686)
`shouldUseDebugInstrRef` can return different value than `useDebugInstrRef`, since the first depends on opt level which can change. Inconsistent usage can lead to errors later. I believe that using `should...` instead of `use...` here is a result of a minor error during this: https://github.com/llvm/llvm-project/pull/94149/files#diff-8ec547e1244562c5837ed180dd9bed61b3cd960ef90bb6002ea2db41a67ed693 Notice how before the change `InstrRef` is assigned value from `should...` *before* the opt change. Now, it's done after -- opt change happens here: ```c bool SelectionDAGISelLegacy::runOnMachineFunction(MachineFunction &MF) { ... // Decide what flavour of variable location debug-info will be used, before // we change the optimisation level. MF.setUseDebugInstrRef(MF.shouldUseDebugInstrRef()); .... return Selector->runOnMachineFunction(MF); } ``` Then `runOnMachineFunction` uses `should...`, which after opt change may return different value than it did previously.
1 parent 655d2f3 commit aa1bfb3

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {
571571
SwiftError->setFunction(mf);
572572
const Function &Fn = mf.getFunction();
573573

574-
bool InstrRef = mf.shouldUseDebugInstrRef();
574+
bool InstrRef = mf.useDebugInstrRef();
575575

576576
FuncInfo->set(MF->getFunction(), *MF, CurDAG);
577577

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
; RUN: llc %s -o - -stop-after=livedebugvalues -opt-bisect-limit=1 | FileCheck %s
2+
; RUN: llc %s -o - -stop-after=livedebugvalues -opt-bisect-limit=10 | FileCheck %s
3+
; RUN: llc %s -o - -stop-after=livedebugvalues -opt-bisect-limit=100 | FileCheck %s
4+
5+
; RUN: llc %s -o - -stop-after=livedebugvalues -opt-bisect-limit=1 -fast-isel=true | FileCheck %s
6+
; RUN: llc %s -o - -stop-after=livedebugvalues -opt-bisect-limit=10 -fast-isel=true | FileCheck %s
7+
; RUN: llc %s -o - -stop-after=livedebugvalues -opt-bisect-limit=100 -fast-isel=true | FileCheck %s
8+
9+
; This test has the same purpose as the instr-ref-opt-bisect.ll, to check if
10+
; during opt-bisect's optimisation level change we won't run into an assert.
11+
; This is simply testing different IR.
12+
13+
; CHECK: DBG_VALUE
14+
15+
target triple = "x86_64-pc-windows-msvc"
16+
17+
define i1 @foo(i32 %arg) !dbg !3 {
18+
entry:
19+
#dbg_value(i32 %arg, !4, !DIExpression(), !5)
20+
switch i32 %arg, label %bb [
21+
i32 810, label %bb
22+
], !dbg !5
23+
bb:
24+
%a = load volatile i1, ptr null, align 1
25+
ret i1 false
26+
}
27+
28+
!llvm.dbg.cu = !{!0}
29+
!llvm.module.flags = !{!2}
30+
31+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1)
32+
!1 = !DIFile(filename: "instr-ref-opt-bisect2.ll", directory: ".")
33+
!2 = !{i32 2, !"Debug Info Version", i32 3}
34+
!3 = distinct !DISubprogram(name: "instr-ref-opt-bisect2", file: !1, unit: !0)
35+
!4 = !DILocalVariable(name: "arg", arg: 2, scope: !3)
36+
!5 = !DILocation(line: 0, scope: !3)

0 commit comments

Comments
 (0)