[cfe-commits] r74299 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/Sema/ext_vector_components.c

Nate Begeman natebegeman at mac.com
Sat Jun 27 15:25:12 PDT 2009


On Jun 26, 2009, at 5:17 PM, Eli Friedman wrote:

> On Fri, Jun 26, 2009 at 11:22 AM, Nate Begeman<natebegeman at mac.com>  
> wrote:
>> -  // Check for vector->vector bitcast.
>> -  if (SE->getType()->isVectorType())
>> +  // Check for vector->vector bitcast and scalar->vector splat.
>> +  if (SETy->isVectorType()) {
>>     return this->Visit(const_cast<Expr*>(SE));
>> +  } else if (SETy->isIntegerType()) {
>> +    APSInt IntResult;
>> +    if (EvaluateInteger(SE, IntResult, Info))
>> +      Result = APValue(IntResult);
>> +  } else if (SETy->isRealFloatingType()) {
>> +    APFloat F(0.0);
>> +    if (EvaluateFloat(SE, F, Info))
>> +      Result = APValue(F);
>> +  }
>>
>> -  return APValue();
>> +  if (Result.isInt() || Result.isFloat()) {
>> +    unsigned NumElts = E->getType()->getAsVectorType()- 
>> >getNumElements();
>> +    llvm::SmallVector<APValue, 4> Elts(NumElts, Result);
>> +    Result = APValue(&Elts[0], Elts.size());
>> +  }
>> +  return Result;
>>  }
>
> This code looks a little suspicious; does it handle stuff like "v2f32
> x = (v2f32)4LL;" correctly?

It should bit-convert 4LL to v2f32 when not targeting OpenCL (to  
maintain gcc compatibility, although i don't know if gcc considers  
that a constant expression or not, will try it out), and create a  
vector of {4.0f, 4.0f} for OpenCL.  I'll update the code to handle  
that.  Lemme know if you have other ideas :)

Thanks,
Nate



More information about the cfe-commits mailing list