[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.

llvm-svn: 321461
This commit is contained in:
Sanjay Patel 2017-12-26 22:12:20 +00:00
parent 546c43fd1a
commit 14adbacd8a
2 changed files with 3 additions and 6 deletions

View File

@ -1631,9 +1631,5 @@ Instruction *InstCombiner::visitFRem(BinaryOperator &I) {
SQ.getWithInstruction(&I))) SQ.getWithInstruction(&I)))
return replaceInstUsesWith(I, V); return replaceInstUsesWith(I, V);
// Handle cases involving: rem X, (select Cond, Y, Z)
if (simplifyDivRemOfSelectWithZeroOp(I))
return &I;
return nullptr; return nullptr;
} }

View File

@ -594,11 +594,12 @@ define <2 x i32> @test23(<2 x i32> %A) {
ret <2 x i32> %mul 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) { define double @PR34870(i1 %cond, double %x, double %y) {
; CHECK-LABEL: @PR34870( ; 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]] ; CHECK-NEXT: ret double [[FMOD]]
; ;
%sel = select i1 %cond, double %y, double 0.0 %sel = select i1 %cond, double %y, double 0.0