[llvm] r321461 - [InstCombine] fix miscompile of frem with 0.0 operand (PR34870)
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 26 14:12:20 PST 2017
Author: spatel
Date: Tue Dec 26 14:12:20 2017
New Revision: 321461
URL: http://llvm.org/viewvc/llvm-project?rev=321461&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/trunk/test/Transforms/InstCombine/rem.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=321461&r1=321460&r2=321461&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Tue Dec 26 14:12:20 2017
@@ -1631,9 +1631,5 @@ Instruction *InstCombiner::visitFRem(Bin
SQ.getWithInstruction(&I)))
return replaceInstUsesWith(I, V);
- // Handle cases involving: rem X, (select Cond, Y, Z)
- if (simplifyDivRemOfSelectWithZeroOp(I))
- return &I;
-
return nullptr;
}
Modified: llvm/trunk/test/Transforms/InstCombine/rem.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/rem.ll?rev=321461&r1=321460&r2=321461&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/rem.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/rem.ll Tue Dec 26 14:12:20 2017
@@ -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
More information about the llvm-commits
mailing list