This repository has been archived by the owner on Apr 23, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
set the underlying value of “#pragma STDC FP_CONTRACT” on by default
Clang has the default FP contraction setting of “-ffp-contract=on”, which doesn't really mean “on” in the conventional sense of the word, but rather really means “according to the per-statement effective value of the relevant pragma”. Before this patch, Clang has that pragma defaulting to “off”. Since the “-ffp-contract=on” mode is really an AND of two booleans and the second of them defaults to “off”, the whole thing effectively defaults to “off”. This patch changes the default value of the pragma to “on”, thus making the default pair of booleans (on, on) rather than (on, off). This makes FP optimization slightly more aggressive than before when not using either “-Ofast”, “-ffast-math”, or “-ffp-contract=fast”. Even with this patch the compiler still respects “-ffp-contract=off”. As per a suggestion by Steve Canon, the added code does _not_ require “-O3” or higher. This is so as to try our best to preserve identical floating-point results for unchanged source code compiling for an unchanged target when only changing from any optimization level in the set (“-O0”, “-O1”, “-O2”, “-O3”) to any other optimization level in that set. “-Os” and “-Oz” seem to be behaving identically, i.e. should probably be considered a part of the aforementioned set, but I have not reviewed this rigorously. “-Ofast” is explicitly _not_ a member of that set. Patch authored by Abe Skolnik [a.skolnik@samsung.com] and Stephen Canon [scanon@apple.com]. Differential Revision: https://reviews.llvm.org/D24481 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@282259 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
Showing
6 changed files
with
226 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
// RUN: %clang_cc1 -triple=aarch64-unknown -Os -ffp-contract=fast -S -o - %s | FileCheck -check-prefix=CHECK-FAST -check-prefix=CHECK-ALL %s | ||
// RUN: %clang_cc1 -triple=aarch64-unknown -Os -ffp-contract=on -S -o - %s | FileCheck -check-prefix=CHECK-ON -check-prefix=CHECK-ALL %s | ||
// RUN: %clang_cc1 -triple=aarch64-unknown -Os -ffp-contract=off -S -o - %s | FileCheck -check-prefix=CHECK-OFF -check-prefix=CHECK-ALL %s | ||
// RUN: %clang_cc1 -triple=aarch64-unknown -Os -S -o - %s | FileCheck -check-prefix=CHECK-ON -check-prefix=CHECK-ALL %s | ||
// REQUIRES: aarch64-registered-target | ||
|
||
float test1(float x, float y, float z) { | ||
return x*y + z; | ||
// CHECK-ALL-LABEL: test1: | ||
// CHECK-FAST: fmadd | ||
// CHECK-ON: fmadd | ||
// CHECK-OFF: fmul | ||
// CHECK-OFF-NEXT: fadd | ||
} | ||
|
||
double test2(double x, double y, double z) { | ||
z -= x*y; | ||
return z; | ||
// CHECK-ALL-LABEL: test2: | ||
// CHECK-FAST: fmsub | ||
// CHECK-ON: fmsub | ||
// CHECK-OFF: fmul | ||
// CHECK-OFF-NEXT: fsub | ||
} | ||
|
||
float test3(float x, float y, float z) { | ||
float tmp = x*y; | ||
return tmp + z; | ||
// CHECK-ALL-LABEL: test3: | ||
// CHECK-FAST: fmadd | ||
// CHECK-ON: fmul | ||
// CHECK-ON-NEXT: fadd | ||
// CHECK-OFF: fmul | ||
// CHECK-OFF-NEXT: fadd | ||
} | ||
|
||
double test4(double x, double y, double z) { | ||
double tmp = x*y; | ||
return tmp - z; | ||
// CHECK-ALL-LABEL: test4: | ||
// CHECK-FAST: fnmsub | ||
// CHECK-ON: fmul | ||
// CHECK-ON-NEXT: fsub | ||
// CHECK-OFF: fmul | ||
// CHECK-OFF-NEXT: fsub | ||
} | ||
|
||
#pragma STDC FP_CONTRACT ON | ||
|
||
float test5(float x, float y, float z) { | ||
return x*y + z; | ||
// CHECK-ALL-LABEL: test5: | ||
// CHECK-FAST: fmadd | ||
// CHECK-ON: fmadd | ||
// CHECK-OFF: fmul | ||
// CHECK-OFF-NEXT: fadd | ||
} | ||
|
||
double test6(double x, double y, double z) { | ||
z -= x*y; | ||
return z; | ||
// CHECK-ALL-LABEL: test6: | ||
// CHECK-FAST: fmsub | ||
// CHECK-ON: fmsub | ||
// CHECK-OFF: fmul | ||
// CHECK-OFF-NEXT: fsub | ||
} | ||
|
||
float test7(float x, float y, float z) { | ||
float tmp = x*y; | ||
return tmp + z; | ||
// CHECK-ALL-LABEL: test7: | ||
// CHECK-FAST: fmadd | ||
// CHECK-ON: fmul | ||
// CHECK-ON-NEXT: fadd | ||
// CHECK-OFF: fmul | ||
// CHECK-OFF-NEXT: fadd | ||
} | ||
|
||
double test8(double x, double y, double z) { | ||
double tmp = x*y; | ||
return tmp - z; | ||
// CHECK-ALL-LABEL: test8: | ||
// CHECK-FAST: fnmsub | ||
// CHECK-ON: fmul | ||
// CHECK-ON-NEXT: fsub | ||
// CHECK-OFF: fmul | ||
// CHECK-OFF-NEXT: fsub | ||
} | ||
|
||
#pragma STDC FP_CONTRACT OFF | ||
|
||
float test9(float x, float y, float z) { | ||
return x*y + z; | ||
// CHECK-ALL-LABEL: test9: | ||
// CHECK-FAST: fmadd | ||
// CHECK-ON: fmul | ||
// CHECK-ON-NEXT: fadd | ||
// CHECK-OFF: fmul | ||
// CHECK-OFF-NEXT: fadd | ||
} | ||
|
||
double test10(double x, double y, double z) { | ||
z -= x*y; | ||
return z; | ||
// CHECK-ALL-LABEL: test10: | ||
// CHECK-FAST: fmsub | ||
// CHECK-ON: fmul | ||
// CHECK-ON-NEXT: fsub | ||
// CHECK-OFF: fmul | ||
// CHECK-OFF-NEXT: fsub | ||
} | ||
|
||
float test11(float x, float y, float z) { | ||
float tmp = x*y; | ||
return tmp + z; | ||
// CHECK-ALL-LABEL: test11: | ||
// CHECK-FAST: fmadd | ||
// CHECK-ON: fmul | ||
// CHECK-ON-NEXT: fadd | ||
// CHECK-OFF: fmul | ||
// CHECK-OFF-NEXT: fadd | ||
} | ||
|
||
double test12(double x, double y, double z) { | ||
double tmp = x*y; | ||
return tmp - z; | ||
// CHECK-ALL-LABEL: test12: | ||
// CHECK-FAST: fnmsub | ||
// CHECK-ON: fmul | ||
// CHECK-ON-NEXT: fsub | ||
// CHECK-OFF: fmul | ||
// CHECK-OFF-NEXT: fsub | ||
} | ||
|
||
#pragma STDC FP_CONTRACT DEFAULT | ||
|
||
float test17(float x, float y, float z) { | ||
return x*y + z; | ||
// CHECK-ALL-LABEL: test17: | ||
// CHECK-FAST: fmadd | ||
// CHECK-ON: fmadd | ||
// CHECK-OFF: fmul | ||
// CHECK-OFF-NEXT: fadd | ||
} | ||
|
||
double test18(double x, double y, double z) { | ||
z -= x*y; | ||
return z; | ||
// CHECK-ALL-LABEL: test18: | ||
// CHECK-FAST: fmsub | ||
// CHECK-ON: fmsub | ||
// CHECK-OFF: fmul | ||
// CHECK-OFF-NEXT: fsub | ||
} | ||
|
||
float test19(float x, float y, float z) { | ||
float tmp = x*y; | ||
return tmp + z; | ||
// CHECK-ALL-LABEL: test19: | ||
// CHECK-FAST: fmadd | ||
// CHECK-ON: fmul | ||
// CHECK-ON-NEXT: fadd | ||
// CHECK-OFF: fmul | ||
// CHECK-OFF-NEXT: fadd | ||
} | ||
|
||
double test20(double x, double y, double z) { | ||
double tmp = x*y; | ||
return tmp - z; | ||
// CHECK-ALL-LABEL: test20: | ||
// CHECK-FAST: fnmsub | ||
// CHECK-ON: fmul | ||
// CHECK-ON-NEXT: fsub | ||
// CHECK-OFF: fmul | ||
// CHECK-OFF-NEXT: fsub | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// RUN: %clang_cc1 -triple aarch64 -O0 -S -o - %s | FileCheck %s --check-prefix ALL_BUILDS | ||
// RUN: %clang_cc1 -triple aarch64 -O1 -S -o - %s | FileCheck %s --check-prefixes ALL_BUILDS,NON_O0 | ||
// RUN: %clang_cc1 -triple aarch64 -O2 -S -o - %s | FileCheck %s --check-prefixes ALL_BUILDS,NON_O0 | ||
// RUN: %clang_cc1 -triple aarch64 -O3 -S -o - %s | FileCheck %s --check-prefixes ALL_BUILDS,NON_O0 | ||
|
||
// REQUIRES: aarch64-registered-target | ||
|
||
// ALL_BUILDS-LABEL: fmadd_double: | ||
// ALL_BUILDS: fmadd d0, d{{[0-7]}}, d{{[0-7]}}, d{{[0-7]}} | ||
// NON_O0-NEXT: ret | ||
double fmadd_double(double a, double b, double c) { | ||
return a*b+c; | ||
} | ||
|
||
// ALL_BUILDS: fmadd_single: | ||
// ALL_BUILDS: fmadd s0, s{{[0-7]}}, s{{[0-7]}}, s{{[0-7]}} | ||
// NON_O0-NEXT: ret | ||
float fmadd_single(float a, float b, float c) { | ||
return a*b+c; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters