diff options
author | Chris Lattner <sabre@nondot.org> | 2010-01-05 06:24:06 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-01-05 06:24:06 +0000 |
commit | d0db8e8bad3060d5c016483ecfc62d822bc84fb7 (patch) | |
tree | 12a3bc84eb41d30c7f6908101f3df9bbeb77a439 | |
parent | d12c27ce0079ba14e73e0c422a30dac68c631a23 (diff) | |
download | external_llvm-d0db8e8bad3060d5c016483ecfc62d822bc84fb7.zip external_llvm-d0db8e8bad3060d5c016483ecfc62d822bc84fb7.tar.gz external_llvm-d0db8e8bad3060d5c016483ecfc62d822bc84fb7.tar.bz2 |
remove massive over-genality manifested as a big template
that got instantiated. There is no reason for instcombine
to try this hard for simple associative optimizations. Next
up, eliminate the template completely.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92692 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/InstCombine/InstructionCombining.cpp | 61 |
1 files changed, 1 insertions, 60 deletions
diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp index 13df38a..a9a5558 100644 --- a/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -298,69 +298,10 @@ static Constant *SubOne(ConstantInt *C) { /// template<typename Functor> static Instruction *AssociativeOpt(BinaryOperator &Root, const Functor &F) { - unsigned Opcode = Root.getOpcode(); - Value *LHS = Root.getOperand(0); - // Quick check, see if the immediate LHS matches... - if (F.shouldApply(LHS)) + if (F.shouldApply(Root.getOperand(0))) return F.apply(Root); - // Otherwise, if the LHS is not of the same opcode as the root, return. - Instruction *LHSI = dyn_cast<Instruction>(LHS); - while (LHSI && LHSI->getOpcode() == Opcode && LHSI->hasOneUse()) { - // Should we apply this transform to the RHS? - bool ShouldApply = F.shouldApply(LHSI->getOperand(1)); - - // If not to the RHS, check to see if we should apply to the LHS... - if (!ShouldApply && F.shouldApply(LHSI->getOperand(0))) { - cast<BinaryOperator>(LHSI)->swapOperands(); // Make the LHS the RHS - ShouldApply = true; - } - - // If the functor wants to apply the optimization to the RHS of LHSI, - // reassociate the expression from ((? op A) op B) to (? op (A op B)) - if (ShouldApply) { - // Now all of the instructions are in the current basic block, go ahead - // and perform the reassociation. - Instruction *TmpLHSI = cast<Instruction>(Root.getOperand(0)); - - // First move the selected RHS to the LHS of the root... - Root.setOperand(0, LHSI->getOperand(1)); - - // Make what used to be the LHS of the root be the user of the root... - Value *ExtraOperand = TmpLHSI->getOperand(1); - if (&Root == TmpLHSI) { - Root.replaceAllUsesWith(Constant::getNullValue(TmpLHSI->getType())); - return 0; - } - Root.replaceAllUsesWith(TmpLHSI); // Users now use TmpLHSI - TmpLHSI->setOperand(1, &Root); // TmpLHSI now uses the root - BasicBlock::iterator ARI = &Root; ++ARI; - TmpLHSI->moveBefore(ARI); // Move TmpLHSI to after Root - ARI = Root; - - // Now propagate the ExtraOperand down the chain of instructions until we - // get to LHSI. - while (TmpLHSI != LHSI) { - Instruction *NextLHSI = cast<Instruction>(TmpLHSI->getOperand(0)); - // Move the instruction to immediately before the chain we are - // constructing to avoid breaking dominance properties. - NextLHSI->moveBefore(ARI); - ARI = NextLHSI; - - Value *NextOp = NextLHSI->getOperand(1); - NextLHSI->setOperand(1, ExtraOperand); - TmpLHSI = NextLHSI; - ExtraOperand = NextOp; - } - - // Now that the instructions are reassociated, have the functor perform - // the transformation... - return F.apply(Root); - } - - LHSI = dyn_cast<Instruction>(LHSI->getOperand(0)); - } return 0; } |