summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkkyzylov <ksenia.kyzylova@intel.com>2016-11-04 20:37:35 +0300
committerYaxun (Sam) Liu <yaxun.liu@amd.com>2016-11-04 13:37:35 -0400
commit509c3cd5ab50fad5402c631ea437aea55e882e05 (patch)
tree48fe9ac7d67b7bbba63049e456ddc421d856a5ad
parentfdf62322cd2bb30c051d128c8dc5797771578128 (diff)
Fix fox OpenCL C++ built-ins translation (#196)
-rw-r--r--lib/SPIRV/SPIRVWriter.cpp8
-rw-r--r--test/FOrdGreaterThanEqual_bool.ll46
-rw-r--r--test/FOrdGreaterThanEqual_int.ll46
-rw-r--r--test/select.ll46
4 files changed, 146 insertions, 0 deletions
diff --git a/lib/SPIRV/SPIRVWriter.cpp b/lib/SPIRV/SPIRVWriter.cpp
index 6b3350a..de7c1ca 100644
--- a/lib/SPIRV/SPIRVWriter.cpp
+++ b/lib/SPIRV/SPIRVWriter.cpp
@@ -1712,6 +1712,10 @@ LLVMToSPIRV::transBuiltinToInstWithoutDecoration(Op OC,
BArgs[4], BArgs[5], BB);
}
break;
+ case OpSelect: {
+ auto BArgs = transValue(getArguments(CI), BB);
+ return BM->addSelectInst(BArgs[0], BArgs[1], BArgs[2], BB);
+ }
default: {
if (isCvtOpCode(OC) && OC != OpGenericCastToPtrExplicit) {
return BM->addUnaryInst(OC, transType(CI->getType()),
@@ -1727,6 +1731,10 @@ LLVMToSPIRV::transBuiltinToInstWithoutDecoration(Op OC,
auto Cmp = BM->addCmpInst(OC, BBT,
transValue(CI->getArgOperand(0), BB),
transValue(CI->getArgOperand(1), BB), BB);
+ // OpenCL C and OpenCL C++ built-ins may have different return type
+ if (ResultTy == BoolTy)
+ return Cmp;
+ assert(IsVector || (!IsVector && ResultTy->isIntegerTy(32)));
auto Zero = transValue(Constant::getNullValue(ResultTy), BB);
auto One = transValue(
IsVector ? Constant::getAllOnesValue(ResultTy) : getInt32(M, 1), BB);
diff --git a/test/FOrdGreaterThanEqual_bool.ll b/test/FOrdGreaterThanEqual_bool.ll
new file mode 100644
index 0000000..c6efd69
--- /dev/null
+++ b/test/FOrdGreaterThanEqual_bool.ll
@@ -0,0 +1,46 @@
+; RUN: llvm-as %s -o %t.bc
+; RUN: llvm-spirv %t.bc -spirv-text -o %t.spt
+; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
+
+; CHECK-SPIRV: 5 FOrdGreaterThanEqual
+; CHECK-SPIRV-NOT: Select
+
+; LLVM IR was generated with -cl-std=c++ option
+
+; ModuleID = 'main'
+target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
+target triple = "spir64-unknown-unknown"
+
+; Function Attrs: nounwind
+define spir_kernel void @test(float %op1, float %op2) #0 {
+entry:
+ %0 = call spir_func zeroext i1 @_Z28__spirv_FOrdGreaterThanEqualff(float %op1, float %op2) #2
+ ret void
+}
+
+; Function Attrs: nounwind readnone
+declare spir_func zeroext i1 @_Z28__spirv_FOrdGreaterThanEqualff(float, float) #1
+
+attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readnone "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #2 = { nounwind readnone }
+
+!opencl.kernels = !{!0}
+!opencl.enable.FP_CONTRACT = !{}
+!opencl.spir.version = !{!6}
+!opencl.ocl.version = !{!7}
+!opencl.used.extensions = !{!8}
+!opencl.used.optional.core.features = !{!8}
+!opencl.compiler.options = !{!8}
+!llvm.ident = !{!9}
+
+!0 = !{void (float, float)* @test, !1, !2, !3, !4, !5}
+!1 = !{!"kernel_arg_addr_space", i32 0, i32 0}
+!2 = !{!"kernel_arg_access_qual", !"none", !"none"}
+!3 = !{!"kernel_arg_type", !"float", !"float"}
+!4 = !{!"kernel_arg_base_type", !"float", !"float"}
+!5 = !{!"kernel_arg_type_qual", !"", !""}
+!6 = !{i32 1, i32 2}
+!7 = !{i32 2, i32 0}
+!8 = !{}
+!9 = !{!"clang version 3.6.1"} \ No newline at end of file
diff --git a/test/FOrdGreaterThanEqual_int.ll b/test/FOrdGreaterThanEqual_int.ll
new file mode 100644
index 0000000..2f05645
--- /dev/null
+++ b/test/FOrdGreaterThanEqual_int.ll
@@ -0,0 +1,46 @@
+; RUN: llvm-as %s -o %t.bc
+; RUN: llvm-spirv %t.bc -spirv-text -o %t.spt
+; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
+
+; CHECK-SPIRV: 5 FOrdGreaterThanEqual {{[0-9]+}} [[result:[0-9]+]] {{[0-9]+}} {{[0-9]+}}
+; CHECK-SPIRV: 6 Select {{[0-9]+}} {{[0-9]+}} [[result]] {{[0-9]+}} {{[0-9]+}}
+
+; LLVM IR was generated with -cl-std=c++ option
+
+; ModuleID = 'main'
+target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
+target triple = "spir64-unknown-unknown"
+
+; Function Attrs: nounwind
+define spir_kernel void @test(float %op1, float %op2) #0 {
+entry:
+ %call = call spir_func i32 @_Z14isgreaterequalff(float %op1, float %op2) #2
+ ret void
+}
+
+; Function Attrs: nounwind readnone
+declare spir_func i32 @_Z14isgreaterequalff(float, float) #1
+
+attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readnone "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #2 = { nounwind readnone }
+
+!opencl.kernels = !{!0}
+!opencl.enable.FP_CONTRACT = !{}
+!opencl.spir.version = !{!6}
+!opencl.ocl.version = !{!7}
+!opencl.used.extensions = !{!8}
+!opencl.used.optional.core.features = !{!8}
+!opencl.compiler.options = !{!8}
+!llvm.ident = !{!9}
+
+!0 = !{void (float, float)* @test, !1, !2, !3, !4, !5}
+!1 = !{!"kernel_arg_addr_space", i32 0, i32 0}
+!2 = !{!"kernel_arg_access_qual", !"none", !"none"}
+!3 = !{!"kernel_arg_type", !"float", !"float"}
+!4 = !{!"kernel_arg_base_type", !"float", !"float"}
+!5 = !{!"kernel_arg_type_qual", !"", !""}
+!6 = !{i32 1, i32 2}
+!7 = !{i32 2, i32 0}
+!8 = !{}
+!9 = !{!"clang version 3.6.1"}
diff --git a/test/select.ll b/test/select.ll
new file mode 100644
index 0000000..778bb92
--- /dev/null
+++ b/test/select.ll
@@ -0,0 +1,46 @@
+; RUN: llvm-as %s -o %t.bc
+; RUN: llvm-spirv %t.bc -spirv-text -o %t.spt
+; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
+
+; CHECK-SPIRV: 6 Select
+
+; LLVM IR was generated with -cl-std=c++ option
+
+; ModuleID = 'main'
+target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
+target triple = "spir64-unknown-unknown"
+
+; Function Attrs: nounwind
+define spir_kernel void @test(i32 %op1, i32 %op2) #0 {
+entry:
+ %0 = trunc i8 undef to i1
+ %call = call spir_func i32 @_Z14__spirv_Selectbii(i1 zeroext %0, i32 %op1, i32 %op2) #2
+ ret void
+}
+
+; Function Attrs: nounwind readnone
+declare spir_func i32 @_Z14__spirv_Selectbii(i1 zeroext, i32, i32) #1
+
+attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readnone "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #2 = { nounwind readnone }
+
+!opencl.kernels = !{!0}
+!opencl.enable.FP_CONTRACT = !{}
+!opencl.spir.version = !{!6}
+!opencl.ocl.version = !{!7}
+!opencl.used.extensions = !{!8}
+!opencl.used.optional.core.features = !{!8}
+!opencl.compiler.options = !{!8}
+!llvm.ident = !{!9}
+
+!0 = !{void (i32, i32)* @test, !1, !2, !3, !4, !5}
+!1 = !{!"kernel_arg_addr_space", i32 0, i32 0}
+!2 = !{!"kernel_arg_access_qual", !"none", !"none"}
+!3 = !{!"kernel_arg_type", !"i32", !"i32"}
+!4 = !{!"kernel_arg_base_type", !"i32", !"i32"}
+!5 = !{!"kernel_arg_type_qual", !"", !""}
+!6 = !{i32 1, i32 2}
+!7 = !{i32 2, i32 0}
+!8 = !{}
+!9 = !{!"clang version 3.6.1"} \ No newline at end of file