-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang] Allow ConditionalOperator
fast-math flags to be overridden by pragma float_control
#105912
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
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,21 @@ | ||
// RUN: %clang_cc1 -ast-dump %s | FileCheck %s | ||
// RUN: %clang_cc1 -ast-dump -menable-no-infs -fapprox-func -funsafe-math-optimizations \ | ||
// RUN: -fno-signed-zeros -mreassociate -freciprocal-math -ffp-contract=fast -ffast-math %s | FileCheck %s | ||
// RUN: %clang_cc1 -emit-pch -o %t %s | ||
// RUN: %clang_cc1 -x c -include-pch %t -ast-dump-all /dev/null | FileCheck %s | ||
|
||
float test_precise_off(int c, float t, float f) { | ||
#pragma float_control(precise, off) | ||
return c ? t : f; | ||
} | ||
|
||
// CHECK-LABEL: FunctionDecl {{.*}} test_precise_off | ||
// CHECK: ConditionalOperator {{.*}} FPContractMode=2 AllowFPReassociate=1 NoHonorNaNs=1 NoHonorInfs=1 NoSignedZero=1 AllowReciprocal=1 AllowApproxFunc=1 MathErrno=0 | ||
|
||
float test_precise_on(int c, float t, float f) { | ||
#pragma float_control(precise, on) | ||
return c ? t : f; | ||
} | ||
|
||
// CHECK-LABEL: FunctionDecl {{.*}} test_precise_on | ||
// CHECK: ConditionalOperator {{.*}} FPContractMode=1 AllowFPReassociate=0 NoHonorNaNs=0 NoHonorInfs=0 NoSignedZero=0 AllowReciprocal=0 AllowApproxFunc=0 MathErrno=1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// RUN: %clang_cc1 -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s | ||
// RUN: %clang_cc1 -disable-llvm-passes -emit-llvm -menable-no-infs -fapprox-func\ | ||
// RUN: -funsafe-math-optimizations -fno-signed-zeros -mreassociate -freciprocal-math\ | ||
// RUN: -ffp-contract=fast -ffast-math %s -o - | FileCheck %s | ||
|
||
float test_precise_off_select(int c) { | ||
#pragma float_control(precise, off) | ||
return c ? 0.0f : 1.0f; | ||
} | ||
|
||
// CHECK-LABEL: test_precise_off_select | ||
// CHECK: select fast i1 {{%.+}}, float 0.000000e+00, float 1.000000e+00 | ||
|
||
float test_precise_off_phi(int c, float t, float f) { | ||
#pragma float_control(precise, off) | ||
return c ? t : f; | ||
} | ||
|
||
// CHECK-LABEL: test_precise_off_phi | ||
// CHECK: phi fast float [ {{%.+}}, {{%.+}} ], [ {{%.+}}, {{%.+}} ] | ||
|
||
float test_precise_on_select(int c) { | ||
#pragma float_control(precise, on) | ||
return c ? 0.0f : 1.0f; | ||
} | ||
|
||
// CHECK-LABEL: test_precise_on_select | ||
// CHECK: select i1 {{%.+}}, float 0.000000e+00, float 1.000000e+00 | ||
|
||
float test_precise_on_phi(int c, float t, float f) { | ||
#pragma float_control(precise, on) | ||
return c ? t : f; | ||
} | ||
|
||
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. Test some vector and complex cases 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. For "vector case" do you mean something along the lines of typedef float float2 __attribute__((ext_vector_type(2)));
typedef int int2 __attribute__((ext_vector_type(2)));
float2 foo(int2 c, float2 t, float2 f) {
#pragma float_control(precise, off)
return c ? t : f;
} In this case, the expression would be codegen-d to a sequence of bitwise operations and these are not affected by fast-math flags ; Function Attrs: noinline nounwind optnone
define <2 x float> @foo(<2 x i32> noundef %c, <2 x float> noundef %t, <2 x float> noundef %f) #0 {
entry:
%c.addr = alloca <2 x i32>, align 8
%t.addr = alloca <2 x float>, align 8
%f.addr = alloca <2 x float>, align 8
store <2 x i32> %c, ptr %c.addr, align 8
store <2 x float> %t, ptr %t.addr, align 8
store <2 x float> %f, ptr %f.addr, align 8
%0 = load <2 x i32>, ptr %c.addr, align 8
%1 = load <2 x float>, ptr %t.addr, align 8
%2 = load <2 x float>, ptr %f.addr, align 8
%3 = icmp slt <2 x i32> %0, zeroinitializer
%sext = sext <2 x i1> %3 to <2 x i32>
%4 = xor <2 x i32> %sext, <i32 -1, i32 -1>
%5 = bitcast <2 x float> %2 to <2 x i32>
%6 = bitcast <2 x float> %1 to <2 x i32>
%7 = and <2 x i32> %5, %4
%8 = and <2 x i32> %6, %sext
%cond = or <2 x i32> %7, %8
%9 = bitcast <2 x i32> %cond to <2 x float>
ret <2 x float> %9
} Not really sure what I will be testing here? |
||
// CHECK-LABEL: test_precise_on_phi | ||
// CHECK: phi float [ {{%.+}}, {{%.+}} ], [ {{%.+}}, {{%.+}} ] |
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.
Redundantly using -ffast-math and all the individual flags?
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.
These flags correspond to how the clang driver
-ffast-math
are expanded to the individual flags passed to-cc1
.Several tests (e.g.
clang/test/Parser/fp-floatcontrol-syntax.cpp
andclang/test/CodeGen/math-errno.c
) use similar command lines for testing fast-path behavior and I was trying to be consistent with them.