[PATCH] D70488: [InstCombine] Infer fast math flags on fadd/fsub/fmul/fcmp

2019-11-21 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer added a comment.

In D70488#1753897 , @mcberg2017 wrote:

> For us this would be an impediment as we have math models that want ieee 
> behavior while relaxing precision.  Adding nnan or ninf would obstruct those 
> choices.


Mind elaborating why nnan/ninf are problematic for you? They're supposed to be 
a hint to the optimizer and can be dropped any time.

In D70488#1753832 , @spatel wrote:

> I like the idea, but I'd be more comfortable reviewing the diffs in stages, 
> so we know that the test coverage for the value tracking calls is good. So 
> I'd prefer if we split this somehow - either by the opcode callers (fadd, 
> fsub, fmul...) or the the FMF analysis (nnan, nsz, ninf). That raises a few 
> questions:
>
> 1. Why aren't fdiv and frem included?


We currently cannot infer anything for fdiv/frem in isKnownNeverNaN/Inf so 
there's no way to test it.

> 2. Can we infer FMF for FP intrinsics/libcalls/select/phi? (follow-on patches)

Yeah, that's a logical followup

> 3. We're moving away from FMF on fcmp (recent step: rGebf9bf2cbc8f 
> ), so is 
> it worth including starting from fcmp, or can we wait for that part to 
> settle? (Side question may be if/when we're going to allow FMF on 
> fptrunc/fpextend).

I'll drop fcmp then and split this up once we know that it's actually a 
direction we want to pursue.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70488/new/

https://reviews.llvm.org/D70488



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70488: [InstCombine] Infer fast math flags on fadd/fsub/fmul/fcmp

2019-11-20 Thread Michael Berg via Phabricator via cfe-commits
mcberg2017 added a comment.

For us this would be an impediment as we have math models that want ieee 
behavior while relaxing precision.  Adding nnan or ninf would obstruct those 
choices.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70488/new/

https://reviews.llvm.org/D70488



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70488: [InstCombine] Infer fast math flags on fadd/fsub/fmul/fcmp

2019-11-20 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added reviewers: cameron.mcinally, mcberg2017, arsenm.
spatel added a comment.
Herald added a subscriber: wdng.

I like the idea, but I'd be more comfortable reviewing the diffs in stages, so 
we know that the test coverage for the value tracking calls is good. So I'd 
prefer if we split this somehow - either by the opcode callers (fadd, fsub, 
fmul...) or the the FMF analysis (nnan, nsz, ninf). That raises a few questions:

