@@ -2590,9 +2590,13 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
2590
2590
Instruction *InstCombiner::commonDivTransforms (BinaryOperator &I) {
2591
2591
Value *Op0 = I.getOperand (0 ), *Op1 = I.getOperand (1 );
2592
2592
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);
2595
2598
return ReplaceInstUsesWith (I, Constant::getNullValue (I.getType ()));
2599
+ }
2596
2600
2597
2601
// X / undef -> undef
2598
2602
if (isa<UndefValue>(Op1))
@@ -2821,13 +2825,16 @@ static Constant *GetFactor(Value *V) {
2821
2825
Instruction *InstCombiner::commonRemTransforms (BinaryOperator &I) {
2822
2826
Value *Op0 = I.getOperand (0 ), *Op1 = I.getOperand (1 );
2823
2827
2824
- // 0 % X == 0, we don't need to preserve faults!
2828
+ // 0 % X == 0 for integer , we don't need to preserve faults!
2825
2829
if (Constant *LHS = dyn_cast<Constant>(Op0))
2826
2830
if (LHS->isNullValue ())
2827
2831
return ReplaceInstUsesWith (I, Constant::getNullValue (I.getType ()));
2828
2832
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)
2830
2836
return ReplaceInstUsesWith (I, Constant::getNullValue (I.getType ()));
2837
+ }
2831
2838
if (isa<UndefValue>(Op1))
2832
2839
return ReplaceInstUsesWith (I, Op1); // X % undef -> undef
2833
2840
0 commit comments