[cfe-dev] [PATCH] [OpenCL] Conversions for ternary operations between scalar and vector

Sahasrabuddhe, Sameer sameer.sahasrabuddhe at amd.com
Tue Dec 16 21:46:41 PST 2014


On 12/17/2014 10:14 AM, Sahasrabuddhe, Sameer wrote:
> > diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
> > index 04497f3..e37e0c5 100644
> > --- a/lib/Sema/SemaExpr.cpp
> > +++ b/lib/Sema/SemaExpr.cpp
> > @@ -5817,13 +5817,27 @@ QualType 
> Sema::CheckConditionalOperands(ExprResult &Cond, ExprResult &LHS,
> >    QualType LHSTy = LHS.get()->getType();
> >    QualType RHSTy = RHS.get()->getType();
> >
> > -  // If the condition is a vector, and both operands are scalar,
> > -  // attempt to implicity convert them to the vector type to act 
> like the
> > -  // built in select. (OpenCL v1.1 s6.3.i)
> > -  if (getLangOpts().OpenCL && CondTy->isVectorType())
> > -    if (checkConditionalConvertScalarsToVectors(*this, LHS, RHS, 
> CondTy))
> > -      return QualType();
> > -
> > +  if (getLangOpts().OpenCL) {
> > +    if (CondTy->isVectorType()){
> > +      if 
> (CondTy->getAs<VectorType>()->getElementType()->isFloatingType())
>
> This needs to be checked for the scalar operator too.
>
> > +        Diag(Cond.get()->getLocStart(), 
> diag::err_use_of_float_ternary_cond)
> > +            << CondTy;
> > +      if (LHSTy != RHSTy){
> > +        if (LHSTy->isVectorType() && RHSTy->isScalarType())
> > +          RHS = ImpCastExprToType(RHS.get(), LHSTy, CK_IntegralCast);
> > +        else if (LHSTy->isScalarType() && RHSTy->isVectorType())
> > +          LHS = ImpCastExprToType(LHS.get(), RHSTy, CK_IntegralCast);
> > +      }
>
> This should be moved to the function 
> "Sema::UsualArithmeticConversions" in the same file. That function 
> implements C99, but needs to be enhanced for Section 6.2.6 from OpenCL 
> 1.2 spec, which provides additional conversion rules for vector 
> operands. Once we have that, we don't need to worry about LHS and RHS; 
> instead, we just use ResTy which is computed just before the current 
> point in the code.

I made a mistake in reading the code. The vector/scalar conversions are 
already handled by CheckVectorOperands, which is called just before 
calling UsualArithmeticConversions. But the current code is immediately 
returning from there ... instead it should update ResTy and continue 
with further checks.

Sameer.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141217/9a2a830a/attachment.html>


More information about the cfe-dev mailing list