[PATCH] D24235: [OpenCL] Improve double literal handling
svenvh added inline comments. Comment at: lib/Sema/SemaChecking.cpp:3732 // If this is an implicit conversion from float -> double, remove it. if (ImplicitCastExpr *Cast = dyn_cast(OrigArg)) { The comment should mention float -> float now as well. Comment at: lib/Sema/SemaExpr.cpp:712 + Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, + nullptr, VK_RValue); You can change this back to what it was before your first commit (which also fixes the indentation). https://reviews.llvm.org/D24235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D24235: [OpenCL] Improve double literal handling
neil.hickey removed rL LLVM as the repository for this revision. neil.hickey updated this revision to Diff 77961. neil.hickey added a comment. Fixes to tests and removal of incorrect check to stop float to float casts if types match. This was still needed as it was an lvalue to rvalue cast. Added extra code in SemaChecking to allow a float to float cast to appear and be handled. https://reviews.llvm.org/D24235 Files: lib/Sema/SemaChecking.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaType.cpp test/CodeGenOpenCL/fpmath.cl test/SemaOpenCL/extensions.cl Index: test/SemaOpenCL/extensions.cl === --- test/SemaOpenCL/extensions.cl +++ test/SemaOpenCL/extensions.cl @@ -1,13 +1,20 @@ // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1 +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 -DFP64 // Test with a target not supporting fp64. // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 +#ifdef FP64 +// expected-no-diagnostics +#endif + +#if __OPENCL_C_VERSION__ < 120 void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}} double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} (void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}} } +#endif #pragma OPENCL EXTENSION cl_khr_fp64 : enable #ifdef NOFP64 @@ -21,16 +28,19 @@ #endif (void) 1.0; + #ifdef NOFP64 -// expected-warning@-2{{double precision constant requires cl_khr_fp64, casting to single precision}} +// expected-warning@-3{{double precision constant requires cl_khr_fp64, casting to single precision}} #endif } #pragma OPENCL EXTENSION cl_khr_fp64 : disable #ifdef NOFP64 // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}} #endif +#if __OPENCL_C_VERSION__ < 120 void f3(void) { double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} } +#endif Index: test/CodeGenOpenCL/fpmath.cl === --- test/CodeGenOpenCL/fpmath.cl +++ test/CodeGenOpenCL/fpmath.cl @@ -1,5 +1,7 @@ // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck --check-prefix=CHECK --check-prefix=NODIVOPT %s // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown -cl-fp32-correctly-rounded-divide-sqrt | FileCheck --check-prefix=CHECK --check-prefix=DIVOPT %s +// RUN: %clang_cc1 %s -emit-llvm -o - -DNOFP64 -cl-std=CL1.2 -triple r600-unknown-unknown -target-cpu r600 -pedantic | FileCheck --check-prefix=CHECK-FLT %s +// RUN: %clang_cc1 %s -emit-llvm -o - -DFP64 -cl-std=CL1.2 -pedantic | FileCheck --check-prefix=CHECK-DBL %s typedef __attribute__(( ext_vector_type(4) )) float float4; @@ -21,14 +23,26 @@ return a / b; } -#pragma OPENCL EXTENSION cl_khr_fp64 : enable +#if __OPENCL_C_VERSION__ >=120 +void printf(constant char* fmt, ...); + +void testdbllit(long *val) { + // CHECK-FLT: float 2.00e+01 + // CHECK-DBL: double 2.00e+01 + printf("%f", 20.0); +} +#endif + +#ifndef NOFP64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable double dpscalardiv(double a, double b) { // CHECK: @dpscalardiv // CHECK: #[[ATTR]] // CHECK-NOT: !fpmath return a / b; } +#endif // CHECK: attributes #[[ATTR]] = { // NODIVOPT: "correctly-rounded-divide-sqrt-fp-math"="false" Index: lib/Sema/SemaType.cpp === --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -1401,8 +1401,7 @@ Result = Context.DoubleTy; if (S.getLangOpts().OpenCL && -!((S.getLangOpts().OpenCLVersion >= 120) || - S.getOpenCLOptions().cl_khr_fp64)) { +!(S.getOpenCLOptions().cl_khr_fp64)) { S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) << Result << "cl_khr_fp64"; declarator.setInvalidType(true); Index: lib/Sema/SemaExpr.cpp === --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -705,9 +705,11 @@ if (getLangOpts().ObjCAutoRefCount && E->getType().getObjCLifetime() == Qualifiers::OCL_Weak) Cleanup.setExprNeedsCleanups(true); + + ExprResult Res = E; - ExprResult Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, -nullptr, VK_RValue); + Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, + nullptr, VK_RValue); // C11 6.3.2.1p2: // ... if the lvalue has atomic type, the value has the non-atomic version @@ -817,8 +819,16 @@ // double. const BuiltinType *BTy = Ty->getAs(); if (BTy && (BTy->getKind() ==
[PATCH] D24235: [OpenCL] Improve double literal handling
This revision was automatically updated to reflect the committed changes. Closed by commit rL286815: Improve handling of floating point literals in OpenCL to only use doubleā¦ (authored by neil.hickey). Changed prior to commit: https://reviews.llvm.org/D24235?vs=77600=77783#toc Repository: rL LLVM https://reviews.llvm.org/D24235 Files: cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/test/CodeGenOpenCL/fpmath.cl cfe/trunk/test/SemaOpenCL/extensions.cl Index: cfe/trunk/test/SemaOpenCL/extensions.cl === --- cfe/trunk/test/SemaOpenCL/extensions.cl +++ cfe/trunk/test/SemaOpenCL/extensions.cl @@ -1,5 +1,6 @@ // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1 +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 -DFP64 // Test with a target not supporting fp64. // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16 @@ -21,12 +22,16 @@ // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -cl-ext=+cl_khr_fp64 -cl-ext=+cl_khr_fp16 -cl-ext=-cl_khr_fp64 -DNOFP64 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -cl-ext=+cl_khr_fp64,-cl_khr_fp64,+cl_khr_fp16 -DNOFP64 +#ifdef FP64 +// expected-no-diagnostics +#endif - +#if __OPENCL_C_VERSION__ < 120 void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}} double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} (void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}} } +#endif #pragma OPENCL EXTENSION cl_khr_fp64 : enable #ifdef NOFP64 @@ -45,16 +50,19 @@ #endif (void) 1.0; + #ifdef NOFP64 -// expected-warning@-2{{double precision constant requires cl_khr_fp64, casting to single precision}} +// expected-warning@-6{{double precision constant requires cl_khr_fp64, casting to single precision}} #endif } #pragma OPENCL EXTENSION cl_khr_fp64 : disable #ifdef NOFP64 // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}} #endif +#if __OPENCL_C_VERSION__ < 120 void f3(void) { double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} } +#endif Index: cfe/trunk/test/CodeGenOpenCL/fpmath.cl === --- cfe/trunk/test/CodeGenOpenCL/fpmath.cl +++ cfe/trunk/test/CodeGenOpenCL/fpmath.cl @@ -1,5 +1,6 @@ // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck --check-prefix=CHECK --check-prefix=NODIVOPT %s // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown -cl-fp32-correctly-rounded-divide-sqrt | FileCheck --check-prefix=CHECK --check-prefix=DIVOPT %s +// RUN: %clang_cc1 %s -emit-llvm -o - -DNOFP64 -cl-std=CL1.1 -triple r600-unknown-unknown -target-cpu r600 -pedantic | FileCheck --check-prefix=CHECK-DBL %s typedef __attribute__(( ext_vector_type(4) )) float float4; @@ -21,14 +22,26 @@ return a / b; } +void printf(constant char* fmt, ...); + +#ifndef NOFP64 #pragma OPENCL EXTENSION cl_khr_fp64 : enable +#endif +void testdbllit(long *val) { + // CHECK-DBL: float 2.00e+01 + // CHECK: double 2.00e+01 + printf("%f", 20.0); +} +#ifndef NOFP64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable double dpscalardiv(double a, double b) { // CHECK: @dpscalardiv // CHECK: #[[ATTR]] // CHECK-NOT: !fpmath return a / b; } +#endif // CHECK: attributes #[[ATTR]] = { // NODIVOPT: "correctly-rounded-divide-sqrt-fp-math"="false" Index: cfe/trunk/lib/Sema/SemaType.cpp === --- cfe/trunk/lib/Sema/SemaType.cpp +++ cfe/trunk/lib/Sema/SemaType.cpp @@ -1402,8 +1402,7 @@ Result = Context.DoubleTy; if (S.getLangOpts().OpenCL && -!((S.getLangOpts().OpenCLVersion >= 120) || - S.getOpenCLOptions().cl_khr_fp64)) { +!(S.getOpenCLOptions().cl_khr_fp64)) { S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) << Result << "cl_khr_fp64"; declarator.setInvalidType(true); Index: cfe/trunk/lib/Sema/SemaExpr.cpp === --- cfe/trunk/lib/Sema/SemaExpr.cpp +++ cfe/trunk/lib/Sema/SemaExpr.cpp @@ -705,9 +705,13 @@ if (getLangOpts().ObjCAutoRefCount && E->getType().getObjCLifetime() == Qualifiers::OCL_Weak) Cleanup.setExprNeedsCleanups(true); + + ExprResult Res = E; - ExprResult Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, -nullptr, VK_RValue); + if ( T != E->getType()) { +Res = ImplicitCastExpr::Create(Context, T,
[PATCH] D24235: [OpenCL] Improve double literal handling
neil.hickey updated this revision to Diff 77600. neil.hickey added a comment. Improving now confusing comment. https://reviews.llvm.org/D24235 Files: lib/Sema/SemaExpr.cpp lib/Sema/SemaType.cpp test/CodeGenOpenCL/fpmath.cl test/SemaOpenCL/extensions.cl Index: test/SemaOpenCL/extensions.cl === --- test/SemaOpenCL/extensions.cl +++ test/SemaOpenCL/extensions.cl @@ -1,13 +1,20 @@ // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1 +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 -DFP64 // Test with a target not supporting fp64. // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 +#ifdef FP64 +// expected-no-diagnostics +#endif + +#if __OPENCL_C_VERSION__ < 120 void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}} double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} (void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}} } +#endif #pragma OPENCL EXTENSION cl_khr_fp64 : enable #ifdef NOFP64 @@ -21,16 +28,19 @@ #endif (void) 1.0; + #ifdef NOFP64 -// expected-warning@-2{{double precision constant requires cl_khr_fp64, casting to single precision}} +// expected-warning@-6{{double precision constant requires cl_khr_fp64, casting to single precision}} #endif } #pragma OPENCL EXTENSION cl_khr_fp64 : disable #ifdef NOFP64 // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}} #endif +#if __OPENCL_C_VERSION__ < 120 void f3(void) { double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} } +#endif Index: test/CodeGenOpenCL/fpmath.cl === --- test/CodeGenOpenCL/fpmath.cl +++ test/CodeGenOpenCL/fpmath.cl @@ -1,5 +1,6 @@ // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck --check-prefix=CHECK --check-prefix=NODIVOPT %s // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown -cl-fp32-correctly-rounded-divide-sqrt | FileCheck --check-prefix=CHECK --check-prefix=DIVOPT %s +// RUN: %clang_cc1 %s -emit-llvm -o - -DNOFP64 -cl-std=CL1.1 -triple r600-unknown-unknown -target-cpu r600 -pedantic | FileCheck --check-prefix=CHECK-DBL %s typedef __attribute__(( ext_vector_type(4) )) float float4; @@ -21,14 +22,26 @@ return a / b; } +void printf(constant char* fmt, ...); + +#ifndef NOFP64 #pragma OPENCL EXTENSION cl_khr_fp64 : enable +#endif +void testdbllit(long *val) { + // CHECK-DBL: float 2.00e+01 + // CHECK: double 2.00e+01 + printf("%f", 20.0); +} +#ifndef NOFP64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable double dpscalardiv(double a, double b) { // CHECK: @dpscalardiv // CHECK: #[[ATTR]] // CHECK-NOT: !fpmath return a / b; } +#endif // CHECK: attributes #[[ATTR]] = { // NODIVOPT: "correctly-rounded-divide-sqrt-fp-math"="false" Index: lib/Sema/SemaType.cpp === --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -1401,8 +1401,7 @@ Result = Context.DoubleTy; if (S.getLangOpts().OpenCL && -!((S.getLangOpts().OpenCLVersion >= 120) || - S.getOpenCLOptions().cl_khr_fp64)) { +!(S.getOpenCLOptions().cl_khr_fp64)) { S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) << Result << "cl_khr_fp64"; declarator.setInvalidType(true); Index: lib/Sema/SemaExpr.cpp === --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -705,9 +705,13 @@ if (getLangOpts().ObjCAutoRefCount && E->getType().getObjCLifetime() == Qualifiers::OCL_Weak) Cleanup.setExprNeedsCleanups(true); + + ExprResult Res = E; - ExprResult Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, -nullptr, VK_RValue); + if ( T != E->getType()) { +Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, + nullptr, VK_RValue); + } // C11 6.3.2.1p2: // ... if the lvalue has atomic type, the value has the non-atomic version @@ -817,8 +821,16 @@ // double. const BuiltinType *BTy = Ty->getAs(); if (BTy && (BTy->getKind() == BuiltinType::Half || - BTy->getKind() == BuiltinType::Float)) -E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get(); + BTy->getKind() == BuiltinType::Float)) { +if (getLangOpts().OpenCL && +!(getOpenCLOptions().cl_khr_fp64)) { +if (BTy->getKind() == BuiltinType::Half) { +E = ImpCastExprToType(E, Context.FloatTy,
[PATCH] D24235: [OpenCL] Improve double literal handling
svenvh added inline comments. Comment at: lib/Sema/SemaExpr.cpp:3431 +.getSupportedOpenCLOpts() +.cl_khr_fp64) || getOpenCLOptions().cl_khr_fp64)) { yaxunl wrote: > neil.hickey wrote: > > yaxunl wrote: > > > This check > > > (getLangOpts().OpenCLVersion >= 120 && > > > Context.getTargetInfo() > > > .getSupportedOpenCLOpts() > > > .cl_khr_fp64) > > > > > > is redundant since for CL 1.2 and above getOpenCLOptions().cl_khr_fp64 is > > > set to be true by default. > > This is get**Supported**OpenCLOpts(). Some hardware may not support doubles > In Sema::Initialize(), there is code to initialize enabled extensions: > > ``` > // Initialize predefined OpenCL types and supported optional core features. > if (getLangOpts().OpenCL) { > #define OPENCLEXT(Ext) \ > if > (Context.getTargetInfo().getSupportedOpenCLOpts().is_##Ext##_supported_core( \ > getLangOpts().OpenCLVersion)) \ >getOpenCLOptions().Ext = 1; > #include "clang/Basic/OpenCLExtensions.def" > > ``` > `is_##Ext##_supported_core` accounts for two factors: 1. whether the target > supports the extension; 2. whether the extension has become OpenCL core > featrue. > > Since getOpenCLOptions().cl_khr_fp64 is initialized with the same value as in > the mentioned check, the check is redundant. Your new patch no longer does version checks, so there is no need to mention it in the comments anymore I'd say. https://reviews.llvm.org/D24235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D24235: [OpenCL] Improve double literal handling
yaxunl added inline comments. Comment at: test/SemaOpenCL/extensions.cl:28 +#ifdef FP64 +// expected-no-diagnostics +#endif expected-no-diagnostics applies to the whole file. better move to the beginning of the file. otherwise LGTM. Thanks! https://reviews.llvm.org/D24235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D24235: [OpenCL] Improve double literal handling
neil.hickey updated this revision to Diff 76587. neil.hickey added a comment. Sorry for the delay. It looks like the code to handle extensions was changed since Neil Henning added the check against opencl 1.2. Perhaps the best approach is just to remove the check. https://reviews.llvm.org/D24235 Files: lib/Sema/SemaExpr.cpp lib/Sema/SemaType.cpp test/CodeGenOpenCL/fpmath.cl test/SemaOpenCL/extensions.cl Index: test/SemaOpenCL/extensions.cl === --- test/SemaOpenCL/extensions.cl +++ test/SemaOpenCL/extensions.cl @@ -1,13 +1,16 @@ // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1 +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 -DFP64 // Test with a target not supporting fp64. // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 +#if __OPENCL_C_VERSION__ < 120 void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}} double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} (void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}} } +#endif #pragma OPENCL EXTENSION cl_khr_fp64 : enable #ifdef NOFP64 @@ -21,16 +24,22 @@ #endif (void) 1.0; +#ifdef FP64 +// expected-no-diagnostics +#endif + #ifdef NOFP64 -// expected-warning@-2{{double precision constant requires cl_khr_fp64, casting to single precision}} +// expected-warning@-6{{double precision constant requires cl_khr_fp64, casting to single precision}} #endif } #pragma OPENCL EXTENSION cl_khr_fp64 : disable #ifdef NOFP64 // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}} #endif +#if __OPENCL_C_VERSION__ < 120 void f3(void) { double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} } +#endif Index: test/CodeGenOpenCL/fpmath.cl === --- test/CodeGenOpenCL/fpmath.cl +++ test/CodeGenOpenCL/fpmath.cl @@ -1,5 +1,6 @@ // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck --check-prefix=CHECK --check-prefix=NODIVOPT %s // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown -cl-fp32-correctly-rounded-divide-sqrt | FileCheck --check-prefix=CHECK --check-prefix=DIVOPT %s +// RUN: %clang_cc1 %s -emit-llvm -o - -DNOFP64 -cl-std=CL1.1 -triple r600-unknown-unknown -target-cpu r600 -pedantic | FileCheck --check-prefix=CHECK-DBL %s typedef __attribute__(( ext_vector_type(4) )) float float4; @@ -21,14 +22,26 @@ return a / b; } +void printf(constant char* fmt, ...); + +#ifndef NOFP64 #pragma OPENCL EXTENSION cl_khr_fp64 : enable +#endif +void testdbllit(long *val) { + // CHECK-DBL: float 2.00e+01 + // CHECK: double 2.00e+01 + printf("%f", 20.0); +} +#ifndef NOFP64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable double dpscalardiv(double a, double b) { // CHECK: @dpscalardiv // CHECK: #[[ATTR]] // CHECK-NOT: !fpmath return a / b; } +#endif // CHECK: attributes #[[ATTR]] = { // NODIVOPT: "correctly-rounded-divide-sqrt-fp-math"="false" Index: lib/Sema/SemaType.cpp === --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -1401,8 +1401,7 @@ Result = Context.DoubleTy; if (S.getLangOpts().OpenCL && -!((S.getLangOpts().OpenCLVersion >= 120) || - S.getOpenCLOptions().cl_khr_fp64)) { +!(S.getOpenCLOptions().cl_khr_fp64)) { S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) << Result << "cl_khr_fp64"; declarator.setInvalidType(true); Index: lib/Sema/SemaExpr.cpp === --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -705,9 +705,13 @@ if (getLangOpts().ObjCAutoRefCount && E->getType().getObjCLifetime() == Qualifiers::OCL_Weak) Cleanup.setExprNeedsCleanups(true); + + ExprResult Res = E; - ExprResult Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, -nullptr, VK_RValue); + if ( T != E->getType()) { +Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, + nullptr, VK_RValue); + } // C11 6.3.2.1p2: // ... if the lvalue has atomic type, the value has the non-atomic version @@ -817,8 +821,16 @@ // double. const BuiltinType *BTy = Ty->getAs(); if (BTy && (BTy->getKind() == BuiltinType::Half || - BTy->getKind() == BuiltinType::Float)) -E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get(); + BTy->getKind() == BuiltinType::Float)) { +if (getLangOpts().OpenCL && +
Re: [PATCH] D24235: [OpenCL] Improve double literal handling
yaxunl added inline comments. Comment at: lib/Sema/SemaExpr.cpp:3431 @@ -3410,1 +3430,3 @@ +.getSupportedOpenCLOpts() +.cl_khr_fp64) || getOpenCLOptions().cl_khr_fp64)) { neil.hickey wrote: > yaxunl wrote: > > This check > > (getLangOpts().OpenCLVersion >= 120 && > > Context.getTargetInfo() > > .getSupportedOpenCLOpts() > > .cl_khr_fp64) > > > > is redundant since for CL 1.2 and above getOpenCLOptions().cl_khr_fp64 is > > set to be true by default. > This is get**Supported**OpenCLOpts(). Some hardware may not support doubles In Sema::Initialize(), there is code to initialize enabled extensions: ``` // Initialize predefined OpenCL types and supported optional core features. if (getLangOpts().OpenCL) { #define OPENCLEXT(Ext) \ if (Context.getTargetInfo().getSupportedOpenCLOpts().is_##Ext##_supported_core( \ getLangOpts().OpenCLVersion)) \ getOpenCLOptions().Ext = 1; #include "clang/Basic/OpenCLExtensions.def" ``` `is_##Ext##_supported_core` accounts for two factors: 1. whether the target supports the extension; 2. whether the extension has become OpenCL core featrue. Since getOpenCLOptions().cl_khr_fp64 is initialized with the same value as in the mentioned check, the check is redundant. https://reviews.llvm.org/D24235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24235: [OpenCL] Improve double literal handling
neil.hickey added inline comments. Comment at: lib/Sema/SemaExpr.cpp:3431 @@ -3410,1 +3430,3 @@ +.getSupportedOpenCLOpts() +.cl_khr_fp64) || getOpenCLOptions().cl_khr_fp64)) { yaxunl wrote: > This check > (getLangOpts().OpenCLVersion >= 120 && > Context.getTargetInfo() > .getSupportedOpenCLOpts() > .cl_khr_fp64) > > is redundant since for CL 1.2 and above getOpenCLOptions().cl_khr_fp64 is set > to be true by default. This is get**Supported**OpenCLOpts(). Some hardware may not support doubles https://reviews.llvm.org/D24235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24235: [OpenCL] Improve double literal handling
yaxunl added inline comments. Comment at: lib/Sema/SemaExpr.cpp:3431 @@ -3410,1 +3430,3 @@ +.getSupportedOpenCLOpts() +.cl_khr_fp64) || getOpenCLOptions().cl_khr_fp64)) { This check (getLangOpts().OpenCLVersion >= 120 && Context.getTargetInfo() .getSupportedOpenCLOpts() .cl_khr_fp64) is redundant since for CL 1.2 and above getOpenCLOptions().cl_khr_fp64 is set to be true by default. https://reviews.llvm.org/D24235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24235: [OpenCL] Improve double literal handling
neil.hickey added a reviewer: tstellarAMD. neil.hickey updated this revision to Diff 71837. neil.hickey added a comment. Herald added subscribers: yaxunl, wdng. There was a bug whereby an implicitcast was being applied from float to float, this caused issues later on in builin processing which caused an assertion. This changed patch removes the duplicate, superfluous, cast. https://reviews.llvm.org/D24235 Files: lib/Sema/SemaExpr.cpp lib/Sema/SemaType.cpp test/CodeGenOpenCL/fpmath.cl test/SemaOpenCL/extensions.cl Index: test/SemaOpenCL/extensions.cl === --- test/SemaOpenCL/extensions.cl +++ test/SemaOpenCL/extensions.cl @@ -1,13 +1,16 @@ // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1 +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 -DFP64 // Test with a target not supporting fp64. // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 +#if __OPENCL_C_VERSION__ < 120 void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}} double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} (void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}} } +#endif #pragma OPENCL EXTENSION cl_khr_fp64 : enable #ifdef NOFP64 @@ -21,16 +24,22 @@ #endif (void) 1.0; +#ifdef FP64 +// expected-no-diagnostics +#endif + #ifdef NOFP64 -// expected-warning@-2{{double precision constant requires cl_khr_fp64, casting to single precision}} +// expected-warning@-6{{double precision constant requires cl_khr_fp64, casting to single precision}} #endif } #pragma OPENCL EXTENSION cl_khr_fp64 : disable #ifdef NOFP64 // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}} #endif +#if __OPENCL_C_VERSION__ < 120 void f3(void) { double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} } +#endif Index: test/CodeGenOpenCL/fpmath.cl === --- test/CodeGenOpenCL/fpmath.cl +++ test/CodeGenOpenCL/fpmath.cl @@ -1,5 +1,6 @@ // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck --check-prefix=CHECK --check-prefix=NODIVOPT %s // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown -cl-fp32-correctly-rounded-divide-sqrt | FileCheck --check-prefix=CHECK --check-prefix=DIVOPT %s +// RUN: %clang_cc1 %s -emit-llvm -o - -DNOFP64 -cl-std=CL1.1 -triple r600-unknown-unknown -target-cpu r600 -pedantic | FileCheck --check-prefix=CHECK-DBL %s typedef __attribute__(( ext_vector_type(4) )) float float4; @@ -21,14 +22,26 @@ return a / b; } +void printf(constant char* fmt, ...); + +#ifndef NOFP64 #pragma OPENCL EXTENSION cl_khr_fp64 : enable +#endif +void testdbllit(long *val) { + // CHECK-DBL: float 2.00e+01 + // CHECK: double 2.00e+01 + printf("%f", 20.0); +} +#ifndef NOFP64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable double dpscalardiv(double a, double b) { // CHECK: @dpscalardiv // CHECK: #[[ATTR]] // CHECK-NOT: !fpmath return a / b; } +#endif // CHECK: attributes #[[ATTR]] = { // NODIVOPT: "correctly-rounded-divide-sqrt-fp-math"="false" Index: lib/Sema/SemaType.cpp === --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -1401,7 +1401,8 @@ Result = Context.DoubleTy; if (S.getLangOpts().OpenCL && -!((S.getLangOpts().OpenCLVersion >= 120) || +!((S.getLangOpts().OpenCLVersion >= 120 + && S.Context.getTargetInfo().getSupportedOpenCLOpts().cl_khr_fp64) || S.getOpenCLOptions().cl_khr_fp64)) { S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) << Result << "cl_khr_fp64"; Index: lib/Sema/SemaExpr.cpp === --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -716,9 +716,13 @@ if (getLangOpts().ObjCAutoRefCount && E->getType().getObjCLifetime() == Qualifiers::OCL_Weak) Cleanup.setExprNeedsCleanups(true); + + ExprResult Res = E; - ExprResult Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, -nullptr, VK_RValue); + if ( T != E->getType()) { +Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, + nullptr, VK_RValue); + } // C11 6.3.2.1p2: // ... if the lvalue has atomic type, the value has the non-atomic version @@ -828,8 +832,20 @@ // double. const BuiltinType *BTy = Ty->getAs(); if (BTy && (BTy->getKind() == BuiltinType::Half || - BTy->getKind() == BuiltinType::Float)) -E =
Re: [PATCH] D24235: [OpenCL] Improve double literal handling
neil.hickey added a comment. committed @ 281714 https://reviews.llvm.org/D24235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24235: [OpenCL] Improve double literal handling
neil.hickey closed this revision. neil.hickey added a comment. Commit merged to trunk https://reviews.llvm.org/D24235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24235: [OpenCL] Improve double literal handling
Anastasia accepted this revision. Anastasia added a comment. This revision is now accepted and ready to land. LGTM! Thanks! https://reviews.llvm.org/D24235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24235: [OpenCL] Improve double literal handling
neil.hickey added inline comments. Comment at: lib/Sema/SemaExpr.cpp:837 @@ +836,3 @@ + .getSupportedOpenCLOpts() + .cl_khr_fp64) || + getOpenCLOptions().cl_khr_fp64)) { Anastasia wrote: > Could we merge this and two lines above into one? This was the result when I ran this through clang-format so I'd rather keep it as it is. https://reviews.llvm.org/D24235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24235: [OpenCL] Improve double literal handling
Anastasia added inline comments. Comment at: lib/Sema/SemaExpr.cpp:832 @@ -831,2 +831,3 @@ BTy->getKind() == BuiltinType::Float)) -E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get(); + { +if (getLangOpts().OpenCL && This should go on the previous line. Comment at: lib/Sema/SemaExpr.cpp:837 @@ +836,3 @@ + .getSupportedOpenCLOpts() + .cl_khr_fp64) || + getOpenCLOptions().cl_khr_fp64)) { Could we merge this and two lines above into one? Comment at: lib/Sema/SemaExpr.cpp:840 @@ +839,3 @@ +E = ImpCastExprToType(E, Context.FloatTy, CK_FloatingCast).get(); +} +else I think the formatting is not right here. Could you change to: } else { Comment at: test/CodeGenOpenCL/fpmath.cl:28 @@ +27,3 @@ +void testdbllit(long *val) { + // CHECK-DBL: float 2.00e+01 + printf("%f", 20.0); Could you please add a check that double is generated in either CL2.0 or fp64 mode. https://reviews.llvm.org/D24235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24235: [OpenCL] Improve double literal handling
neil.hickey updated this revision to Diff 70527. neil.hickey added a comment. Added a CodeGen test as well as fixed an issue with vararg type promotion https://reviews.llvm.org/D24235 Files: lib/Sema/SemaExpr.cpp lib/Sema/SemaType.cpp test/CodeGenOpenCL/fpmath.cl test/SemaOpenCL/extensions.cl Index: test/SemaOpenCL/extensions.cl === --- test/SemaOpenCL/extensions.cl +++ test/SemaOpenCL/extensions.cl @@ -1,13 +1,16 @@ // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1 +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 -DFP64 // Test with a target not supporting fp64. // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 +#if __OPENCL_C_VERSION__ < 120 void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}} double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} (void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}} } +#endif #pragma OPENCL EXTENSION cl_khr_fp64 : enable #ifdef NOFP64 @@ -21,16 +24,22 @@ #endif (void) 1.0; +#ifdef FP64 +// expected-no-diagnostics +#endif + #ifdef NOFP64 -// expected-warning@-2{{double precision constant requires cl_khr_fp64, casting to single precision}} +// expected-warning@-6{{double precision constant requires cl_khr_fp64, casting to single precision}} #endif } #pragma OPENCL EXTENSION cl_khr_fp64 : disable #ifdef NOFP64 // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}} #endif +#if __OPENCL_C_VERSION__ < 120 void f3(void) { double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} } +#endif Index: test/CodeGenOpenCL/fpmath.cl === --- test/CodeGenOpenCL/fpmath.cl +++ test/CodeGenOpenCL/fpmath.cl @@ -1,5 +1,6 @@ // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck --check-prefix=CHECK --check-prefix=NODIVOPT %s // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown -cl-fp32-correctly-rounded-divide-sqrt | FileCheck --check-prefix=CHECK --check-prefix=DIVOPT %s +// RUN: %clang_cc1 %s -emit-llvm -o - -DNOFP64 -cl-std=CL1.1 -triple r600-unknown-unknown -target-cpu r600 -pedantic | FileCheck --check-prefix=CHECK-DBL %s typedef __attribute__(( ext_vector_type(4) )) float float4; @@ -21,14 +22,22 @@ return a / b; } -#pragma OPENCL EXTENSION cl_khr_fp64 : enable +void printf(constant char* fmt, ...); + +void testdbllit(long *val) { + // CHECK-DBL: float 2.00e+01 + printf("%f", 20.0); +} +#ifndef NOFP64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable double dpscalardiv(double a, double b) { // CHECK: @dpscalardiv // CHECK: #[[ATTR]] // CHECK-NOT: !fpmath return a / b; } +#endif // CHECK: attributes #[[ATTR]] = { // NODIVOPT: "correctly-rounded-divide-sqrt-fp-math"="false" Index: lib/Sema/SemaType.cpp === --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -1413,7 +1413,8 @@ Result = Context.DoubleTy; if (S.getLangOpts().OpenCL && -!((S.getLangOpts().OpenCLVersion >= 120) || +!((S.getLangOpts().OpenCLVersion >= 120 + && S.Context.getTargetInfo().getSupportedOpenCLOpts().cl_khr_fp64) || S.getOpenCLOptions().cl_khr_fp64)) { S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) << Result << "cl_khr_fp64"; Index: lib/Sema/SemaExpr.cpp === --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -829,7 +829,20 @@ const BuiltinType *BTy = Ty->getAs(); if (BTy && (BTy->getKind() == BuiltinType::Half || BTy->getKind() == BuiltinType::Float)) -E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get(); + { +if (getLangOpts().OpenCL && +!((getLangOpts().OpenCLVersion >= 120 && + Context.getTargetInfo() + .getSupportedOpenCLOpts() + .cl_khr_fp64) || + getOpenCLOptions().cl_khr_fp64)) { +E = ImpCastExprToType(E, Context.FloatTy, CK_FloatingCast).get(); +} +else +{ + E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get(); +} + } // C++ performs lvalue-to-rvalue conversion as a default argument // promotion, even on class types, but note: @@ -3406,8 +3419,14 @@ if (getLangOpts().SinglePrecisionConstants) { Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get(); } else if (getLangOpts().OpenCL && - !((getLangOpts().OpenCLVersion >= 120) || + !((getLangOpts().OpenCLVersion >=
Re: [PATCH] D24235: [OpenCL] Improve double literal handling
Anastasia added a comment. Could we add a CodeGen test as well to check that the constants generated are in the right precision format? https://reviews.llvm.org/D24235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits