New testcase
[oota-llvm.git] / test / LLC / constindices.ll
1 ; Test that a sequence of constant indices are folded correctly
2 ; into the equivalent offset at compile-time.
3
4 %MixedA = type { float, [15 x int], sbyte, float }
5
6 %MixedB = type { float, %MixedA, float }
7
8 %fmtArg = internal global [44 x sbyte] c"sqrt(2) = %g\0Aexp(1) = %g\0Api = %g\0Afive = %g\0A\00"; <[44 x sbyte]*> [#uses=1]
9
10 implementation
11
12 declare int "printf"(sbyte*, ...)
13
14 int "main"()
15 begin
16         %ScalarA = alloca %MixedA
17         %ScalarB = alloca %MixedB
18         %ArrayA  = alloca %MixedA, uint 4
19         %ArrayB  = alloca %MixedB, uint 3
20
21         %I1 = getelementptr %MixedA* %ScalarA, uint 0, ubyte 0  
22         store float 1.4142, float *%I1
23         %I2 = getelementptr %MixedB* %ScalarB, uint 0, ubyte 1, ubyte 0 
24         store float 2.7183, float *%I2
25         
26         %fptrA = getelementptr %MixedA* %ArrayA, uint 1, ubyte 0 
27         %fptrB = getelementptr %MixedB* %ArrayB, uint 2, ubyte 1, ubyte 0 
28         
29         store float 3.1415, float* %fptrA
30         store float 5.0,    float* %fptrB
31         
32         ;; Test that a sequence of GEPs with constant indices are folded right
33         %fptrA1 = getelementptr %MixedA* %ArrayA, uint 3          ; &ArrayA[3]
34         %fptrA2 = getelementptr %MixedA* %fptrA1, uint 0, ubyte 1 ; &(*fptrA1).1
35         %fptrA3 = getelementptr [15 x int]* %fptrA2, uint 0, uint 8 ; &(*fptrA2)[8]
36         store int 5, int* %fptrA3       ; ArrayA[3].1[8] = 5
37
38         %sqrtTwo = load float *%I1
39         %exp     = load float *%I2
40         %I3 = getelementptr %MixedA* %ArrayA, uint 1, ubyte 0 
41         %pi      = load float* %I3
42         %I4 = getelementptr %MixedB* %ArrayB, uint 2, ubyte 1, ubyte 0  
43         %five    = load float* %I4
44                  
45         %dsqrtTwo = cast float %sqrtTwo to double
46         %dexp     = cast float %exp to double
47         %dpi      = cast float %pi to double
48         %dfive    = cast float %five to double
49                   
50         %castFmt = getelementptr [44 x sbyte]* %fmtArg, uint 0, uint 0
51         call int (sbyte*, ...)* %printf(sbyte* %castFmt, double %dsqrtTwo, double %dexp, double %dpi, double %dfive)
52         
53         ret int 0
54 end