[InstCombine] intersect FMF when reassociating FP min/max intrinsics

As discussed in PR45478:
https://bugs.llvm.org/show_bug.cgi?id=45478
...propagating FMF from the outer (second) call is not correct,
so intersect them instead.
I suspect we could do better (see TODO comment), but mismatched
FMF is probably too rare to care about.

Differential Revision: https://reviews.llvm.org/D78631
This commit is contained in:
Sanjay Patel 2020-04-24 11:59:15 -04:00
parent 1fcd234ac5
commit e4175ff525
5 changed files with 15 additions and 12 deletions

View File

@ -2298,8 +2298,11 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
llvm_unreachable("unexpected intrinsic ID");
}
Instruction *NewCall = Builder.CreateBinaryIntrinsic(
IID, X, ConstantFP::get(Arg0->getType(), Res));
NewCall->copyIRFlags(II);
IID, X, ConstantFP::get(Arg0->getType(), Res), II);
// TODO: Conservatively intersecting FMF. If Res == C2, the transform
// was a simplification (so Arg0 and its original flags could
// propagate?)
NewCall->andIRFlags(M);
return replaceInstUsesWith(*II, NewCall);
}
}

View File

@ -157,7 +157,7 @@ define float @maximum_f32_1_maximum_val_p0(float %x) {
define float @maximum_f32_1_maximum_p0_val_fast(float %x) {
; CHECK-LABEL: @maximum_f32_1_maximum_p0_val_fast(
; CHECK-NEXT: [[TMP1:%.*]] = call fast float @llvm.maximum.f32(float [[X:%.*]], float 1.000000e+00)
; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.maximum.f32(float [[X:%.*]], float 1.000000e+00)
; CHECK-NEXT: ret float [[TMP1]]
;
%y = call float @llvm.maximum.f32(float 0.0, float %x)
@ -167,7 +167,7 @@ define float @maximum_f32_1_maximum_p0_val_fast(float %x) {
define float @maximum_f32_1_maximum_p0_val_fmf1(float %x) {
; CHECK-LABEL: @maximum_f32_1_maximum_p0_val_fmf1(
; CHECK-NEXT: [[TMP1:%.*]] = call nnan ninf arcp float @llvm.maximum.f32(float [[X:%.*]], float 1.000000e+00)
; CHECK-NEXT: [[TMP1:%.*]] = call nnan arcp float @llvm.maximum.f32(float [[X:%.*]], float 1.000000e+00)
; CHECK-NEXT: ret float [[TMP1]]
;
%y = call arcp nnan float @llvm.maximum.f32(float 0.0, float %x)
@ -187,7 +187,7 @@ define float @maximum_f32_1_maximum_p0_val_fmf2(float %x) {
define float @maximum_f32_1_maximum_p0_val_fmf3(float %x) {
; CHECK-LABEL: @maximum_f32_1_maximum_p0_val_fmf3(
; CHECK-NEXT: [[TMP1:%.*]] = call nnan ninf arcp float @llvm.maximum.f32(float [[X:%.*]], float 1.000000e+00)
; CHECK-NEXT: [[TMP1:%.*]] = call nnan ninf float @llvm.maximum.f32(float [[X:%.*]], float 1.000000e+00)
; CHECK-NEXT: ret float [[TMP1]]
;
%y = call nnan ninf float @llvm.maximum.f32(float 0.0, float %x)

View File

@ -157,7 +157,7 @@ define float @maxnum_f32_1_maxnum_val_p0(float %x) {
define float @maxnum_f32_1_maxnum_p0_val_fast(float %x) {
; CHECK-LABEL: @maxnum_f32_1_maxnum_p0_val_fast(
; CHECK-NEXT: [[TMP1:%.*]] = call fast float @llvm.maxnum.f32(float [[X:%.*]], float 1.000000e+00)
; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float 1.000000e+00)
; CHECK-NEXT: ret float [[TMP1]]
;
%y = call float @llvm.maxnum.f32(float 0.0, float %x)
@ -167,7 +167,7 @@ define float @maxnum_f32_1_maxnum_p0_val_fast(float %x) {
define float @minnum_f32_1_maxnum_p0_val_fmf1(float %x) {
; CHECK-LABEL: @minnum_f32_1_maxnum_p0_val_fmf1(
; CHECK-NEXT: [[TMP1:%.*]] = call nnan ninf float @llvm.maxnum.f32(float [[X:%.*]], float 1.000000e+00)
; CHECK-NEXT: [[TMP1:%.*]] = call nnan float @llvm.maxnum.f32(float [[X:%.*]], float 1.000000e+00)
; CHECK-NEXT: ret float [[TMP1]]
;
%y = call nnan float @llvm.maxnum.f32(float 0.0, float %x)

View File

@ -159,7 +159,7 @@ define float @minimum_f32_1_minimum_val_p0(float %x) {
define float @minimum_f32_1_minimum_p0_val_fast(float %x) {
; CHECK-LABEL: @minimum_f32_1_minimum_p0_val_fast(
; CHECK-NEXT: [[TMP1:%.*]] = call fast float @llvm.minimum.f32(float [[X:%.*]], float 0.000000e+00)
; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.minimum.f32(float [[X:%.*]], float 0.000000e+00)
; CHECK-NEXT: ret float [[TMP1]]
;
%y = call float @llvm.minimum.f32(float 0.0, float %x)
@ -169,7 +169,7 @@ define float @minimum_f32_1_minimum_p0_val_fast(float %x) {
define float @minimum_f32_1_minimum_p0_val_fmf1(float %x) {
; CHECK-LABEL: @minimum_f32_1_minimum_p0_val_fmf1(
; CHECK-NEXT: [[TMP1:%.*]] = call nnan ninf float @llvm.minimum.f32(float [[X:%.*]], float 0.000000e+00)
; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.minimum.f32(float [[X:%.*]], float 0.000000e+00)
; CHECK-NEXT: ret float [[TMP1]]
;
%y = call float @llvm.minimum.f32(float 0.0, float %x)

View File

@ -159,7 +159,7 @@ define float @minnum_f32_1_minnum_val_p0(float %x) {
define float @minnum_f32_1_minnum_p0_val_fast(float %x) {
; CHECK-LABEL: @minnum_f32_1_minnum_p0_val_fast(
; CHECK-NEXT: [[TMP1:%.*]] = call fast float @llvm.minnum.f32(float [[X:%.*]], float 0.000000e+00)
; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], float 0.000000e+00)
; CHECK-NEXT: ret float [[TMP1]]
;
%y = call float @llvm.minnum.f32(float 0.0, float %x)
@ -169,7 +169,7 @@ define float @minnum_f32_1_minnum_p0_val_fast(float %x) {
define float @minnum_f32_1_minnum_p0_val_fmf1(float %x) {
; CHECK-LABEL: @minnum_f32_1_minnum_p0_val_fmf1(
; CHECK-NEXT: [[TMP1:%.*]] = call nnan ninf float @llvm.minnum.f32(float [[X:%.*]], float 0.000000e+00)
; CHECK-NEXT: [[TMP1:%.*]] = call nnan float @llvm.minnum.f32(float [[X:%.*]], float 0.000000e+00)
; CHECK-NEXT: ret float [[TMP1]]
;
%y = call nsz nnan float @llvm.minnum.f32(float 0.0, float %x)
@ -179,7 +179,7 @@ define float @minnum_f32_1_minnum_p0_val_fmf1(float %x) {
define float @minnum_f32_1_minnum_p0_val_fmf2(float %x) {
; CHECK-LABEL: @minnum_f32_1_minnum_p0_val_fmf2(
; CHECK-NEXT: [[TMP1:%.*]] = call ninf nsz float @llvm.minnum.f32(float [[X:%.*]], float 0.000000e+00)
; CHECK-NEXT: [[TMP1:%.*]] = call ninf float @llvm.minnum.f32(float [[X:%.*]], float 0.000000e+00)
; CHECK-NEXT: ret float [[TMP1]]
;
%y = call nnan ninf float @llvm.minnum.f32(float 0.0, float %x)