fp-contract-on-pragma.cpp
1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// RUN: %clang_cc1 -O3 -triple %itanium_abi_triple -emit-llvm -o - %s | FileCheck %s
// Is FP_CONTRACT honored in a simple case?
float fp_contract_1(float a, float b, float c) {
// CHECK: _Z13fp_contract_1fff
// CHECK: tail call float @llvm.fmuladd
#pragma clang fp contract(on)
return a * b + c;
}
// Is FP_CONTRACT state cleared on exiting compound statements?
float fp_contract_2(float a, float b, float c) {
// CHECK: _Z13fp_contract_2fff
// CHECK: %[[M:.+]] = fmul float %a, %b
// CHECK-NEXT: fadd float %[[M]], %c
{
#pragma clang fp contract(on)
}
return a * b + c;
}
// Does FP_CONTRACT survive template instantiation?
class Foo {};
Foo operator+(Foo, Foo);
template <typename T>
T template_muladd(T a, T b, T c) {
#pragma clang fp contract(on)
return a * b + c;
}
float fp_contract_3(float a, float b, float c) {
// CHECK: _Z13fp_contract_3fff
// CHECK: tail call float @llvm.fmuladd
return template_muladd<float>(a, b, c);
}
template <typename T>
class fp_contract_4 {
float method(float a, float b, float c) {
#pragma clang fp contract(on)
return a * b + c;
}
};
template class fp_contract_4<int>;
// CHECK: _ZN13fp_contract_4IiE6methodEfff
// CHECK: tail call float @llvm.fmuladd
// Check file-scoped FP_CONTRACT
#pragma clang fp contract(on)
float fp_contract_5(float a, float b, float c) {
// CHECK: _Z13fp_contract_5fff
// CHECK: tail call float @llvm.fmuladd
return a * b + c;
}
#pragma clang fp contract(off)
float fp_contract_6(float a, float b, float c) {
// CHECK: _Z13fp_contract_6fff
// CHECK: %[[M:.+]] = fmul float %a, %b
// CHECK-NEXT: fadd float %[[M]], %c
return a * b + c;
}
// If the multiply has multiple uses, don't produce fmuladd.
// This used to assert (PR25719):
// https://llvm.org/bugs/show_bug.cgi?id=25719
float fp_contract_7(float a, float b, float c) {
// CHECK: _Z13fp_contract_7fff
// CHECK: %[[M:.+]] = fmul float %b, 2.000000e+00
// CHECK-NEXT: fsub float %[[M]], %c
#pragma clang fp contract(on)
return (a = 2 * b) - c;
}