From: Aditya Kumar Date: Thu, 16 Mar 2017 14:09:18 +0000 (+0000) Subject: Fix: Refactor SimplifyCFG:canSinkInstructions [NFC] X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=610fcc0d5f9866bac27d9353fc9f3d4e28953269;p=llvm Fix: Refactor SimplifyCFG:canSinkInstructions [NFC] Differential Revision: https://reviews.llvm.org/D30116 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297955 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 589f96b171b..1869741b342 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1473,29 +1473,28 @@ static bool canSinkInstructions( return false; } + // Because SROA can't handle speculating stores of selects, try not + // to sink loads or stores of allocas when we'd have to create a PHI for + // the address operand. Also, because it is likely that loads or stores + // of allocas will disappear when Mem2Reg/SROA is run, don't sink them. + // This can cause code churn which can have unintended consequences down + // the line - see https://llvm.org/bugs/show_bug.cgi?id=30244. + // FIXME: This is a workaround for a deficiency in SROA - see + // https://llvm.org/bugs/show_bug.cgi?id=30188 + if (isa(I0) && any_of(Insts, [](const Instruction *I) { + return isa(I->getOperand(1)); + })) + return false; + if (isa(I0) && any_of(Insts, [](const Instruction *I) { + return isa(I->getOperand(0)); + })) + return false; + for (unsigned OI = 0, OE = I0->getNumOperands(); OI != OE; ++OI) { if (I0->getOperand(OI)->getType()->isTokenTy()) // Don't touch any operand of token type. return false; - // Because SROA can't handle speculating stores of selects, try not - // to sink loads or stores of allocas when we'd have to create a PHI for - // the address operand. Also, because it is likely that loads or stores - // of allocas will disappear when Mem2Reg/SROA is run, don't sink them. - // This can cause code churn which can have unintended consequences down - // the line - see https://llvm.org/bugs/show_bug.cgi?id=30244. - // FIXME: This is a workaround for a deficiency in SROA - see - // https://llvm.org/bugs/show_bug.cgi?id=30188 - if (OI == 1 && isa(I0) && - any_of(Insts, [](const Instruction *I) { - return isa(I->getOperand(1)); - })) - return false; - if (OI == 0 && isa(I0) && any_of(Insts, [](const Instruction *I) { - return isa(I->getOperand(0)); - })) - return false; - auto SameAsI0 = [&I0, OI](const Instruction *I) { assert(I->getNumOperands() == I0->getNumOperands()); return I->getOperand(OI) == I0->getOperand(OI);