Skip to content

Commit

Permalink
do not lower mad to fma when using only native fma (#1441)
Browse files Browse the repository at this point in the history
make -cl-mad-enable or -cl-unsafe-math-optimisation required to lower
mad to fma.

This avoid CTS failure on erf for Nvidia devices
  • Loading branch information
rjodinchr authored Jan 17, 2025
1 parent c4f91b9 commit 9737855
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 1 addition & 3 deletions lib/ReplaceOpenCLBuiltinPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2118,9 +2118,7 @@ bool ReplaceOpenCLBuiltinPass::replaceMul(Function &F, bool is_float,
bool is_mad) {
// floating-point fma can be handle later in the flow if they are allowed
if (is_float && is_mad &&
(clspv::Option::UseNativeBuiltins().count(
clspv::Builtins::BuiltinType::kFma) > 0 ||
clspv::Option::ClMadEnable() || clspv::Option::UnsafeMath())) {
(clspv::Option::ClMadEnable() || clspv::Option::UnsafeMath())) {
return false;
}
return replaceCallsWithValue(F, [&](CallInst *CI) -> llvm::Value * {
Expand Down
6 changes: 3 additions & 3 deletions test/mad-float-optimization.cl
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
// RUN: FileCheck %s < %t.mad.spvasm
// RUN: spirv-val --target-env spv1.0 %t.mad.spv

// CHECK: OpExtInst {{.*}} Fma

// RUN: clspv %target %s -o %t.native.spv --use-native-builtins=fma
// RUN: spirv-dis -o %t.native.spvasm %t.native.spv
// RUN: FileCheck %s < %t.native.spvasm
// RUN: FileCheck %s --check-prefix=NOOPT < %t.native.spvasm
// RUN: spirv-val --target-env spv1.0 %t.native.spv

// CHECK: OpExtInst {{.*}} Fma

// RUN: clspv %target %s -o %t.spv
// RUN: spirv-dis -o %t.spvasm %t.spv
// RUN: FileCheck %s --check-prefix=NOOPT < %t.spvasm
Expand Down

0 comments on commit 9737855

Please sign in to comment.