From: Sanjay Patel Date: Tue, 26 Dec 2017 22:12:20 +0000 (+0000) Subject: [InstCombine] fix miscompile of frem with 0.0 operand (PR34870) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f186f082c569f37f10f8ef73ecad4b27d9359cab;p=llvm [InstCombine] fix miscompile of frem with 0.0 operand (PR34870) 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 --- diff --git a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index 87666360c1a..541dde6c47d 100644 --- a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -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; } diff --git a/test/Transforms/InstCombine/rem.ll b/test/Transforms/InstCombine/rem.ll index 348190df5b1..f71a0fb4c62 100644 --- a/test/Transforms/InstCombine/rem.ll +++ b/test/Transforms/InstCombine/rem.ll @@ -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