From 923e98c232fe8e06fa73fba29cd789e42499df5d Mon Sep 17 00:00:00 2001 From: James Molloy Date: Wed, 31 Aug 2016 10:46:16 +0000 Subject: [SimplifyCFG] Tail-merge calls with sideeffects This was deliberately disabled during my rewrite of SinkIfThenToEnd to keep behaviour at least vaguely consistent with the previous version and keep it as close to NFC as I could. There's no real reason not to merge sideeffect calls though, so let's do it! Small fixup along the way to ensure we don't create indirect calls. Should fix PR28964. llvm-svn: 280215 --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp') diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 2868641..dc36a6e 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1433,11 +1433,6 @@ static bool canSinkLastInstruction(ArrayRef Blocks, if (isa(I) || I->isEHPad() || isa(I) || I->getType()->isTokenTy()) return false; - // Apart from loads and stores, we won't move anything that could - // change memory or have sideeffects. - if (!isa(I) && !isa(I) && - (I->mayHaveSideEffects() || I->mayHaveSideEffects())) - return false; // Everything must have only one use too, apart from stores which // have no uses. if (!isa(I) && !I->hasOneUse()) @@ -1472,10 +1467,11 @@ static bool canSinkLastInstruction(ArrayRef Blocks, if (!canReplaceOperandWithVariable(I0, OI)) // We can't create a PHI from this GEP. return false; - if ((isa(I0) || isa(I0)) && OI != 0) - // Don't create indirect calls! + // Don't create indirect calls! The called value is the final operand. + if ((isa(I0) || isa(I0)) && OI == OE - 1) { // FIXME: if the call was *already* indirect, we should do this. return false; + } ++NumPHIsRequired; } } -- cgit v1.1