[LLVMdev] Question about documentation of BitCast CExps.

Nick Lewycky nicholas at mxc.ca
Sat Feb 28 11:13:12 PST 2009


Nick Lewycky wrote:
> Jesper Louis Andersen wrote:
>> In the documentation at [http://llvm.org/docs/LangRef.html], we have
>> the section [#aggregateconstants] telling us that the aggregate
>> constants are:
>>
>>   * Structure constants
>>   * Array constants
>>   * Vector constants
>>   * Zeroinitialization
>>
>> However, in [#constantexprs] we have a bitcast(CST, TYPE) operator
>> with the documentation (emphasis by me):
>>
>> Convert a constant, CST, to another TYPE. The size of CST and TYPE
>> must be identical (same number of bits). The conversion is done as if
>> the CST value was stored to memory and read back as TYPE. In other
>> words, no bits change with this operator, just the type. {{{This can
>> be used for conversion of vector types to any other type, as long as
>> they have the same bit width}}}. For pointers it is only valid to cast
>> to another pointer type. {{{It is not valid to bitcast to or from an
>> aggregate type.}}}
> 
> Thanks for the report. I've updated this text to read:
> 
> "Convert a constant, CST, to another TYPE. The size of CST and TYPE must 
> be identical (same number of bits). The conversion is done as if the CST 
> value was stored to memory and read back as TYPE. In other words, no 
> bits change with this operator, just the type.  This can be used for 
> conversion of aggregate types to any aggregate type, as long as they 
> have the same bit width. Vector types may also be casted to and from any 
> other type as long as they have the same bit width. For pointers it is 
> only valid to cast to another pointer type."
> 
> This should make it clear that aggregates may be bitcasted to other 
> aggregates, and that additionally vectors may be bitcasted to and from 
> other types, but not pointers or labels or functions or void, because 
> those will never have the same width as a vector (tricky!).

Just to follow up on myself, Chris has gone ahead and removed this text 
from the LangRef and over IRC informed me that I was mistaken.

The fact that we accepted aggregate to aggregate bitcasts was a bug, not 
a deliberate feature of the IR. Those are still invalid, and we should 
update the verifier to catch them.

Nick

> Nick
> 
>> The first emphasis states that it is possible to use the bitcast
>> operation for conversion of vector types. However, the second emphasis
>> says that this is not valid (A vector is an aggregate type). So my
>> questions are:
>>
>> What is right?
>> Is this a mistake?
>> Am I reading this wrong in any way? If so, where?
>>
>> The reason I am asking is because I am in the process of implementing
>> a rudimentary type-checker phase for LLVM in Standard ML. It is mostly
>> done because it is a tremendous way to learn about the finer details
>> of the language. I am forced to think and know details about LLVM
>> because of the process, so hence my question.
>>
> 
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> 




More information about the llvm-dev mailing list