diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2018-12-01 21:56:10 +0000 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2018-12-01 21:56:10 +0000 |
commit | af07de40596a90d293c2adc59af1ad50ed1598d0 (patch) | |
tree | a442916f9de5cab00cae4359a63dbd05f6a3445f /clang | |
parent | eff43f6ae3cebbdefe5aac96d0165471421dd44c (diff) | |
download | bcm5719-llvm-af07de40596a90d293c2adc59af1ad50ed1598d0.tar.gz bcm5719-llvm-af07de40596a90d293c2adc59af1ad50ed1598d0.zip |
OpenCL: Extend argument promotion rules to vector types
The spec is ambiguous on whether vector types are allowed to be
implicitly converted. The only legal context I think this can
be used for OpenCL is printf, where it seems necessary.
llvm-svn: 348083
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 23 | ||||
-rw-r--r-- | clang/test/CodeGenOpenCL/printf.cl | 39 |
2 files changed, 57 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 9a83c5cb440..f4edd7b89bf 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -730,20 +730,33 @@ ExprResult Sema::DefaultArgumentPromotion(Expr *E) { return ExprError(); E = Res.get(); + QualType ScalarTy = Ty; + unsigned NumElts = 0; + if (const ExtVectorType *VecTy = Ty->getAs<ExtVectorType>()) { + NumElts = VecTy->getNumElements(); + ScalarTy = VecTy->getElementType(); + } + // If this is a 'float' or '__fp16' (CVR qualified or typedef) // promote to double. // Note that default argument promotion applies only to float (and // half/fp16); it does not apply to _Float16. - const BuiltinType *BTy = Ty->getAs<BuiltinType>(); + const BuiltinType *BTy = ScalarTy->getAs<BuiltinType>(); if (BTy && (BTy->getKind() == BuiltinType::Half || BTy->getKind() == BuiltinType::Float)) { if (getLangOpts().OpenCL && !getOpenCLOptions().isEnabled("cl_khr_fp64")) { - if (BTy->getKind() == BuiltinType::Half) { - E = ImpCastExprToType(E, Context.FloatTy, CK_FloatingCast).get(); - } + if (BTy->getKind() == BuiltinType::Half) { + QualType Ty = Context.FloatTy; + if (NumElts != 0) + Ty = Context.getExtVectorType(Ty, NumElts); + E = ImpCastExprToType(E, Ty, CK_FloatingCast).get(); + } } else { - E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get(); + QualType Ty = Context.DoubleTy; + if (NumElts != 0) + Ty = Context.getExtVectorType(Ty, NumElts); + E = ImpCastExprToType(E, Ty, CK_FloatingCast).get(); } } diff --git a/clang/test/CodeGenOpenCL/printf.cl b/clang/test/CodeGenOpenCL/printf.cl new file mode 100644 index 00000000000..346f6c35bae --- /dev/null +++ b/clang/test/CodeGenOpenCL/printf.cl @@ -0,0 +1,39 @@ +// RUN: %clang_cc1 -cl-std=CL1.2 -cl-ext=-+cl_khr_fp64 -triple spir-unknown-unknown -disable-llvm-passes -emit-llvm -o - %s | FileCheck -check-prefixes=FP64,ALL %s +// RUN: %clang_cc1 -cl-std=CL1.2 -cl-ext=-cl_khr_fp64 -triple spir-unknown-unknown -disable-llvm-passes -emit-llvm -o - %s | FileCheck -check-prefixes=NOFP64,ALL %s + +typedef __attribute__((ext_vector_type(2))) float float2; +typedef __attribute__((ext_vector_type(2))) half half2; + +#ifdef cl_khr_fp64 +typedef __attribute__((ext_vector_type(2))) double double2; +#endif + +int printf(__constant const char* st, ...) __attribute__((format(printf, 1, 2))); + + +// ALL-LABEL: @test_printf_float2( +// FP64: %conv = fpext <2 x float> %0 to <2 x double> +// FP64: %call = call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([5 x i8], [5 x i8] addrspace(2)* @.str, i32 0, i32 0), <2 x double> %conv) + +// NOFP64: call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([5 x i8], [5 x i8] addrspace(2)* @.str, i32 0, i32 0), <2 x float> %0) +kernel void test_printf_float2(float2 arg) { + printf("%v2f", arg); +} + +// ALL-LABEL: @test_printf_half2( +// FP64: %conv = fpext <2 x half> %0 to <2 x double> +// FP64: %call = call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([5 x i8], [5 x i8] addrspace(2)* @.str, i32 0, i32 0), <2 x double> %conv) #2 + +// NOFP64: %conv = fpext <2 x half> %0 to <2 x float> +// NOFP64: %call = call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([5 x i8], [5 x i8] addrspace(2)* @.str, i32 0, i32 0), <2 x float> %conv) #2 +kernel void test_printf_half2(half2 arg) { + printf("%v2f", arg); +} + +#ifdef cl_khr_fp64 +// FP64-LABEL: @test_printf_double2( +// FP64: call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([5 x i8], [5 x i8] addrspace(2)* @.str, i32 0, i32 0), <2 x double> %0) #2 +kernel void test_printf_double2(double2 arg) { + printf("%v2f", arg); +} +#endif |