From c73fadaa843992bf859276f8c23badad7c3c2223 Mon Sep 17 00:00:00 2001 From: "David L. Jones" Date: Thu, 13 Jun 2019 02:04:45 +0000 Subject: Revert r361811: 'Re-commit r357452 (take 2): "SimplifyCFG SinkCommonCodeFromPredecessors ...' We have observed some failures with internal builds with this revision. - Performance regressions: - llvm's SingleSource/Misc evalloop shows performance regressions (although these may be red herrings). - Benchmarks for Abseil's SwissTable. - Correctness: - Failures for particular libicu tests when building the Google AppEngine SDK (for PHP). hwennborg has already been notified, and is aware of reproducer failures. llvm-svn: 363220 --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'llvm/lib/Transforms/Utils') diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 69df6549cb1..90b552035af 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1445,10 +1445,9 @@ HoistTerminator: static bool canSinkInstructions( ArrayRef Insts, DenseMap> &PHIOperands) { - // Prune out obviously bad instructions to move. Each instruction must have - // exactly zero or one use, and we check later that use is by a single, common - // PHI instruction in the successor. - bool HasUse = !Insts.front()->user_empty(); + // Prune out obviously bad instructions to move. Any non-store instruction + // must have exactly one use, and we check later that use is by a single, + // common PHI instruction in the successor. for (auto *I : Insts) { // These instructions may change or break semantics if moved. if (isa(I) || I->isEHPad() || isa(I) || @@ -1462,10 +1461,9 @@ static bool canSinkInstructions( if (C->isInlineAsm()) return false; - // Each instruction must have zero or one use. - if (HasUse && !I->hasOneUse()) - return false; - if (!HasUse && !I->user_empty()) + // Everything must have only one use too, apart from stores which + // have no uses. + if (!isa(I) && !I->hasOneUse()) return false; } @@ -1474,11 +1472,11 @@ static bool canSinkInstructions( if (!I->isSameOperationAs(I0)) return false; - // All instructions in Insts are known to be the same opcode. If they have a - // use, check that the only user is a PHI or in the same block as the - // instruction, because if a user is in the same block as an instruction we're - // contemplating sinking, it must already be determined to be sinkable. - if (HasUse) { + // All instructions in Insts are known to be the same opcode. If they aren't + // stores, check the only user of each is a PHI or in the same block as the + // instruction, because if a user is in the same block as an instruction + // we're contemplating sinking, it must already be determined to be sinkable. + if (!isa(I0)) { auto *PNUse = dyn_cast(*I0->user_begin()); auto *Succ = I0->getParent()->getTerminator()->getSuccessor(0); if (!all_of(Insts, [&PNUse,&Succ](const Instruction *I) -> bool { @@ -1556,7 +1554,7 @@ static bool sinkLastInstruction(ArrayRef Blocks) { // it is slightly over-aggressive - it gets confused by commutative instructions // so double-check it here. Instruction *I0 = Insts.front(); - if (!I0->user_empty()) { + if (!isa(I0)) { auto *PNUse = dyn_cast(*I0->user_begin()); if (!all_of(Insts, [&PNUse](const Instruction *I) -> bool { auto *U = cast(*I->user_begin()); @@ -1614,10 +1612,11 @@ static bool sinkLastInstruction(ArrayRef Blocks) { I0->andIRFlags(I); } - if (!I0->user_empty()) { + if (!isa(I0)) { // canSinkLastInstruction checked that all instructions were used by // one and only one PHI node. Find that now, RAUW it to our common // instruction and nuke it. + assert(I0->hasOneUse()); auto *PN = cast(*I0->user_begin()); PN->replaceAllUsesWith(I0); PN->eraseFromParent(); -- cgit v1.2.3