Skip to content

Commit 0c7d268

Browse files
authored
[CodeGen][SDAG] Skip preferred extend at O0 (#92643)
This is a pure optimization to avoid redundant extensions, but iterating over all users is expensive, so don't do this at -O0.
1 parent 10edb49 commit 0c7d268

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ class SelectionDAG {
469469
MachineFunction &getMachineFunction() const { return *MF; }
470470
const Pass *getPass() const { return SDAGISelPass; }
471471

472+
CodeGenOptLevel getOptLevel() const { return OptLevel; }
472473
const DataLayout &getDataLayout() const { return MF->getDataLayout(); }
473474
const TargetMachine &getTarget() const { return TM; }
474475
const TargetSubtargetInfo &getSubtarget() const { return MF->getSubtarget(); }

llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,10 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
222222
if (!isa<AllocaInst>(I) || !StaticAllocaMap.count(cast<AllocaInst>(&I)))
223223
InitializeRegForValue(&I);
224224

225-
// Decide the preferred extend type for a value.
226-
PreferredExtendType[&I] = getPreferredExtendForValue(&I);
225+
// Decide the preferred extend type for a value. This iterates over all
226+
// users and therefore isn't cheap, so don't do this at O0.
227+
if (DAG->getOptLevel() != CodeGenOptLevel::None)
228+
PreferredExtendType[&I] = getPreferredExtendForValue(&I);
227229
}
228230
}
229231

0 commit comments

Comments
 (0)