[LLVMdev] Interesting optimization failure.

Richard Pennington rich at pennware.com
Wed Jul 16 03:18:41 PDT 2008


Duncan Sands wrote:
> Hi Richard,
> 
>> I have been working on using arrays and structs as first class objects.
> 
> good to hear!  The example doesn't make use of that though, does it?
> 
>> I have this small function:
>>
>> int main()
>> {
>>      char ar[10] = "12";
>>      return ar[4];
>> }
> ...
>> define i32 @main() nounwind  {
>> entry:
>>          ret i32 49
>> }
>>
> 
> Here I get
> 
> define i32 @main() nounwind  {
> entry:
>         ret i32 0
> }
> 
> at -O1 and above.
> 
> Ciao,
> 
> Duncan.
> 

I think you're looking at the output of llvm-gcc or clang, I'm assuming 
your parser is performing the optimization before it gets to LLVM. My 
parser isn't quite that smart: I'm letting LLVM do all the hard work. ;-)

I think that the example is using arrays as first class objects, 
especially this:

          %ar = alloca [10 x i8]          ; <[10 x i8]*> [#uses=2]
          store [10 x i8] c"12\00\00\00\00\00\00\00\00", [10 x i8]* %ar

It's assigning an array constant to an array.

-Rich



More information about the llvm-dev mailing list