[InstSimplify] fix miscompiles with maximum/minimum intrinsics

As discussed in the sibling codegen functionality patch D87571,
this transform was created with D52766, but it is not correct.

The incorrect test diffs were missed during review, but the
'TODO' comment about this functionality was still in the code -
we need 'nnan' to enable this fold.
This commit is contained in:
Sanjay Patel 2020-09-14 09:06:41 -04:00
parent c799f873cb
commit 7bb9a2f996
2 changed files with 10 additions and 6 deletions

View File

@ -5476,9 +5476,9 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1,
bool UseNegInf = IID == Intrinsic::minnum || IID == Intrinsic::minimum;
const APFloat *C;
if ((match(Op0, m_APFloat(C)) && C->isInfinity() &&
C->isNegative() == UseNegInf) ||
C->isNegative() == UseNegInf && !PropagateNaN) ||
(match(Op1, m_APFloat(C)) && C->isInfinity() &&
C->isNegative() == UseNegInf))
C->isNegative() == UseNegInf && !PropagateNaN))
return ConstantFP::getInfinity(ReturnType, UseNegInf);
// TODO: minnum(nnan x, inf) -> x

View File

@ -1064,7 +1064,8 @@ define float @minimum_x_y_minimum_z(float %x, float %y, float %z) {
define float @minimum_neginf(float %x) {
; CHECK-LABEL: @minimum_neginf(
; CHECK-NEXT: ret float 0xFFF0000000000000
; CHECK-NEXT: [[VAL:%.*]] = call float @llvm.minimum.f32(float [[X:%.*]], float 0xFFF0000000000000)
; CHECK-NEXT: ret float [[VAL]]
;
%val = call float @llvm.minimum.f32(float %x, float 0xFFF0000000000000)
ret float %val
@ -1072,7 +1073,8 @@ define float @minimum_neginf(float %x) {
define <2 x double> @minimum_neginf_commute_vec(<2 x double> %x) {
; CHECK-LABEL: @minimum_neginf_commute_vec(
; CHECK-NEXT: ret <2 x double> <double 0xFFF0000000000000, double 0xFFF0000000000000>
; CHECK-NEXT: [[R:%.*]] = call <2 x double> @llvm.minimum.v2f64(<2 x double> <double 0xFFF0000000000000, double 0xFFF0000000000000>, <2 x double> [[X:%.*]])
; CHECK-NEXT: ret <2 x double> [[R]]
;
%r = call <2 x double> @llvm.minimum.v2f64(<2 x double> <double 0xFFF0000000000000, double 0xFFF0000000000000>, <2 x double> %x)
ret <2 x double> %r
@ -1158,7 +1160,8 @@ define float @maximum_x_y_maximum_z(float %x, float %y, float %z) {
define <2 x double> @maximum_inf(<2 x double> %x) {
; CHECK-LABEL: @maximum_inf(
; CHECK-NEXT: ret <2 x double> <double 0x7FF0000000000000, double 0x7FF0000000000000>
; CHECK-NEXT: [[VAL:%.*]] = call <2 x double> @llvm.maximum.v2f64(<2 x double> [[X:%.*]], <2 x double> <double 0x7FF0000000000000, double 0x7FF0000000000000>)
; CHECK-NEXT: ret <2 x double> [[VAL]]
;
%val = call <2 x double> @llvm.maximum.v2f64(<2 x double> %x, <2 x double><double 0x7FF0000000000000, double 0x7FF0000000000000>)
ret <2 x double> %val
@ -1166,7 +1169,8 @@ define <2 x double> @maximum_inf(<2 x double> %x) {
define float @maximum_inf_commute(float %x) {
; CHECK-LABEL: @maximum_inf_commute(
; CHECK-NEXT: ret float 0x7FF0000000000000
; CHECK-NEXT: [[VAL:%.*]] = call float @llvm.maximum.f32(float 0x7FF0000000000000, float [[X:%.*]])
; CHECK-NEXT: ret float [[VAL]]
;
%val = call float @llvm.maximum.f32(float 0x7FF0000000000000, float %x)
ret float %val