]> granicus.if.org Git - llvm/commitdiff
[InstCombine] fix miscompile of frem with 0.0 operand (PR34870)
authorSanjay Patel <spatel@rotateright.com>
Tue, 26 Dec 2017 22:12:20 +0000 (22:12 +0000)
committerSanjay Patel <spatel@rotateright.com>
Tue, 26 Dec 2017 22:12:20 +0000 (22:12 +0000)
We might want to select NAN here or do this transform with fast-math,
but this should at least fix the miscompile.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321461 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
test/Transforms/InstCombine/rem.ll

index 87666360c1a08dfe2ff192d23a98fb60f336d211..541dde6c47d2e801f737c64f988bb5979286b894 100644 (file)
@@ -1631,9 +1631,5 @@ Instruction *InstCombiner::visitFRem(BinaryOperator &I) {
                                   SQ.getWithInstruction(&I)))
     return replaceInstUsesWith(I, V);
 
-  // Handle cases involving: rem X, (select Cond, Y, Z)
-  if (simplifyDivRemOfSelectWithZeroOp(I))
-    return &I;
-
   return nullptr;
 }
index 348190df5b104c031c98ff70ccccf78cb4db545b..f71a0fb4c621df6795b7a653b952f118740a3c46 100644 (file)
@@ -594,11 +594,12 @@ define <2 x i32> @test23(<2 x i32> %A) {
   ret <2 x i32> %mul
 }
 
-; FIXME: FP division-by-zero is not UB.
+; FP division-by-zero is not UB.
 
 define double @PR34870(i1 %cond, double %x, double %y) {
 ; CHECK-LABEL: @PR34870(
-; CHECK-NEXT:    [[FMOD:%.*]] = frem double %x, %y
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 %cond, double %y, double 0.000000e+00
+; CHECK-NEXT:    [[FMOD:%.*]] = frem double %x, [[SEL]]
 ; CHECK-NEXT:    ret double [[FMOD]]
 ;
   %sel = select i1 %cond, double %y, double 0.0