Skip to content

Commit 739d568

Browse files
[Backport to llvm_release_220] Fix backward translation of OpFmaKHR (#3548)
Backport of PR #3529 into `llvm_release_220`. All commits applied cleanly. Co-authored-by: Viktoria Maximova <viktoria.maksimova@intel.com>
1 parent 7a43833 commit 739d568

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

lib/SPIRV/SPIRVReader.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3016,8 +3016,13 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
30163016
BV, Builder.CreateIntrinsic(Intrinsic::arithmetic_fence, RetTy, Val));
30173017
}
30183018
case OpFmaKHR: {
3019+
IRBuilder<> Builder(BB);
30193020
auto *BC = static_cast<SPIRVFmaKHR *>(BV);
3020-
return mapValue(BV, transBuiltinFromInst("fma", BC, BB));
3021+
return mapValue(
3022+
BV, Builder.CreateIntrinsic(Intrinsic::fma, transType(BC->getType()),
3023+
{transValue(BC->getOperand(0), F, BB),
3024+
transValue(BC->getOperand(1), F, BB),
3025+
transValue(BC->getOperand(2), F, BB)}));
30213026
}
30223027
case internal::OpMaskedGatherINTEL: {
30233028
IRBuilder<> Builder(BB);

test/extensions/KHR/SPV_KHR_fma/fma.ll

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
66
; RUN: llvm-spirv -r %t.spv -o - | llvm-dis -o %t.rev.ll
77
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM
8+
; RUN: llvm-spirv -r %t.spv --spirv-target-env=SPV-IR -o - | llvm-dis -o %t.rev.ll
9+
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM
810

911
; RUN: llvm-spirv %s -spirv-text -o %t.spt
1012
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV-NO-EXT
1113
; RUN: llvm-spirv %s -o %t.spv
1214
; RUN: spirv-val %t.spv
1315
; RUN: llvm-spirv -r %t.spv -o - | llvm-dis -o %t.rev.ll
14-
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM
16+
; RUN: FileCheck < %t.rev.ll %s --check-prefix=LLVM-NO-EXT
17+
; RUN: llvm-spirv -r %t.spv --spirv-target-env=SPV-IR -o - | llvm-dis -o %t.rev.ll
18+
; RUN: FileCheck < %t.rev.ll %s --check-prefix=LLVM-NO-EXT-SPV-IR
1519

1620
; CHECK-SPIRV: Capability FMAKHR
1721
; CHECK-SPIRV: Extension "SPV_KHR_fma"
@@ -28,9 +32,17 @@
2832
; CHECK-SPIRV-NO-EXT: ExtInst [[#TYPE_FLOAT]] [[#]] [[#]] fma
2933
; CHECK-SPIRV-NO-EXT: ExtInst [[#TYPE_VEC]] [[#]] [[#]] fma
3034

31-
; CHECK-LLVM: %{{.*}} = call spir_func float @_Z3fmafff(float %{{.*}}, float %{{.*}}, float %{{.*}})
32-
; CHECK-LLVM: %{{.*}} = call spir_func <4 x float> @_Z3fmaDv4_fS_S_(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}})
33-
; CHECK-LLVM: %{{.*}} = call spir_func float @_Z3fmafff(float %{{.*}}, float %{{.*}}, float %{{.*}})
35+
; CHECK-LLVM: %{{.*}} = call float @llvm.fma.f32(float %{{.*}}, float %{{.*}}, float %{{.*}})
36+
; CHECK-LLVM: %{{.*}} = call <4 x float> @llvm.fma.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}})
37+
; CHECK-LLVM: %{{.*}} = call float @llvm.fma.f32(float %{{.*}}, float %{{.*}}, float %{{.*}})
38+
39+
; LLVM-NO-EXT: %{{.*}} = call spir_func float @_Z3fmafff(float %{{.*}}, float %{{.*}}, float %{{.*}})
40+
; LLVM-NO-EXT: %{{.*}} = call spir_func <4 x float> @_Z3fmaDv4_fS_S_(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}})
41+
; LLVM-NO-EXT: %{{.*}} = call spir_func float @_Z3fmafff(float %{{.*}}, float %{{.*}}, float %{{.*}})
42+
43+
; LLVM-NO-EXT-SPV-IR: %{{.*}} = call spir_func float @_Z15__spirv_ocl_fmafff(float %{{.*}}, float %{{.*}}, float %{{.*}})
44+
; LLVM-NO-EXT-SPV-IR: %{{.*}} = call spir_func <4 x float> @_Z15__spirv_ocl_fmaDv4_fS_S_(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}})
45+
; LLVM-NO-EXT-SPV-IR: %{{.*}} = call spir_func float @_Z15__spirv_ocl_fmafff(float %{{.*}}, float %{{.*}}, float %{{.*}})
3446

3547
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
3648
target triple = "spir64-unknown-unknown"

0 commit comments

Comments
 (0)