Skip to content

Commit e80f32f

Browse files
authored
[CodeGenPrepare] Use Instruction::comesBefore instead of manual ordering (llvm#190485)
After llvm#172329, we noticed that some sources compiled with MSan take 1000x longer to compile. This is caused by quadratic complexity in tryToSinkFreeOperands, which can be called on a significant number of instructions within huge basic blocks. This inefficiency was introduced in 9cfa9b4, which manually iterates and creates a DenseMap of entire basic blocks for each interesting instruction. This patch avoids the manual ordering by using Instruction::comesBefore(), which provides the exact same ordering much more efficiently.
1 parent 49093c4 commit e80f32f

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7968,17 +7968,12 @@ bool CodeGenPrepare::tryToSinkFreeOperands(Instruction *I) {
79687968
bool Changed = false;
79697969
SmallVector<Use *, 4> ToReplace;
79707970
Instruction *InsertPoint = I;
7971-
DenseMap<const Instruction *, unsigned long> InstOrdering;
7972-
unsigned long InstNumber = 0;
7973-
for (const auto &I : *TargetBB)
7974-
InstOrdering[&I] = InstNumber++;
7975-
79767971
for (Use *U : reverse(OpsToSink)) {
79777972
auto *UI = cast<Instruction>(U->get());
79787973
if (isa<PHINode>(UI) || UI->mayHaveSideEffects() || UI->mayReadFromMemory())
79797974
continue;
79807975
if (UI->getParent() == TargetBB) {
7981-
if (InstOrdering[UI] < InstOrdering[InsertPoint])
7976+
if (UI->comesBefore(InsertPoint))
79827977
InsertPoint = UI;
79837978
continue;
79847979
}

0 commit comments

Comments
 (0)