Skip to content

Commit c7957ef

Browse files
committed
Revert r282168 "GVN-hoist: fix store past load dependence analysis (PR30216)"
and also the dependent r282175 "GVN-hoist: do not dereference null pointers" It's causing compiler crashes building Harfbuzz (PR30499). llvm-svn: 282199
1 parent 5f78d38 commit c7957ef

File tree

2 files changed

+28
-87
lines changed

2 files changed

+28
-87
lines changed

llvm/lib/Transforms/Scalar/GVNHoist.cpp

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -329,56 +329,49 @@ class GVNHoist {
329329
return I1DFS < I2DFS;
330330
}
331331

332-
// Return true when there are memory uses of Def in BB.
333-
bool hasMemoryUseOnPath(const Instruction *NewPt, MemoryDef *Def, const BasicBlock *BB) {
334-
const Instruction *OldPt = Def->getMemoryInst();
332+
// Return true when there are users of Def in BB.
333+
bool hasMemoryUseOnPath(MemoryAccess *Def, const BasicBlock *BB,
334+
const Instruction *OldPt) {
335+
const BasicBlock *DefBB = Def->getBlock();
335336
const BasicBlock *OldBB = OldPt->getParent();
336-
const BasicBlock *NewBB = NewPt->getParent();
337337

338-
bool ReachedNewPt = false;
339-
MemoryLocation DefLoc = MemoryLocation::get(OldPt);
340-
const MemorySSA::AccessList *Acc = MSSA->getBlockAccesses(BB);
341-
if (!Acc)
342-
return false;
338+
for (User *U : Def->users())
339+
if (auto *MU = dyn_cast<MemoryUse>(U)) {
340+
// FIXME: MU->getBlock() does not get updated when we move the instruction.
341+
BasicBlock *UBB = MU->getMemoryInst()->getParent();
342+
// Only analyze uses in BB.
343+
if (BB != UBB)
344+
continue;
343345

344-
for (const MemoryAccess &MA : *Acc) {
345-
auto *MU = dyn_cast<MemoryUse>(&MA);
346-
if (!MU)
347-
continue;
346+
// A use in the same block as the Def is on the path.
347+
if (UBB == DefBB) {
348+
assert(MSSA->locallyDominates(Def, MU) && "def not dominating use");
349+
return true;
350+
}
348351

349-
// Do not check whether MU aliases Def when MU occurs after OldPt.
350-
if (BB == OldBB && firstInBB(OldPt, MU->getMemoryInst()))
351-
break;
352+
if (UBB != OldBB)
353+
return true;
352354

353-
// Do not check whether MU aliases Def when MU occurs before NewPt.
354-
if (BB == NewBB) {
355-
if (!ReachedNewPt) {
356-
if (firstInBB(MU->getMemoryInst(), NewPt))
357-
continue;
358-
ReachedNewPt = true;
359-
}
355+
// It is only harmful to hoist when the use is before OldPt.
356+
if (firstInBB(MU->getMemoryInst(), OldPt))
357+
return true;
360358
}
361359

362-
if (!AA->isNoAlias(DefLoc, MemoryLocation::get(MU->getMemoryInst())))
363-
return true;
364-
}
365-
366360
return false;
367361
}
368362

369363
// Return true when there are exception handling or loads of memory Def
370-
// between Def and NewPt. This function is only called for stores: Def is
371-
// the MemoryDef of the store to be hoisted.
364+
// between OldPt and NewPt.
372365

373366
// Decrement by 1 NBBsOnAllPaths for each block between HoistPt and BB, and
374367
// return true when the counter NBBsOnAllPaths reaces 0, except when it is
375368
// initialized to -1 which is unlimited.
376-
bool hasEHOrLoadsOnPath(const Instruction *NewPt, MemoryDef *Def,
377-
int &NBBsOnAllPaths) {
369+
bool hasEHOrLoadsOnPath(const Instruction *NewPt, const Instruction *OldPt,
370+
MemoryAccess *Def, int &NBBsOnAllPaths) {
378371
const BasicBlock *NewBB = NewPt->getParent();
379-
const BasicBlock *OldBB = Def->getBlock();
372+
const BasicBlock *OldBB = OldPt->getParent();
380373
assert(DT->dominates(NewBB, OldBB) && "invalid path");
381-
assert(DT->dominates(Def->getDefiningAccess()->getBlock(), NewBB) &&
374+
assert(DT->dominates(Def->getBlock(), NewBB) &&
382375
"def does not dominate new hoisting point");
383376

384377
// Walk all basic blocks reachable in depth-first iteration on the inverse
@@ -397,7 +390,7 @@ class GVNHoist {
397390
return true;
398391

399392
// Check that we do not move a store past loads.
400-
if (hasMemoryUseOnPath(NewPt, Def, *I))
393+
if (hasMemoryUseOnPath(Def, *I, OldPt))
401394
return true;
402395

403396
// Stop walk once the limit is reached.
@@ -480,7 +473,7 @@ class GVNHoist {
480473

481474
// Check for unsafe hoistings due to side effects.
482475
if (K == InsKind::Store) {
483-
if (hasEHOrLoadsOnPath(NewPt, dyn_cast<MemoryDef>(U), NBBsOnAllPaths))
476+
if (hasEHOrLoadsOnPath(NewPt, OldPt, D, NBBsOnAllPaths))
484477
return false;
485478
} else if (hasEHOnPath(NewBB, OldBB, NBBsOnAllPaths))
486479
return false;

llvm/test/Transforms/GVNHoist/pr30216.ll

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)