Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,11 @@ static bool initTargetOptions(const CompilerInstance &CI,
Options.AllowFPOpFusion = llvm::FPOpFusion::Standard;
break;
case LangOptions::FPM_Fast:
Options.AllowFPOpFusion = llvm::FPOpFusion::Fast;
// We always honor fp-contract pragmas for PlayStation.
if (CI.getASTContext().getTargetInfo().getTriple().isPS())
Options.AllowFPOpFusion = llvm::FPOpFusion::Standard;
else
Options.AllowFPOpFusion = llvm::FPOpFusion::Fast;
break;
}

Expand Down
53 changes: 53 additions & 0 deletions clang/test/CodeGen/X86/fma-fast-pragma.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// REQUIRES: x86-registered-target

// With the pragma in place, generic targets leave FMA enabled unless the
// switch '-ffp-contract=fast-honor-pragmas' is used to disable it; whereas
// for PlayStation, the pragma is always honored, so FMA is disabled even in
// plain 'fast' mode:
// RUN: %clang_cc1 -S -triple x86_64-unknown-unknown -target-feature +fma \
// RUN: -O2 -ffp-contract=fast -o - %s | \
// RUN: FileCheck --check-prefix=CHECK-YES-FMA %s
// RUN: %clang_cc1 -S -triple x86_64-unknown-unknown -target-feature +fma \
// RUN: -O2 -ffp-contract=fast-honor-pragmas -o - %s | \
// RUN: FileCheck --check-prefix=CHECK-NO-FMA %s
// RUN: %clang_cc1 -S -triple x86_64-unknown-unknown -target-feature +fma \
// RUN: -O2 -ffp-contract=fast -ffp-contract=fast-honor-pragmas -o - %s | \
// RUN: FileCheck --check-prefix=CHECK-NO-FMA %s
// RUN: %clang_cc1 -S -triple x86_64-sie-ps5 -target-feature +fma \
// RUN: -O2 -ffp-contract=fast -o - %s | \
// RUN: FileCheck --check-prefix=CHECK-NO-FMA %s
// RUN: %clang_cc1 -S -triple x86_64-sie-ps5 -target-feature +fma \
// RUN: -O2 -ffp-contract=fast-honor-pragmas -o - %s | \
// RUN: FileCheck --check-prefix=CHECK-NO-FMA %s
//
// With the pragma suppressed, FMA happens in 'fast' or 'fast-honor-pragmas'
// modes (for generic targets and for PlayStation):
// RUN: %clang_cc1 -S -DSUPPRESS_PRAGMA \
// RUN: -triple x86_64-unknown-unknown -target-feature +fma \
// RUN: -O2 -ffp-contract=fast -o - %s | \
// RUN: FileCheck --check-prefix=CHECK-YES-FMA %s
// RUN: %clang_cc1 -S -DSUPPRESS_PRAGMA \
// RUN: -triple x86_64-unknown-unknown -target-feature +fma \
// RUN: -O2 -ffp-contract=fast-honor-pragmas -o - %s | \
// RUN: FileCheck --check-prefix=CHECK-YES-FMA %s
// RUN: %clang_cc1 -S -DSUPPRESS_PRAGMA \
// RUN: -triple x86_64-sie-ps5 -target-feature +fma \
// RUN: -O2 -ffp-contract=fast -o - %s | \
// RUN: FileCheck --check-prefix=CHECK-YES-FMA %s
// RUN: %clang_cc1 -S -DSUPPRESS_PRAGMA \
// RUN: -triple x86_64-sie-ps5 -target-feature +fma \
// RUN: -O2 -ffp-contract=fast-honor-pragmas -o - %s | \
// RUN: FileCheck --check-prefix=CHECK-YES-FMA %s
//
float compute(float a, float b, float c) {
#if !defined(SUPPRESS_PRAGMA)
#pragma clang fp contract (off)
#endif
float product = a * b;
return product + c;
}

// CHECK-NO-FMA: vmulss
// CHECK-NO-FMA-NEXT: vaddss

// CHECK-YES-FMA: vfmadd213ss