diff options
| author | Pedro Artigas <partigas@apple.com> | 2012-11-30 22:47:15 +0000 |
|---|---|---|
| committer | Pedro Artigas <partigas@apple.com> | 2012-11-30 22:47:15 +0000 |
| commit | 00b83c9b8d04eb391912320437ee5172a02ca8ce (patch) | |
| tree | 2dacc56e22d580de5a59acaa9f438cf056134fbf /llvm/lib | |
| parent | 3ae24ee08a4566ba1f79a390f8e018bab2b64ff1 (diff) | |
| download | bcm5719-llvm-00b83c9b8d04eb391912320437ee5172a02ca8ce.tar.gz bcm5719-llvm-00b83c9b8d04eb391912320437ee5172a02ca8ce.zip | |
reversed the logic of the log2 detection routine to reduce the number of nested ifs
llvm-svn: 169049
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index b0b9bac8f75..2fc5f85cd7e 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -261,31 +261,35 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) { // static void detectLog2OfHalf(Value *&Op, Value *&Y, IntrinsicInst *&Log2) { - if (Op->hasOneUse()) { - if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Op)) { - if (II->getIntrinsicID() == Intrinsic::log2 && - II->hasUnsafeAlgebra()) { - Log2 = II; - Value *OpLog2Of = II->getArgOperand(0); - if (OpLog2Of->hasOneUse()) { - if (Instruction *I = dyn_cast<Instruction>(OpLog2Of)) { - if (I->getOpcode() == Instruction::FMul && - I->hasUnsafeAlgebra()) { - ConstantFP *CFP = dyn_cast<ConstantFP>(I->getOperand(0)); - if (CFP && CFP->isExactlyValue(0.5)) { - Y = I->getOperand(1); - } else { - CFP = dyn_cast<ConstantFP>(I->getOperand(1)); - if (CFP && CFP->isExactlyValue(0.5)) { - Y = I->getOperand(0); - } - } - } - } - } - } - } - } + + if (!Op->hasOneUse()) + return; + + IntrinsicInst *II = dyn_cast<IntrinsicInst>(Op); + if (!II) + return; + if (II->getIntrinsicID() != Intrinsic::log2 || !II->hasUnsafeAlgebra()) + return; + Log2 = II; + + Value *OpLog2Of = II->getArgOperand(0); + if (!OpLog2Of->hasOneUse()) + return; + + Instruction *I = dyn_cast<Instruction>(OpLog2Of); + if (!I) + return; + if (I->getOpcode() != Instruction::FMul || !I->hasUnsafeAlgebra()) + return; + + ConstantFP *CFP = dyn_cast<ConstantFP>(I->getOperand(0)); + if (CFP && CFP->isExactlyValue(0.5)) { + Y = I->getOperand(1); + return; + } + CFP = dyn_cast<ConstantFP>(I->getOperand(1)); + if (CFP && CFP->isExactlyValue(0.5)) + Y = I->getOperand(0); } Instruction *InstCombiner::visitFMul(BinaryOperator &I) { |