1. Why aren't fdiv and frem included?
2. Can we infer FMF for FP intrinsics/libcalls/select/phi? (follow-on patches)
3. We're moving away from FMF on fcmp (recent step: rGebf9bf2cbc8f 
), so is 
it worth including that change, or can we wait for that part to settle? (Side 
question may be if/when we're going to allow FMF on fptrunc/fpextend).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70488/new/

https://reviews.llvm.org/D70488



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70488: [InstCombine] Infer fast math flags on fadd/fsub/fmul/fcmp

2019-11-20 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer updated this revision to Diff 230245.
bkramer added a comment.

Fix condition


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70488/new/

https://reviews.llvm.org/D70488

Files:
  clang/test/CodeGen/builtins-systemz-zvector.c
  llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
  llvm/lib/Transforms/InstCombine/InstCombineInternal.h
  llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/add-sitofp.ll
  llvm/test/Transforms/InstCombine/cast-int-fcmp-eq-0.ll
  llvm/test/Transforms/InstCombine/fadd-fsub-factor.ll
  llvm/test/Transforms/InstCombine/fast-math.ll
  llvm/test/Transforms/InstCombine/fcmp.ll
  llvm/test/Transforms/InstCombine/known-never-nan.ll
  llvm/test/Transforms/InstCombine/minmax-fp.ll
  llvm/test/Transforms/InstCombine/pow_fp_int.ll

Index: llvm/test/Transforms/InstCombine/pow_fp_int.ll
===
--- llvm/test/Transforms/InstCombine/pow_fp_int.ll
+++ llvm/test/Transforms/InstCombine/pow_fp_int.ll
@@ -91,7 +91,7 @@
 define double @pow_uitofp_const_base_power_of_2_fast(i31 %x) {
 ; CHECK-LABEL: @pow_uitofp_const_base_power_of_2_fast(
 ; CHECK-NEXT:[[SUBFP:%.*]] = uitofp i31 [[X:%.*]] to float
-; CHECK-NEXT:[[MUL:%.*]] = fmul afn float [[SUBFP]], 4.00e+00
+; CHECK-NEXT:[[MUL:%.*]] = fmul nnan afn float [[SUBFP]], 4.00e+00
 ; CHECK-NEXT:[[EXP2:%.*]] = call afn float @llvm.exp2.f32(float [[MUL]])
 ; CHECK-NEXT:[[RES:%.*]] = fpext float [[EXP2]] to double
 ; CHECK-NEXT:ret double [[RES]]
@@ -383,7 +383,7 @@
 define double @pow_uitofp_const_base_power_of_2_no_fast(i32 %x) {
 ; CHECK-LABEL: @pow_uitofp_const_base_power_of_2_no_fast(
 ; CHECK-NEXT:[[SUBFP:%.*]] = uitofp i32 [[X:%.*]] to float
-; CHECK-NEXT:[[MUL:%.*]] = fmul float [[SUBFP]], 4.00e+00
+; CHECK-NEXT:[[MUL:%.*]] = fmul nnan float [[SUBFP]], 4.00e+00
 ; CHECK-NEXT:[[EXP2:%.*]] = call float @llvm.exp2.f32(float [[MUL]])
 ; CHECK-NEXT:[[RES:%.*]] = fpext float [[EXP2]] to double
 ; CHECK-NEXT:ret double [[RES]]
Index: llvm/test/Transforms/InstCombine/minmax-fp.ll
===
--- llvm/test/Transforms/InstCombine/minmax-fp.ll
+++ llvm/test/Transforms/InstCombine/minmax-fp.ll
@@ -273,7 +273,7 @@
 ; CHECK-LABEL: define {{[^@]+}}@fsub_fmax(
 ; CHECK-NEXT:[[COND_INV:%.*]] = fcmp nnan nsz ogt <2 x float> [[X:%.*]], [[Y:%.*]]
 ; CHECK-NEXT:[[TMP1:%.*]] = select nnan nsz <2 x i1> [[COND_INV]], <2 x float> [[Y]], <2 x float> [[X]]
-; CHECK-NEXT:[[MAX:%.*]] = fsub <2 x float> , [[TMP1]]
+; CHECK-NEXT:[[MAX:%.*]] = fsub nnan <2 x float> , [[TMP1]]
 ; CHECK-NEXT:ret <2 x float> [[MAX]]
 ;
   %n1 = fsub <2 x float> , %x
Index: llvm/test/Transforms/InstCombine/known-never-nan.ll
===
--- llvm/test/Transforms/InstCombine/known-never-nan.ll
+++ llvm/test/Transforms/InstCombine/known-never-nan.ll
@@ -11,7 +11,7 @@
 ; CHECK-LABEL: @fabs_sqrt_src_maybe_nan(
 ; CHECK-NEXT:[[FABS:%.*]] = call double @llvm.fabs.f64(double [[ARG0:%.*]])
 ; CHECK-NEXT:[[OP:%.*]] = call double @llvm.sqrt.f64(double [[FABS]])
-; CHECK-NEXT:[[TMP:%.*]] = fcmp ord double [[OP]], 0.00e+00
+; CHECK-NEXT:[[TMP:%.*]] = fcmp nsz ord double [[OP]], 0.00e+00
 ; CHECK-NEXT:ret i1 [[TMP]]
 ;
   %fabs = call double @llvm.fabs.f64(double %arg0)
Index: llvm/test/Transforms/InstCombine/fcmp.ll
===
--- llvm/test/Transforms/InstCombine/fcmp.ll
+++ llvm/test/Transforms/InstCombine/fcmp.ll
@@ -535,11 +535,11 @@
 ; Do not fold 1.0 / X > 0.0 when ninf is missing
 define i1 @test24_recipX_noninf_cmp(float %X) {
 ; CHECK-LABEL: @test24_recipX_noninf_cmp(
-; CHECK-NEXT:[[DIV:%.*]] = fdiv ninf float 2.00e+00, [[X:%.*]]
+; CHECK-NEXT:[[DIV:%.*]] = fdiv float 2.00e+00, [[X:%.*]]
 ; CHECK-NEXT:[[CMP:%.*]] = fcmp ogt float [[DIV]], 0.00e+00
 ; CHECK-NEXT:ret i1 [[CMP]]
 ;
-  %div = fdiv ninf float 2.0, %X
+  %div = fdiv float 2.0, %X
   %cmp = fcmp ogt float %div, 0.0
   ret i1 %cmp
 }
Index: llvm/test/Transforms/InstCombine/fast-math.ll
===
--- llvm/test/Transforms/InstCombine/fast-math.ll
+++ llvm/test/Transforms/InstCombine/fast-math.ll
@@ -18,7 +18,7 @@
 define float @notfold(float %a) {
 ; CHECK-LABEL: @notfold(
 ; CHECK-NEXT:[[MUL:%.*]] = fmul fast float [[A:%.*]], 0x3FF34000
-; CHECK-NEXT:[[MUL1:%.*]] = fmul float [[MUL]], 0x40026000
+; CHECK-NEXT:[[MUL1:%.*]] = fmul nnan float [[MUL]], 0x40026000
 ; CHECK-NEXT:ret float [[MUL1]]
 ;
   %mul = fmul fast float %a, 0x3FF34000
Index: 

[PATCH] D70488: [InstCombine] Infer fast math flags on fadd/fsub/fmul/fcmp

2019-11-20 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer created this revision.
bkramer added a reviewer: spatel.
Herald added subscribers: cfe-commits, hiraditya.
Herald added projects: clang, LLVM.

Applies nnan, ninf and nsz. This allows more instructions to be folded
away even with no fast math flags, e.g. (int)x * (b ? 1.0 : 0.0) -> b ? x : 0.0

As a side effect this will propagate fast math flags out of inlined fast
math code into surrounding functions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70488

Files:
  clang/test/CodeGen/builtins-systemz-zvector.c
  llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
  llvm/lib/Transforms/InstCombine/InstCombineInternal.h
  llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/add-sitofp.ll
  llvm/test/Transforms/InstCombine/cast-int-fcmp-eq-0.ll
  llvm/test/Transforms/InstCombine/fadd-fsub-factor.ll
  llvm/test/Transforms/InstCombine/fast-math.ll
  llvm/test/Transforms/InstCombine/fcmp.ll
  llvm/test/Transforms/InstCombine/known-never-nan.ll
  llvm/test/Transforms/InstCombine/minmax-fp.ll
  llvm/test/Transforms/InstCombine/pow_fp_int.ll

Index: llvm/test/Transforms/InstCombine/pow_fp_int.ll
===
--- llvm/test/Transforms/InstCombine/pow_fp_int.ll
+++ llvm/test/Transforms/InstCombine/pow_fp_int.ll
@@ -91,7 +91,7 @@
 define double @pow_uitofp_const_base_power_of_2_fast(i31 %x) {
 ; CHECK-LABEL: @pow_uitofp_const_base_power_of_2_fast(
 ; CHECK-NEXT:[[SUBFP:%.*]] = uitofp i31 [[X:%.*]] to float
-; CHECK-NEXT:[[MUL:%.*]] = fmul afn float [[SUBFP]], 4.00e+00
+; CHECK-NEXT:[[MUL:%.*]] = fmul nnan afn float [[SUBFP]], 4.00e+00
 ; CHECK-NEXT:[[EXP2:%.*]] = call afn float @llvm.exp2.f32(float [[MUL]])
 ; CHECK-NEXT:[[RES:%.*]] = fpext float [[EXP2]] to double
 ; CHECK-NEXT:ret double [[RES]]
@@ -383,7 +383,7 @@
 define double @pow_uitofp_const_base_power_of_2_no_fast(i32 %x) {
 ; CHECK-LABEL: @pow_uitofp_const_base_power_of_2_no_fast(
 ; CHECK-NEXT:[[SUBFP:%.*]] = uitofp i32 [[X:%.*]] to float
-; CHECK-NEXT:[[MUL:%.*]] = fmul float [[SUBFP]], 4.00e+00
+; CHECK-NEXT:[[MUL:%.*]] = fmul nnan float [[SUBFP]], 4.00e+00
 ; CHECK-NEXT:[[EXP2:%.*]] = call float @llvm.exp2.f32(float [[MUL]])
 ; CHECK-NEXT:[[RES:%.*]] = fpext float [[EXP2]] to double
 ; CHECK-NEXT:ret double [[RES]]
Index: llvm/test/Transforms/InstCombine/minmax-fp.ll
===
--- llvm/test/Transforms/InstCombine/minmax-fp.ll
+++ llvm/test/Transforms/InstCombine/minmax-fp.ll
@@ -273,7 +273,7 @@
 ; CHECK-LABEL: define {{[^@]+}}@fsub_fmax(
 ; CHECK-NEXT:[[COND_INV:%.*]] = fcmp nnan nsz ogt <2 x float> [[X:%.*]], [[Y:%.*]]
 ; CHECK-NEXT:[[TMP1:%.*]] = select nnan nsz <2 x i1> [[COND_INV]], <2 x float> [[Y]], <2 x float> [[X]]
-; CHECK-NEXT:[[MAX:%.*]] = fsub <2 x float> , [[TMP1]]
+; CHECK-NEXT:[[MAX:%.*]] = fsub nnan <2 x float> , [[TMP1]]
 ; CHECK-NEXT:ret <2 x float> [[MAX]]
 ;
   %n1 = fsub <2 x float> , %x
Index: llvm/test/Transforms/InstCombine/known-never-nan.ll
===
--- llvm/test/Transforms/InstCombine/known-never-nan.ll
+++ llvm/test/Transforms/InstCombine/known-never-nan.ll
@@ -11,7 +11,7 @@
 ; CHECK-LABEL: @fabs_sqrt_src_maybe_nan(
 ; CHECK-NEXT:[[FABS:%.*]] = call double @llvm.fabs.f64(double [[ARG0:%.*]])
 ; CHECK-NEXT:[[OP:%.*]] = call double @llvm.sqrt.f64(double [[FABS]])
-; CHECK-NEXT:[[TMP:%.*]] = fcmp ord double [[OP]], 0.00e+00
+; CHECK-NEXT:[[TMP:%.*]] = fcmp nsz ord double [[OP]], 0.00e+00
 ; CHECK-NEXT:ret i1 [[TMP]]
 ;
   %fabs = call double @llvm.fabs.f64(double %arg0)
Index: llvm/test/Transforms/InstCombine/fcmp.ll
===
--- llvm/test/Transforms/InstCombine/fcmp.ll
+++ llvm/test/Transforms/InstCombine/fcmp.ll
@@ -535,11 +535,11 @@
 ; Do not fold 1.0 / X > 0.0 when ninf is missing
 define i1 @test24_recipX_noninf_cmp(float %X) {
 ; CHECK-LABEL: @test24_recipX_noninf_cmp(
-; CHECK-NEXT:[[DIV:%.*]] = fdiv ninf float 2.00e+00, [[X:%.*]]
+; CHECK-NEXT:[[DIV:%.*]] = fdiv float 2.00e+00, [[X:%.*]]
 ; CHECK-NEXT:[[CMP:%.*]] = fcmp ogt float [[DIV]], 0.00e+00
 ; CHECK-NEXT:ret i1 [[CMP]]
 ;
-  %div = fdiv ninf float 2.0, %X
+  %div = fdiv float 2.0, %X
   %cmp = fcmp ogt float %div, 0.0
   ret i1 %cmp
 }
Index: llvm/test/Transforms/InstCombine/fast-math.ll
===
--- llvm/test/Transforms/InstCombine/fast-math.ll
+++ llvm/test/Transforms/InstCombine/fast-math.ll
@@ -18,7 +18,7 @@
 define float @notfold(float %a) {
 ; CHECK-LABEL: @notfold(
 ; CHECK-NEXT:[[MUL:%.*]] = fmul fast float [[A:%.*]], 0x3FF34000
-;