From 104370ab37b6b6fb4d35fcd86a52f3c77af4cd20 Mon Sep 17 00:00:00 2001 From: James Molloy Date: Sun, 11 Sep 2016 09:00:03 +0000 Subject: [SimplifyCFG] Be even more conservative in SinkThenElseCodeToEnd This should *actually* fix PR30244. This cranks up the workaround for PR30188 so that we never sink loads or stores of allocas. The idea is that these should be removed by SROA/Mem2Reg, and any movement of them may well confuse SROA or just cause unwanted code churn. It's not ideal that the midend should be crippled like this, but that unwanted churn can really cause significant regressions in important workloads (tsan). llvm-svn: 281162 --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 34 +++++++++++++++++-------------- 1 file changed, 19 insertions(+), 15 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 64e75548e0f..877e55928d4 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1428,6 +1428,25 @@ static bool canSinkInstructions( 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); @@ -1441,21 +1460,6 @@ static bool canSinkInstructions( // FIXME: if the call was *already* indirect, we should do this. 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. - // 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; for (auto *I : Insts) PHIOperands[I].push_back(I->getOperand(OI)); } -- cgit v1.2.3