diff options
author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2014-10-01 10:07:28 +0000 |
---|---|---|
committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2014-10-01 10:07:28 +0000 |
commit | 815f2869adfe7e9dfec14f4f30639a6c129ee5cf (patch) | |
tree | 5960485430ff9e5e18e4f5538f7f708aacf7d7f2 /llvm/lib/Transforms | |
parent | 530b3edab61d968e1d0262561721a1cb28bda11b (diff) | |
download | bcm5719-llvm-815f2869adfe7e9dfec14f4f30639a6c129ee5cf.tar.gz bcm5719-llvm-815f2869adfe7e9dfec14f4f30639a6c129ee5cf.zip |
Revert r218721, r218735.
Failing bootstrap on Linux (arm, x86).
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/13139/steps/bootstrap%20clang/logs/stdio
http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-selfhost/builds/470
http://lab.llvm.org:8011/builders/clang-native-arm-lnt/builds/8518
llvm-svn: 218752
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombine.h | 11 | ||||
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 144 | ||||
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 8 |
3 files changed, 8 insertions, 155 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombine.h b/llvm/lib/Transforms/InstCombine/InstCombine.h index da7a22c0c6e..6c0d4e74a7a 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombine.h +++ b/llvm/lib/Transforms/InstCombine/InstCombine.h @@ -14,7 +14,6 @@ #include "llvm/Analysis/AssumptionTracker.h" #include "llvm/Analysis/TargetFolder.h" #include "llvm/Analysis/ValueTracking.h" -#include "llvm/IR/Dominators.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/InstVisitor.h" #include "llvm/IR/IntrinsicInst.h" @@ -99,7 +98,7 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner AssumptionTracker *AT; const DataLayout *DL; TargetLibraryInfo *TLI; - DominatorTree *DT; + DominatorTree *DT; // not required bool MadeIRChange; LibCallSimplifier *Simplifier; bool MinimizeSize; @@ -114,8 +113,7 @@ public: BuilderTy *Builder; static char ID; // Pass identification, replacement for typeid - InstCombiner() - : FunctionPass(ID), DL(nullptr), DT(nullptr), Builder(nullptr) { + InstCombiner() : FunctionPass(ID), DL(nullptr), Builder(nullptr) { MinimizeSize = false; initializeInstCombinerPass(*PassRegistry::getPassRegistry()); } @@ -244,11 +242,6 @@ public: // visitInstruction - Specify what to return for unhandled instructions... Instruction *visitInstruction(Instruction &I) { return nullptr; } - bool dominatesAllUses(const Instruction *DI, const Instruction *UI, - const BasicBlock *DB) const; - bool replacedSelectWithOperand(SelectInst *SI, const ICmpInst *Icmp, - const ConstantInt *CI1, - const ConstantInt *CI2); private: bool ShouldChangeType(Type *From, Type *To) const; diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index e10eab1f81a..00623b1cbf6 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2429,133 +2429,6 @@ static bool swapMayExposeCSEOpportunities(const Value * Op0, return GlobalSwapBenefits > 0; } -/// \brief Check that one use is in the same block as the definition and all -/// other uses are in blocks dominated by a given block -/// -/// \param DI Definition -/// \param UI Use -/// \param DB Block that must dominate all uses of \p DI outside -/// the parent block. Note there can be a use of \p DI in \p DB. -/// \return true when \p UI is the only use of \p DI in the parent block -/// and all other uses of \p DI are in blocks dominated by \p DB. -/// -bool InstCombiner::dominatesAllUses(const Instruction *DI, - const Instruction *UI, - const BasicBlock *DB) const { - assert(DI && UI && DI->getParent() == UI->getParent() && - "definition and use must be in the same block"); - // DominatorTree available? - if (!DT) - return false; - for (const User *U : DI->users()) { - auto *Usr = cast<Instruction>(U); - if (Usr != UI && !DT->dominates(DB, Usr->getParent())) - return false; - } - return true; -} - -/// -/// true when the instruction sequence within a block is select-cmp-br. -/// -static bool isChainSelectCmpBranch(const SelectInst *SI) { - const BasicBlock *BB = SI->getParent(); - if (!BB) - return false; - auto *BI = dyn_cast_or_null<BranchInst>(BB->getTerminator()); - if (!BI || BI->getNumSuccessors() != 2) - return false; - auto *IC = dyn_cast<ICmpInst>(BI->getCondition()); - if (!IC || (IC->getOperand(0) != SI && IC->getOperand(1) != SI)) - return false; - // FIXME: Conservatively suppress the optimization when the IC - // has a parent different from SI (including no parent). Otherwise - // the assertion in dominatesAllUses() fires and causes a build failure. - // Make the optimization safe w/o this condition. - if (SI->getParent() != IC->getParent()) - return false; - return true; -} - -/// -/// \brief True when a select result is replaced by one of its operands -/// in select-icmp sequence. This will eventually result in the elimination -/// of the select. -/// -/// \param SI Select instruction -/// \param Icmp Compare instruction -/// \param CI1 'true' when first select operand is equal to RHSC of Icmp -/// \param CI2 'true' when second select operand is equal to RHSC of Icmp -/// -/// Notes: -/// - The replacement is global and requires dominator information -/// - The caller is responsible for the actual replacement -/// -/// Example: -/// -/// entry: -/// %4 = select i1 %3, %C* %0, %C* null -/// %5 = icmp eq %C* %4, null -/// br i1 %5, label %9, label %7 -/// ... -/// ; <label>:7 ; preds = %entry -/// %8 = getelementptr inbounds %C* %4, i64 0, i32 0 -/// ... -/// -/// can be transformed to -/// -/// %5 = icmp eq %C* %0, null -/// %6 = select i1 %3, i1 %5, i1 true -/// br i1 %6, label %9, label %7 -/// ... -/// ; <label>:7 ; preds = %entry -/// %8 = getelementptr inbounds %C* %0, i64 0, i32 0 // replace by %0! -/// -/// Similar when the first operand of the select is a constant or/and -/// the compare is for not equal rather than equal. -/// -/// FIXME: Currently the function considers equal compares only. It should be -/// possbile to extend it to not equal compares also. -/// -bool InstCombiner::replacedSelectWithOperand(SelectInst *SI, - const ICmpInst *Icmp, - const ConstantInt *CI1, - const ConstantInt *CI2) { - if (isChainSelectCmpBranch(SI) && Icmp->isEquality()) { - // Code sequence is select - icmp.[eq|ne] - br - unsigned ReplaceWithOpd = 0; - if (CI1 && !CI1->isZero()) - // The first constant operand of the select and the RHS of - // the compare match, so try to substitute - // the select results with its second operand - // Example: - // %4 = select i1 %3, %C* null, %C* %0 - // %5 = icmp eq %C* %4, null - // ==> could replace select with second operand - ReplaceWithOpd = 2; - else if (CI2 && !CI2->isZero()) - // Similar when the second operand of the select is a constant - // Example: - // %4 = select i1 %3, %C* %0, %C* null - // %5 = icmp eq %C* %4, null - // ==> could replace select with first operand - ReplaceWithOpd = 1; - if (ReplaceWithOpd) { - // Replace select with operand on else path for EQ compares. - // Replace select with operand on then path for NE compares. - BasicBlock *Succ = - Icmp->getPredicate() == ICmpInst::ICMP_EQ - ? SI->getParent()->getTerminator()->getSuccessor(1) - : SI->getParent()->getTerminator()->getSuccessor(0); - if (InstCombiner::dominatesAllUses(SI, Icmp, Succ)) { - SI->replaceAllUsesWith(SI->getOperand(ReplaceWithOpd)); - return true; - } - } - } - return false; -} - Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { bool Changed = false; Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); @@ -3012,21 +2885,8 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { // fold to a constant (in which case the icmp is replaced with a select // which will usually simplify) or this is the only user of the // select (in which case we are trading a select+icmp for a simpler - // select+icmp) or all uses of the select can be replaced based on - // dominance information ("Global cases"). - bool Transform = false; - if (Op1 && Op2) - Transform = true; - else if (Op1 || Op2) { - if (LHSI->hasOneUse()) - Transform = true; - else - // Global cases - Transform = replacedSelectWithOperand( - cast<SelectInst>(LHSI), &I, dyn_cast_or_null<ConstantInt>(Op1), - dyn_cast_or_null<ConstantInt>(Op2)); - } - if (Transform) { + // select+icmp). + if ((Op1 && Op2) || (LHSI->hasOneUse() && (Op1 || Op2))) { if (!Op1) Op1 = Builder->CreateICmp(I.getPredicate(), LHSI->getOperand(1), RHSC, I.getName()); diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index a3a29b4e0bd..ac0c01e3c7b 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -90,7 +90,6 @@ INITIALIZE_PASS_BEGIN(InstCombiner, "instcombine", "Combine redundant instructions", false, false) INITIALIZE_PASS_DEPENDENCY(AssumptionTracker) INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfo) -INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) INITIALIZE_PASS_END(InstCombiner, "instcombine", "Combine redundant instructions", false, false) @@ -98,8 +97,6 @@ void InstCombiner::getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesCFG(); AU.addRequired<AssumptionTracker>(); AU.addRequired<TargetLibraryInfo>(); - AU.addRequired<DominatorTreeWrapperPass>(); - AU.addPreserved<DominatorTreeWrapperPass>(); } @@ -2936,9 +2933,12 @@ bool InstCombiner::runOnFunction(Function &F) { AT = &getAnalysis<AssumptionTracker>(); DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>(); DL = DLP ? &DLP->getDataLayout() : nullptr; - DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree(); TLI = &getAnalysis<TargetLibraryInfo>(); + DominatorTreeWrapperPass *DTWP = + getAnalysisIfAvailable<DominatorTreeWrapperPass>(); + DT = DTWP ? &DTWP->getDomTree() : nullptr; + // Minimizing size? MinimizeSize = F.getAttributes().hasAttribute(AttributeSet::FunctionIndex, Attribute::MinSize); |