Skip to content

Commit 8a39af8

Browse files
authored
[Backport to 14] [LLVM->SPIRV] Fix FMA name check (#3499) (#3507)
Previous check in 199d2e0 translated __spirv_ocl_fmax to FMA. (cherry picked from commit 64b7a07)
1 parent f5ee806 commit 8a39af8

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4631,7 +4631,7 @@ SPIRVValue *LLVMToSPIRVBase::transDirectCallInst(CallInst *CI,
46314631
BM->addExtension(
46324632
ExtensionID::SPV_EXT_relaxed_printf_string_address_space);
46334633
}
4634-
} else if (DemangledName.find("__spirv_ocl_fma") != StringRef::npos) {
4634+
} else if (DemangledName == "__spirv_ocl_fma") {
46354635
if (BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_fma))
46364636
return BM->addInstTemplate(OpFmaKHR,
46374637
BM->getIds(transValue(getArguments(CI), BB)),

test/transcoding/fmax.ll

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_KHR_fma -o %t.spv
3+
; RUN: spirv-val %t.spv
4+
; RUN: llvm-spirv %t.spv -to-text -o %t.spt
5+
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
6+
; RUN: llvm-spirv -r %t.spv -o - | llvm-dis -o %t.rev.ll
7+
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM
8+
9+
; Check enabling SPV_KHR_fma does not translate fmax to fma.
10+
11+
; CHECK-SPIRV: ExtInst [[#]] [[#]] [[#]] fmax [[#]] [[#]]
12+
13+
; CHECK-LLVM: %{{.*}} = call spir_func float @_Z4fmaxff(float %{{.*}}, float %{{.*}})
14+
15+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
16+
target triple = "spir64-unknown-unknown"
17+
18+
; Case to test fmax translation via OCL builtins.
19+
define spir_func float @test_fmax_ocl_scalar(float %a, float %b) {
20+
entry:
21+
%result = call spir_func float @_Z16__spirv_ocl_fmaxff(float %a, float %b)
22+
ret float %result
23+
}
24+
25+
declare spir_func float @_Z16__spirv_ocl_fmaxff(float, float)

0 commit comments

Comments
 (0)