| 1 |
; Source: |
| 2 |
; void kernel k1 (float a, float b, float c) { |
| 3 |
; #pragma OPENCL FP_CONTRACT OFF |
| 4 |
; float d = a * b + c; |
| 5 |
; } |
| 6 |
; |
| 7 |
; void kernel k2 (float a, float b, float c) { |
| 8 |
; float d = a * b + c; |
| 9 |
; } |
| 10 |
; |
| 11 |
; void kernel k3 (float a, float b, float c) { |
| 12 |
; float d = a * b; // a * b together with -d in the next statement look |
| 13 |
; float e = a * c - d; // exactly like an unfused fmuladd in LLVM IR |
| 14 |
; } |
| 15 |
; |
| 16 |
; IR generated using the following commands: |
| 17 |
; clang -cc1 -x cl -emit-llvm -O2 -disable-llvm-passes -triple spir64 1.cl -o 1.ll |
| 18 |
; opt -mem2reg 1.ll -S -o 1.o.ll |
| 19 |
|
| 20 |
; RUN: llvm-as %s -o %t.bc |
| 21 |
; RUN: llvm-spirv %t.bc -o %t.spv.default |
| 22 |
; RUN: llvm-spirv %t.spv.default -to-text -o - | FileCheck %s --check-prefixes CHECK,CHECK-ON |
| 23 |
; RUN: spirv-val %t.spv.default |
| 24 |
|
| 25 |
; RUN: llvm-as %s -o %t.bc |
| 26 |
; RUN: llvm-spirv %t.bc -o %t.spv.off --spirv-fp-contract=off |
| 27 |
; RUN: llvm-spirv %t.spv.off -to-text -o - | FileCheck %s --check-prefixes CHECK,CHECK-OFF |
| 28 |
; RUN: spirv-val %t.spv.off |
| 29 |
|
| 30 |
; RUN: llvm-as %s -o %t.bc |
| 31 |
; RUN: llvm-spirv %t.bc -o %t.spv.fast --spirv-fp-contract=fast |
| 32 |
; RUN: llvm-spirv %t.spv.fast -to-text -o - | FileCheck %s --check-prefixes CHECK,CHECK-FAST |
| 33 |
; RUN: spirv-val %t.spv.fast |
| 34 |
|
| 35 |
; RUN: llvm-as %s -o %t.bc |
| 36 |
; RUN: llvm-spirv %t.bc -o %t.spv.on --spirv-fp-contract=on |
| 37 |
; RUN: llvm-spirv %t.spv.on -to-text -o - | FileCheck %s --check-prefixes CHECK,CHECK-ON |
| 38 |
; RUN: spirv-val %t.spv.on |
| 39 |
|
| 40 |
; CHECK: EntryPoint 6 [[K1:[0-9]+]] "k1" |
| 41 |
; CHECK: EntryPoint 6 [[K2:[0-9]+]] "k2" |
| 42 |
; CHECK: EntryPoint 6 [[K3:[0-9]+]] "k3" |
| 43 |
|
| 44 |
; CHECK-OFF: ExecutionMode [[K1]] 31 |
| 45 |
; CHECK-OFF: ExecutionMode [[K2]] 31 |
| 46 |
; CHECK-OFF: ExecutionMode [[K3]] 31 |
| 47 |
|
| 48 |
; CHECK-FAST-NOT: ExecutionMode [[K1]] 31 |
| 49 |
; CHECK-FAST-NOT: ExecutionMode [[K2]] 31 |
| 50 |
; CHECK-FAST-NOT: ExecutionMode [[K3]] 31 |
| 51 |
|
| 52 |
; CHECK-ON: ExecutionMode [[K1]] 31 |
| 53 |
; CHECK-ON-NOT: ExecutionMode [[K2]] 31 |
| 54 |
; CHECK-ON: ExecutionMode [[K3]] 31 |
| 55 |
|
| 56 |
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" |
| 57 |
target triple = "spir64" |
| 58 |
|
| 59 |
; Function Attrs: convergent nounwind |
| 60 |
define spir_kernel void @k1(float %a, float %b, float %c) #0 !kernel_arg_addr_space !4 !kernel_arg_access_qual !5 !kernel_arg_type !6 !kernel_arg_base_type !6 !kernel_arg_type_qual !7 { |
| 61 |
entry: |
| 62 |
%mul = fmul float %a, %b |
| 63 |
%add = fadd float %mul, %c |
| 64 |
ret void |
| 65 |
} |
| 66 |
|
| 67 |
; Function Attrs: convergent nounwind |
| 68 |
define spir_kernel void @k2(float %a, float %b, float %c) #0 !kernel_arg_addr_space !4 !kernel_arg_access_qual !5 !kernel_arg_type !6 !kernel_arg_base_type !6 !kernel_arg_type_qual !7 { |
| 69 |
entry: |
| 70 |
%0 = call float @llvm.fmuladd.f32(float %a, float %b, float %c) |
| 71 |
ret void |
| 72 |
} |
| 73 |
|
| 74 |
; Function Attrs: nounwind readnone speculatable |
| 75 |
declare float @llvm.fmuladd.f32(float, float, float) #2 |
| 76 |
|
| 77 |
; Function Attrs: convergent nounwind |
| 78 |
define spir_kernel void @k3(float %a, float %b, float %c) #0 !kernel_arg_addr_space !4 !kernel_arg_access_qual !5 !kernel_arg_type !6 !kernel_arg_base_type !6 !kernel_arg_type_qual !7 { |
| 79 |
entry: |
| 80 |
%mul = fmul float %a, %b |
| 81 |
%neg = fsub float -0.000000e+00, %mul |
| 82 |
%0 = call float @llvm.fmuladd.f32(float %a, float %c, float %neg) |
| 83 |
ret void |
| 84 |
} |
| 85 |
|
| 86 |
attributes #0 = { convergent nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "uniform-work-group-size"="true" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 87 |
attributes #1 = { argmemonly nounwind } |
| 88 |
attributes #2 = { nounwind readnone speculatable } |
| 89 |
|
| 90 |
!llvm.module.flags = !{!0} |
| 91 |
!opencl.ocl.version = !{!1} |
| 92 |
!opencl.spir.version = !{!2} |
| 93 |
!llvm.ident = !{!3} |
| 94 |
|
| 95 |
!0 = !{i32 1, !"wchar_size", i32 4} |
| 96 |
!1 = !{i32 1, i32 0} |
| 97 |
!2 = !{i32 1, i32 2} |
| 98 |
!3 = !{!"clang version 7.0.1"} |
| 99 |
!4 = !{i32 0, i32 0, i32 0} |
| 100 |
!5 = !{!"none", !"none", !"none"} |
| 101 |
!6 = !{!"float", !"float", !"float"} |
| 102 |
!7 = !{!"", !"", !""} |