-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[Flang] Add -ffast-real-mod back for further control of MOD optimizations #167118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,24 @@ | ||
| ! RUN: %flang_fc1 -ffast-math -emit-mlir -o - %s | FileCheck %s --check-prefixes=CHECK%if target=x86_64{{.*}} %{,CHECK-KIND10%}%if flang-supports-f128-math %{,CHECK-KIND16%} | ||
| ! RUN: %flang_fc1 -ffast-real-mod -emit-mlir -o - %s | FileCheck %s --check-prefixes=CHECK-FRM%if target=x86_64{{.*}} %{,CHECK-FRM-KIND10%}%if flang-supports-f128-math %{,CHECK-FRM-KIND16%} | ||
| ! RUN: %flang_fc1 -ffast-math -emit-mlir -o - %s | FileCheck %s --check-prefixes=CHECK-FRM%if target=x86_64{{.*}} %{,CHECK-FRM-KIND10%}%if flang-supports-f128-math %{,CHECK-FRM-KIND16%} | ||
| ! RUN: %flang_fc1 -ffast-math -fno-fast-real-mod -emit-mlir -o - %s | FileCheck %s --check-prefixes=CHECK-NFRM%if target=x86_64{{.*}} %{,CHECK-NFRM-KIND10%}%if flang-supports-f128-math %{,CHECK-NFRM-KIND16%} | ||
tarunprabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ! TODO: check line that fir.fast_real_mod is not there | ||
| ! CHECK-NFRM: module attributes {{{.*}}fir.no_fast_real_mod = true{{.*}}} | ||
| ! CHECK,CHECK-FRM: module attributes {{{.*}}fir.fast_real_mod = true{{.*}}} | ||
|
|
||
| ! CHECK-LABEL: @_QPmod_real4 | ||
| subroutine mod_real4(r, a, p) | ||
| implicit none | ||
| real(kind=4) :: r, a, p | ||
| ! CHECK: %[[A:.*]] = fir.declare{{.*}}a" | ||
| ! CHECK: %[[P:.*]] = fir.declare{{.*}}p" | ||
| ! CHECK: %[[R:.*]] = fir.declare{{.*}}r" | ||
| ! CHECK: %[[A_LOAD:.*]] = fir.load %[[A]] | ||
| ! CHECK: %[[P_LOAD:.*]] = fir.load %[[P]] | ||
| ! CHECK: %[[DIV:.*]] = arith.divf %[[A_LOAD]], %[[P_LOAD]] fastmath<fast> : f32 | ||
| ! CHECK: %[[CV1:.*]] = fir.convert %[[DIV]] : (f32) -> si32 | ||
| ! CHECK: %[[CV2:.*]] = fir.convert %[[CV1]] : (si32) -> f32 | ||
| ! CHECK: %[[MUL:.*]] = arith.mulf %[[CV2]], %[[P_LOAD]] fastmath<fast> : f32 | ||
| ! CHECK: %[[SUB:.*]] = arith.subf %[[A_LOAD]], %[[MUL]] fastmath<fast> : f32 | ||
| ! CHECK: fir.store %[[SUB]] to %[[R]] : !fir.ref<f32> | ||
| ! CHECK-FRM: %[[A:.*]] = fir.declare{{.*}}a" | ||
| ! CHECK-FRM: %[[P:.*]] = fir.declare{{.*}}p" | ||
| ! CHECK-FRM: %[[R:.*]] = fir.declare{{.*}}r" | ||
| ! CHECK-FRM: %[[A_LOAD:.*]] = fir.load %[[A]] | ||
| ! CHECK-FRM: %[[P_LOAD:.*]] = fir.load %[[P]] | ||
| ! CHECK-FRM: %[[DIV:.*]] = arith.divf %[[A_LOAD]], %[[P_LOAD]] fastmath<{{.*}}> : f32 | ||
|
||
| ! CHECK-FRM: %[[CV1:.*]] = fir.convert %[[DIV]] : (f32) -> si32 | ||
| ! CHECK-FRM: %[[CV2:.*]] = fir.convert %[[CV1]] : (si32) -> f32 | ||
| ! CHECK-FRM: %[[MUL:.*]] = arith.mulf %[[CV2]], %[[P_LOAD]] fastmath<{{.*}}> : f32 | ||
| ! CHECK-FRM: %[[SUB:.*]] = arith.subf %[[A_LOAD]], %[[MUL]] fastmath<{{.*}}> : f32 | ||
| ! CHECK-FRM: fir.store %[[SUB]] to %[[R]] : !fir.ref<f32> | ||
| ! CHECK-NFRM: fir.call @_FortranAModReal4(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}}: (f32, f32, !fir.ref<i8>, i32) -> f32 | ||
| r = mod(a, p) | ||
| end subroutine mod_real4 | ||
|
|
@@ -27,17 +27,17 @@ end subroutine mod_real4 | |
| subroutine mod_real8(r, a, p) | ||
| implicit none | ||
| real(kind=8) :: r, a, p | ||
| ! CHECK: %[[A:.*]] = fir.declare{{.*}}a" | ||
| ! CHECK: %[[P:.*]] = fir.declare{{.*}}p" | ||
| ! CHECK: %[[R:.*]] = fir.declare{{.*}}r" | ||
| ! CHECK: %[[A_LOAD:.*]] = fir.load %[[A]] | ||
| ! CHECK: %[[P_LOAD:.*]] = fir.load %[[P]] | ||
| ! CHECK: %[[DIV:.*]] = arith.divf %[[A_LOAD]], %[[P_LOAD]] fastmath<fast> : f64 | ||
| ! CHECK: %[[CV1:.*]] = fir.convert %[[DIV]] : (f64) -> si64 | ||
| ! CHECK: %[[CV2:.*]] = fir.convert %[[CV1]] : (si64) -> f64 | ||
| ! CHECK: %[[MUL:.*]] = arith.mulf %[[CV2]], %[[P_LOAD]] fastmath<fast> : f64 | ||
| ! CHECK: %[[SUB:.*]] = arith.subf %[[A_LOAD]], %[[MUL]] fastmath<fast> : f64 | ||
| ! CHECK: fir.store %[[SUB]] to %[[R]] : !fir.ref<f64> | ||
| ! CHECK-FRM: %[[A:.*]] = fir.declare{{.*}}a" | ||
| ! CHECK-FRM: %[[P:.*]] = fir.declare{{.*}}p" | ||
| ! CHECK-FRM: %[[R:.*]] = fir.declare{{.*}}r" | ||
| ! CHECK-FRM: %[[A_LOAD:.*]] = fir.load %[[A]] | ||
| ! CHECK-FRM: %[[P_LOAD:.*]] = fir.load %[[P]] | ||
| ! CHECK-FRM: %[[DIV:.*]] = arith.divf %[[A_LOAD]], %[[P_LOAD]] fastmath<{{.*}}> : f64 | ||
| ! CHECK-FRM: %[[CV1:.*]] = fir.convert %[[DIV]] : (f64) -> si64 | ||
| ! CHECK-FRM: %[[CV2:.*]] = fir.convert %[[CV1]] : (si64) -> f64 | ||
| ! CHECK-FRM: %[[MUL:.*]] = arith.mulf %[[CV2]], %[[P_LOAD]] fastmath<{{.*}}> : f64 | ||
| ! CHECK-FRM: %[[SUB:.*]] = arith.subf %[[A_LOAD]], %[[MUL]] fastmath<{{.*}}> : f64 | ||
| ! CHECK-FRM: fir.store %[[SUB]] to %[[R]] : !fir.ref<f64> | ||
| ! CHECK-NFRM: fir.call @_FortranAModReal8(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}}: (f64, f64, !fir.ref<i8>, i32) -> f64 | ||
| r = mod(a, p) | ||
| end subroutine mod_real8 | ||
|
|
@@ -47,17 +47,17 @@ subroutine mod_real10(r, a, p) | |
| implicit none | ||
| integer, parameter :: kind10 = merge(10, 4, selected_real_kind(p=18).eq.10) | ||
| real(kind=kind10) :: r, a, p | ||
| ! CHECK-KIND10: %[[A:.*]] = fir.declare{{.*}}a" | ||
| ! CHECK-KIND10: %[[P:.*]] = fir.declare{{.*}}p" | ||
| ! CHECK-KIND10: %[[R:.*]] = fir.declare{{.*}}r" | ||
| ! CHECK-KIND10: %[[A_LOAD:.*]] = fir.load %[[A]] | ||
| ! CHECK-KIND10: %[[P_LOAD:.*]] = fir.load %[[P]] | ||
| ! CHECK-KIND10: %[[DIV:.*]] = arith.divf %[[A_LOAD]], %[[P_LOAD]] fastmath<fast> : f80 | ||
| ! CHECK-KIND10: %[[CV1:.*]] = fir.convert %[[DIV]] : (f80) -> si80 | ||
| ! CHECK-KIND10: %[[CV2:.*]] = fir.convert %[[CV1]] : (si80) -> f80 | ||
| ! CHECK-KIND10: %[[MUL:.*]] = arith.mulf %[[CV2]], %[[P_LOAD]] fastmath<fast> : f80 | ||
| ! CHECK-KIND10: %[[SUB:.*]] = arith.subf %[[A_LOAD]], %[[MUL]] fastmath<fast> : f80 | ||
| ! CHECK-KIND10: fir.store %[[SUB]] to %[[R]] : !fir.ref<f80> | ||
| ! CHECK-FRM-KIND10: %[[A:.*]] = fir.declare{{.*}}a" | ||
| ! CHECK-FRM-KIND10: %[[P:.*]] = fir.declare{{.*}}p" | ||
| ! CHECK-FRM-KIND10: %[[R:.*]] = fir.declare{{.*}}r" | ||
| ! CHECK-FRM-KIND10: %[[A_LOAD:.*]] = fir.load %[[A]] | ||
| ! CHECK-FRM-KIND10: %[[P_LOAD:.*]] = fir.load %[[P]] | ||
| ! CHECK-FRM-KIND10: %[[DIV:.*]] = arith.divf %[[A_LOAD]], %[[P_LOAD]] fastmath<{{.*}}> : f80 | ||
| ! CHECK-FRM-KIND10: %[[CV1:.*]] = fir.convert %[[DIV]] : (f80) -> si80 | ||
| ! CHECK-FRM-KIND10: %[[CV2:.*]] = fir.convert %[[CV1]] : (si80) -> f80 | ||
| ! CHECK-FRM-KIND10: %[[MUL:.*]] = arith.mulf %[[CV2]], %[[P_LOAD]] fastmath<{{.*}}> : f80 | ||
| ! CHECK-FRM-KIND10: %[[SUB:.*]] = arith.subf %[[A_LOAD]], %[[MUL]] fastmath<{{.*}}> : f80 | ||
| ! CHECK-FRM-KIND10: fir.store %[[SUB]] to %[[R]] : !fir.ref<f80> | ||
| ! CHECK-NFRM-KIND10: fir.call @_FortranAModReal10(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}}: (f80, f80, !fir.ref<i8>, i32) -> f80 | ||
| r = mod(a, p) | ||
| end subroutine mod_real10 | ||
|
|
@@ -67,17 +67,17 @@ subroutine mod_real16(r, a, p) | |
| implicit none | ||
| integer, parameter :: kind16 = merge(16, 4, selected_real_kind(p=33).eq.16) | ||
| real(kind=kind16) :: r, a, p | ||
| ! CHECK-KIND16: %[[A:.*]] = fir.declare{{.*}}a" | ||
| ! CHECK-KIND16: %[[P:.*]] = fir.declare{{.*}}p" | ||
| ! CHECK-KIND16: %[[R:.*]] = fir.declare{{.*}}r" | ||
| ! CHECK-KIND16: %[[A_LOAD:.*]] = fir.load %[[A]] | ||
| ! CHECK-KIND16: %[[P_LOAD:.*]] = fir.load %[[P]] | ||
| ! CHECK-KIND16: %[[DIV:.*]] = arith.divf %[[A_LOAD]], %[[P_LOAD]] fastmath<fast> : f128 | ||
| ! CHECK-KIND16: %[[CV1:.*]] = fir.convert %[[DIV]] : (f128) -> si128 | ||
| ! CHECK-KIND16: %[[CV2:.*]] = fir.convert %[[CV1]] : (si128) -> f128 | ||
| ! CHECK-KIND16: %[[MUL:.*]] = arith.mulf %[[CV2]], %[[P_LOAD]] fastmath<fast> : f128 | ||
| ! CHECK-KIND16: %[[SUB:.*]] = arith.subf %[[A_LOAD]], %[[MUL]] fastmath<fast> : f128 | ||
| ! CHECK-KIND16: fir.store %[[SUB]] to %[[R]] : !fir.ref<f128> | ||
| ! CHECK-FRM-KIND16: %[[A:.*]] = fir.declare{{.*}}a" | ||
| ! CHECK-FRM-KIND16: %[[P:.*]] = fir.declare{{.*}}p" | ||
| ! CHECK-FRM-KIND16: %[[R:.*]] = fir.declare{{.*}}r" | ||
| ! CHECK-FRM-KIND16: %[[A_LOAD:.*]] = fir.load %[[A]] | ||
| ! CHECK-FRM-KIND16: %[[P_LOAD:.*]] = fir.load %[[P]] | ||
| ! CHECK-FRM-KIND16: %[[DIV:.*]] = arith.divf %[[A_LOAD]], %[[P_LOAD]] fastmath<{{.*}}> : f128 | ||
| ! CHECK-FRM-KIND16: %[[CV1:.*]] = fir.convert %[[DIV]] : (f128) -> si128 | ||
| ! CHECK-FRM-KIND16: %[[CV2:.*]] = fir.convert %[[CV1]] : (si128) -> f128 | ||
| ! CHECK-FRM-KIND16: %[[MUL:.*]] = arith.mulf %[[CV2]], %[[P_LOAD]] fastmath<{{.*}}> : f128 | ||
| ! CHECK-FRM-KIND16: %[[SUB:.*]] = arith.subf %[[A_LOAD]], %[[MUL]] fastmath<{{.*}}> : f128 | ||
| ! CHECK-FRM-KIND16: fir.store %[[SUB]] to %[[R]] : !fir.ref<f128> | ||
| ! CHECK-NFRM-KIND16: fir.call @_FortranAModReal16(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}}: (f128, f128, !fir.ref<i8>, i32) -> f128 | ||
| r = mod(a, p) | ||
| end subroutine mod_real16 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be a good idea to add tests that check what happens when both
-ffast-real-modand-fno-fast-real-modappear on the command line. The last to appear should "win".Since these are related to
ffast-math, it may be good to check that they work as expected in the presence of-ffast-mathThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! That's another thing that I can add to the test.