diff options
author | Chris Lattner <sabre@nondot.org> | 2008-02-19 06:12:18 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-02-19 06:12:18 +0000 |
commit | 50b2ca4c73c614574a847c43ad9b87301367c59b (patch) | |
tree | bf42bc8c4bdce01a1b61083ee13e53712b964e08 | |
parent | 389056110f861ef8f5af5c3c10ddd854d260a0b8 (diff) | |
download | external_llvm-50b2ca4c73c614574a847c43ad9b87301367c59b.zip external_llvm-50b2ca4c73c614574a847c43ad9b87301367c59b.tar.gz external_llvm-50b2ca4c73c614574a847c43ad9b87301367c59b.tar.bz2 |
fdiv/frem of undef can produce undef, because the undef operand
can be a SNaN. We could be more aggressive and turn this into
unreachable, but that is less nice, and not really worth it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47313 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 5582f51..9957bc1 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2590,9 +2590,13 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) { Instruction *InstCombiner::commonDivTransforms(BinaryOperator &I) { Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); - // undef / X -> 0 - if (isa<UndefValue>(Op0)) + // undef / X -> 0 for integer. + // undef / X -> undef for FP (the undef could be a snan). + if (isa<UndefValue>(Op0)) { + if (Op0->getType()->isFPOrFPVector()) + return ReplaceInstUsesWith(I, Op0); return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); + } // X / undef -> undef if (isa<UndefValue>(Op1)) @@ -2821,13 +2825,16 @@ static Constant *GetFactor(Value *V) { Instruction *InstCombiner::commonRemTransforms(BinaryOperator &I) { Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); - // 0 % X == 0, we don't need to preserve faults! + // 0 % X == 0 for integer, we don't need to preserve faults! if (Constant *LHS = dyn_cast<Constant>(Op0)) if (LHS->isNullValue()) return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); - if (isa<UndefValue>(Op0)) // undef % X -> 0 + if (isa<UndefValue>(Op0)) { // undef % X -> 0 + if (I.getType()->isFPOrFPVector()) + return ReplaceInstUsesWith(I, Op0); // X % undef -> undef (could be SNaN) return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); + } if (isa<UndefValue>(Op1)) return ReplaceInstUsesWith(I, Op1); // X % undef -> undef |