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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we should simply do this silently (which may be surprising) or if we should at least issue a warning that we are doing this? Perhaps with a deprecation notice in the vague hope that we could turn it into an error in future?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it happens, for PlayStation, we have had a private patch in place to honor the fp-contract pragma since our llvm11-based release (this was before the concept of -ffp-contract=fast-honor-pragmas was created). So this isn't a change in behavior for PlayStation developers, and so no need for a warning, from that perspective.

That said, if #105746 is done in some form (and there is activity there now), this PR can be abandoned. And as I've said above, I'm very much in favor of that approach being taken.

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