-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][CodeGen] Propagate pragma set fast-math flags to floating point builtins #90377
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
Changes from all commits
80836f5
4af840d
e1b01ae
251009f
dc28827
af625c7
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s | ||
|
||
// precise mode | ||
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fmath-errno -ffp-contract=on \ | ||
// RUN: -fno-rounding-math -emit-llvm -o - %s | FileCheck \ | ||
// RUN: --check-prefix=CHECK-PRECISE %s | ||
|
||
// fast mode | ||
// RUN: %clang_cc1 -triple x86_64-linux-gnu -ffast-math -ffp-contract=fast \ | ||
// RUN: -emit-llvm -o - %s | FileCheck --check-prefix=CHECK-FAST %s | ||
|
||
// Reproducer for issue #87758 | ||
// The testcase below verifies that the "fast" flag are set on the calls. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about using these run lines?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I update the testcase with only those run lines. |
||
float sqrtf(float x); // unary fp builtin | ||
float powf(float x, float y); // binary fp builtin | ||
float fmaf(float x, float y, float z); // ternary fp builtin | ||
char *rindex(const char *s, int c); // not a fp builtin | ||
|
||
#pragma float_control(push) | ||
#pragma float_control(precise, off) | ||
// CHECK: define dso_local float @fp_precise_off_libm_calls( | ||
// CHECK: call fast float @llvm.sqrt.f32( | ||
// CHECK: call fast float @llvm.pow.f32( | ||
// CHECK: call fast float @llvm.fma.f32( | ||
// CHECK: call ptr @rindex( | ||
|
||
// CHECK-PRECISE: define dso_local float @fp_precise_off_libm_calls( | ||
// CHECK-PRECISE: call fast float @sqrtf( | ||
// CHECK-PRECISE: call fast float @powf( | ||
// CHECK-PRECISE: call fast float @llvm.fma.f32( | ||
// CHECK-PRECISE: call ptr @rindex( | ||
|
||
// CHECK-FAST: define dso_local nofpclass(nan inf) float @fp_precise_off_libm_calls( | ||
// CHECK-FAST: call fast float @llvm.sqrt.f32( | ||
// CHECK-FAST: call fast float @llvm.pow.f32( | ||
// CHECK-FAST: call fast float @llvm.fma.f32( | ||
// CHECK-FAST: call ptr @rindex( | ||
|
||
float fp_precise_off_libm_calls(float a, float b, float c, const char *d, char *e, unsigned char f) { | ||
a = sqrtf(a); | ||
a = powf(a,b); | ||
a = fmaf(a,b,c); | ||
e = rindex(d, 75); | ||
return a; | ||
} | ||
#pragma float_control(pop) | ||
|
||
#pragma float_control(push) | ||
#pragma float_control(precise, on) | ||
// CHECK: define dso_local float @fp_precise_on_libm_calls( | ||
// CHECK: call float @sqrtf( | ||
// CHECK: call float @powf( | ||
// CHECK: call float @llvm.fma.f32( | ||
// CHECK: call ptr @rindex( | ||
|
||
// CHECK-PRECISE: define dso_local float @fp_precise_on_libm_calls( | ||
// CHECK-PRECISE: call float @sqrtf( | ||
// CHECK-PRECISE: call float @powf( | ||
// CHECK-PRECISE: call float @llvm.fma.f32( | ||
// CHECK-PRECISE: call ptr @rindex( | ||
|
||
// CHECK-FAST: define dso_local nofpclass(nan inf) float @fp_precise_on_libm_calls( | ||
// CHECK-FAST: call nofpclass(nan inf) float @sqrtf( | ||
// CHECK-FAST: call nofpclass(nan inf) float @powf( | ||
// CHECK-FAST: call float @llvm.fma.f32( | ||
// CHECK-FAST: call ptr @rindex( | ||
|
||
float fp_precise_on_libm_calls(float a, float b, float c, const char *d, char *e, unsigned char f) { | ||
a = sqrtf(a); | ||
a = powf(a,b); | ||
a = fmaf(a,b,c); | ||
e = rindex(d, 75); | ||
return a; | ||
} | ||
#pragma float_control(pop) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could also use the same test with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By combining There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried the patch with your change in We can see that with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the testcase with more RUN: lines and also added a libc call to rindex that have nothing to do with floats to verify that it never get the "fast" flag. |
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.
How about adding a run line with
ffast-math
option?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.
Sure, I will add that.