reversed the logic of the log2 detection routine to reduce the number of nested ifs

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169049 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Pedro Artigas 2012-11-30 22:47:15 +00:00
parent d6964741f5
commit ef2ef3e246

View File

@ -261,32 +261,36 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
// //
static void detectLog2OfHalf(Value *&Op, Value *&Y, IntrinsicInst *&Log2) { static void detectLog2OfHalf(Value *&Op, Value *&Y, IntrinsicInst *&Log2) {
if (Op->hasOneUse()) {
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Op)) { if (!Op->hasOneUse())
if (II->getIntrinsicID() == Intrinsic::log2 && return;
II->hasUnsafeAlgebra()) {
IntrinsicInst *II = dyn_cast<IntrinsicInst>(Op);
if (!II)
return;
if (II->getIntrinsicID() != Intrinsic::log2 || !II->hasUnsafeAlgebra())
return;
Log2 = II; Log2 = II;
Value *OpLog2Of = II->getArgOperand(0); Value *OpLog2Of = II->getArgOperand(0);
if (OpLog2Of->hasOneUse()) { if (!OpLog2Of->hasOneUse())
if (Instruction *I = dyn_cast<Instruction>(OpLog2Of)) { return;
if (I->getOpcode() == Instruction::FMul &&
I->hasUnsafeAlgebra()) { 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)); ConstantFP *CFP = dyn_cast<ConstantFP>(I->getOperand(0));
if (CFP && CFP->isExactlyValue(0.5)) { if (CFP && CFP->isExactlyValue(0.5)) {
Y = I->getOperand(1); Y = I->getOperand(1);
} else { return;
}
CFP = dyn_cast<ConstantFP>(I->getOperand(1)); CFP = dyn_cast<ConstantFP>(I->getOperand(1));
if (CFP && CFP->isExactlyValue(0.5)) { if (CFP && CFP->isExactlyValue(0.5))
Y = I->getOperand(0); Y = I->getOperand(0);
} }
}
}
}
}
}
}
}
}
Instruction *InstCombiner::visitFMul(BinaryOperator &I) { Instruction *InstCombiner::visitFMul(BinaryOperator &I) {
bool Changed = SimplifyAssociativeOrCommutative(I); bool Changed = SimplifyAssociativeOrCommutative(I);