diff options
author | Chris Lattner <sabre@nondot.org> | 2010-01-02 08:20:51 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-01-02 08:20:51 +0000 |
commit | 34e0c76f939d305a76785daa420f0cde650f17df (patch) | |
tree | da27cc9755d4c2473ea35c94cf019ec8e7af03fc /lib/Transforms/Scalar/InstructionCombining.cpp | |
parent | 1f12e44b628679d003e99adc70e1ea0464e1971e (diff) |
enhance the previous optimization to work with fcmp in addition
to icmp.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92412 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/InstructionCombining.cpp')
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 1fcc64efe9..05da044e38 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -6180,7 +6180,7 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) { if (Instruction *NV = FoldFCmp_IntToFP_Cst(I, LHSI, RHSC)) return NV; break; - case Instruction::Select: + case Instruction::Select: { // If either operand of the select is a constant, we can fold the // comparison into the select arms, which will cause one to be // constant folded and the select turned into a bitwise or. @@ -6205,6 +6205,20 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) { return SelectInst::Create(LHSI->getOperand(0), Op1, Op2); break; } + case Instruction::Load: + if (GetElementPtrInst *GEP = + dyn_cast<GetElementPtrInst>(LHSI->getOperand(0))) { + if (GlobalVariable *GV = dyn_cast<GlobalVariable>(GEP->getOperand(0))) + if (GV->isConstant() && GV->hasDefinitiveInitializer() && + !cast<LoadInst>(LHSI)->isVolatile()) + if (Instruction *Res = FoldCmpLoadFromIndexedGlobal(GEP, GV, I)) + return Res; + //errs() << "NOT HANDLED: " << *GV << "\n"; + //errs() << "\t" << *GEP << "\n"; + //errs() << "\t " << I << "\n\n\n"; + } + break; + } } return Changed ? &I : 0; @@ -6586,13 +6600,16 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { case Instruction::Load: if (GetElementPtrInst *GEP = - dyn_cast<GetElementPtrInst>(LHSI->getOperand(0))) + dyn_cast<GetElementPtrInst>(LHSI->getOperand(0))) { if (GlobalVariable *GV = dyn_cast<GlobalVariable>(GEP->getOperand(0))) if (GV->isConstant() && GV->hasDefinitiveInitializer() && - !cast<LoadInst>(LHSI)->isVolatile()) { + !cast<LoadInst>(LHSI)->isVolatile()) if (Instruction *Res = FoldCmpLoadFromIndexedGlobal(GEP, GV, I)) return Res; - } + //errs() << "NOT HANDLED: " << *GV << "\n"; + //errs() << "\t" << *GEP << "\n"; + //errs() << "\t " << I << "\n\n\n"; + } break; } } |