[llvm] [SDAG] Use useDebugInstrRef instead of shouldUseDebugInstrRef (PR #160686)

Mikołaj Piróg via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 25 04:25:14 PDT 2025


https://github.com/mikolaj-pirog created https://github.com/llvm/llvm-project/pull/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.



>From d73e3a7cb9528b0dc890dd7cfb7689f1a182e207 Mon Sep 17 00:00:00 2001
From: "Pirog, Mikolaj Maciej" <mikolaj.maciej.pirog at intel.com>
Date: Thu, 25 Sep 2025 13:09:34 +0200
Subject: [PATCH] Use useDebugInstrRef instead of shouldUseDebugInstrRef

---
 llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index e61558c59bf0d..214edfc7c07f3 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -566,7 +566,7 @@ bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {
   SwiftError->setFunction(mf);
   const Function &Fn = mf.getFunction();
 
-  bool InstrRef = mf.shouldUseDebugInstrRef();
+  bool InstrRef = mf.useDebugInstrRef();
 
   FuncInfo->set(MF->getFunction(), *MF, CurDAG);
 



More information about the llvm-commits mailing list