diff options
author | Frits van Bommel <fvbommel@gmail.com> | 2011-01-29 15:26:31 +0000 |
---|---|---|
committer | Frits van Bommel <fvbommel@gmail.com> | 2011-01-29 15:26:31 +0000 |
commit | 1fca2c32cc99197215d3fd32a4ad05214c74edd1 (patch) | |
tree | 9f358ce4aed7f898391854c5310aa5a6aaaf68ee /lib/Analysis/InstructionSimplify.cpp | |
parent | 9136782d273cd45b6f19a7d0cc0d146d0791bac9 (diff) |
Move InstCombine's knowledge of fdiv to SimplifyInstruction().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124534 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/InstructionSimplify.cpp')
-rw-r--r-- | lib/Analysis/InstructionSimplify.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp index 16cdfeb838..c1fa6fcca6 100644 --- a/lib/Analysis/InstructionSimplify.cpp +++ b/lib/Analysis/InstructionSimplify.cpp @@ -837,7 +837,7 @@ static Value *SimplifySDivInst(Value *Op0, Value *Op1, const TargetData *TD, } Value *llvm::SimplifySDivInst(Value *Op0, Value *Op1, const TargetData *TD, - const DominatorTree *DT) { + const DominatorTree *DT) { return ::SimplifySDivInst(Op0, Op1, TD, DT, RecursionLimit); } @@ -852,10 +852,28 @@ static Value *SimplifyUDivInst(Value *Op0, Value *Op1, const TargetData *TD, } Value *llvm::SimplifyUDivInst(Value *Op0, Value *Op1, const TargetData *TD, - const DominatorTree *DT) { + const DominatorTree *DT) { return ::SimplifyUDivInst(Op0, Op1, TD, DT, RecursionLimit); } +static Value *SimplifyFDivInst(Value *Op0, Value *Op1, const TargetData *TD, + const DominatorTree *DT, unsigned MaxRecurse) { + // undef / X -> undef (the undef could be a snan). + if (isa<UndefValue>(Op0)) + return Op0; + + // X / undef -> undef + if (isa<UndefValue>(Op1)) + return Op1; + + return 0; +} + +Value *llvm::SimplifyFDivInst(Value *Op0, Value *Op1, const TargetData *TD, + const DominatorTree *DT) { + return ::SimplifyFDivInst(Op0, Op1, TD, DT, RecursionLimit); +} + /// SimplifyShift - Given operands for an Shl, LShr or AShr, see if we can /// fold the result. If not, this returns null. static Value *SimplifyShift(unsigned Opcode, Value *Op0, Value *Op1, @@ -1760,6 +1778,7 @@ static Value *SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, case Instruction::Mul: return SimplifyMulInst(LHS, RHS, TD, DT, MaxRecurse); case Instruction::SDiv: return SimplifySDivInst(LHS, RHS, TD, DT, MaxRecurse); case Instruction::UDiv: return SimplifyUDivInst(LHS, RHS, TD, DT, MaxRecurse); + case Instruction::FDiv: return SimplifyFDivInst(LHS, RHS, TD, DT, MaxRecurse); case Instruction::Shl: return SimplifyShlInst(LHS, RHS, TD, DT, MaxRecurse); case Instruction::LShr: return SimplifyLShrInst(LHS, RHS, TD, DT, MaxRecurse); case Instruction::AShr: return SimplifyAShrInst(LHS, RHS, TD, DT, MaxRecurse); @@ -1847,6 +1866,9 @@ Value *llvm::SimplifyInstruction(Instruction *I, const TargetData *TD, case Instruction::UDiv: Result = SimplifyUDivInst(I->getOperand(0), I->getOperand(1), TD, DT); break; + case Instruction::FDiv: + Result = SimplifyFDivInst(I->getOperand(0), I->getOperand(1), TD, DT); + break; case Instruction::Shl: Result = SimplifyShlInst(I->getOperand(0), I->getOperand(1), TD, DT); break; |