Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 50b2ca4

Browse files
committed
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
1 parent 3890561 commit 50b2ca4

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lib/Transforms/Scalar/InstructionCombining.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,9 +2590,13 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
25902590
Instruction *InstCombiner::commonDivTransforms(BinaryOperator &I) {
25912591
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
25922592

2593-
// undef / X -> 0
2594-
if (isa<UndefValue>(Op0))
2593+
// undef / X -> 0 for integer.
2594+
// undef / X -> undef for FP (the undef could be a snan).
2595+
if (isa<UndefValue>(Op0)) {
2596+
if (Op0->getType()->isFPOrFPVector())
2597+
return ReplaceInstUsesWith(I, Op0);
25952598
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
2599+
}
25962600

25972601
// X / undef -> undef
25982602
if (isa<UndefValue>(Op1))
@@ -2821,13 +2825,16 @@ static Constant *GetFactor(Value *V) {
28212825
Instruction *InstCombiner::commonRemTransforms(BinaryOperator &I) {
28222826
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
28232827

2824-
// 0 % X == 0, we don't need to preserve faults!
2828+
// 0 % X == 0 for integer, we don't need to preserve faults!
28252829
if (Constant *LHS = dyn_cast<Constant>(Op0))
28262830
if (LHS->isNullValue())
28272831
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
28282832

2829-
if (isa<UndefValue>(Op0)) // undef % X -> 0
2833+
if (isa<UndefValue>(Op0)) { // undef % X -> 0
2834+
if (I.getType()->isFPOrFPVector())
2835+
return ReplaceInstUsesWith(I, Op0); // X % undef -> undef (could be SNaN)
28302836
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
2837+
}
28312838
if (isa<UndefValue>(Op1))
28322839
return ReplaceInstUsesWith(I, Op1); // X % undef -> undef
28332840

0 commit comments

Comments
 (0)