Lang Hames | be9af12 | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -O3 -emit-llvm -o - %s | FileCheck %s |
| 2 | |
| 3 | // Is FP_CONTRACT is honored in a simple case? |
| 4 | float fp_contract_1(float a, float b, float c) { |
| 5 | // CHECK: _Z13fp_contract_1fff |
NAKAMURA Takumi | 438daee | 2012-10-02 16:36:54 +0000 | [diff] [blame] | 6 | // CHECK: tail call float @llvm.fmuladd |
Lang Hames | be9af12 | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 7 | #pragma STDC FP_CONTRACT ON |
| 8 | return a * b + c; |
| 9 | } |
| 10 | |
| 11 | // Is FP_CONTRACT state cleared on exiting compound statements? |
| 12 | float fp_contract_2(float a, float b, float c) { |
| 13 | // CHECK: _Z13fp_contract_2fff |
NAKAMURA Takumi | 438daee | 2012-10-02 16:36:54 +0000 | [diff] [blame] | 14 | // CHECK: %[[M:.+]] = fmul float %a, %b |
| 15 | // CHECK-NEXT: fadd float %[[M]], %c |
Lang Hames | be9af12 | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 16 | { |
| 17 | #pragma STDC FP_CONTRACT ON |
| 18 | } |
| 19 | return a * b + c; |
| 20 | } |
| 21 | |
| 22 | // Does FP_CONTRACT survive template instatiation? |
| 23 | class Foo {}; |
| 24 | Foo operator+(Foo, Foo); |
| 25 | |
| 26 | template <typename T> |
| 27 | T template_muladd(T a, T b, T c) { |
| 28 | #pragma STDC FP_CONTRACT ON |
| 29 | return a * b + c; |
| 30 | } |
| 31 | |
| 32 | float fp_contract_3(float a, float b, float c) { |
| 33 | // CHECK: _Z13fp_contract_3fff |
NAKAMURA Takumi | 438daee | 2012-10-02 16:36:54 +0000 | [diff] [blame] | 34 | // CHECK: tail call float @llvm.fmuladd |
Lang Hames | be9af12 | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 35 | return template_muladd<float>(a, b, c); |
| 36 | } |
Eli Friedman | 9595c7e | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 37 | |
| 38 | template<typename T> class fp_contract_4 { |
| 39 | float method(float a, float b, float c) { |
| 40 | #pragma STDC FP_CONTRACT ON |
| 41 | return a * b + c; |
Eli Friedman | 9595c7e | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 42 | } |
| 43 | }; |
| 44 | |
| 45 | template class fp_contract_4<int>; |
| 46 | // CHECK: _ZN13fp_contract_4IiE6methodEfff |
| 47 | // CHECK: tail call float @llvm.fmuladd |
Lang Hames | eddb00a | 2012-10-04 03:07:37 +0000 | [diff] [blame] | 48 | |
| 49 | // Check file-scoped FP_CONTRACT |
| 50 | #pragma STDC FP_CONTRACT ON |
| 51 | float fp_contract_5(float a, float b, float c) { |
| 52 | // CHECK: _Z13fp_contract_5fff |
| 53 | // CHECK: tail call float @llvm.fmuladd |
| 54 | return a * b + c; |
| 55 | } |
| 56 | |
| 57 | #pragma STDC FP_CONTRACT OFF |
| 58 | float fp_contract_6(float a, float b, float c) { |
| 59 | // CHECK: _Z13fp_contract_6fff |
| 60 | // CHECK: %[[M:.+]] = fmul float %a, %b |
| 61 | // CHECK-NEXT: fadd float %[[M]], %c |
| 62 | return a * b + c; |
| 63 | } |
| 64 | |