blob: 637d72d65350d1e1bf8e84e841a7f3eb6e5af7b7 [file] [log] [blame]
Tanya Lattner2393a242004-11-06 23:08:26 +00001; RUN: llvm-as -f %s -o - | llc
2
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +00003; Test that a sequence of constant indices are folded correctly
4; into the equivalent offset at compile-time.
5
6%MixedA = type { float, [15 x int], sbyte, float }
7
8%MixedB = type { float, %MixedA, float }
9
10%fmtArg = internal global [44 x sbyte] c"sqrt(2) = %g\0Aexp(1) = %g\0Api = %g\0Afive = %g\0A\00"; <[44 x sbyte]*> [#uses=1]
11
12implementation
13
14declare int "printf"(sbyte*, ...)
15
16int "main"()
17begin
18 %ScalarA = alloca %MixedA
19 %ScalarB = alloca %MixedB
20 %ArrayA = alloca %MixedA, uint 4
21 %ArrayB = alloca %MixedB, uint 3
Chris Lattner236c4a32002-08-21 22:44:39 +000022
Chris Lattner30e2d912003-09-09 18:14:37 +000023 %I1 = getelementptr %MixedA* %ScalarA, long 0, ubyte 0
Chris Lattner236c4a32002-08-21 22:44:39 +000024 store float 1.4142, float *%I1
Chris Lattner30e2d912003-09-09 18:14:37 +000025 %I2 = getelementptr %MixedB* %ScalarB, long 0, ubyte 1, ubyte 0
Chris Lattner236c4a32002-08-21 22:44:39 +000026 store float 2.7183, float *%I2
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +000027
Chris Lattner30e2d912003-09-09 18:14:37 +000028 %fptrA = getelementptr %MixedA* %ArrayA, long 1, ubyte 0
29 %fptrB = getelementptr %MixedB* %ArrayB, long 2, ubyte 1, ubyte 0
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +000030
31 store float 3.1415, float* %fptrA
32 store float 5.0, float* %fptrB
33
Vikram S. Adve7894d562002-08-04 20:53:14 +000034 ;; Test that a sequence of GEPs with constant indices are folded right
Chris Lattner30e2d912003-09-09 18:14:37 +000035 %fptrA1 = getelementptr %MixedA* %ArrayA, long 3 ; &ArrayA[3]
36 %fptrA2 = getelementptr %MixedA* %fptrA1, long 0, ubyte 1 ; &(*fptrA1).1
37 %fptrA3 = getelementptr [15 x int]* %fptrA2, long 0, long 8 ; &(*fptrA2)[8]
Vikram S. Adve7894d562002-08-04 20:53:14 +000038 store int 5, int* %fptrA3 ; ArrayA[3].1[8] = 5
39
Chris Lattner236c4a32002-08-21 22:44:39 +000040 %sqrtTwo = load float *%I1
41 %exp = load float *%I2
Chris Lattner30e2d912003-09-09 18:14:37 +000042 %I3 = getelementptr %MixedA* %ArrayA, long 1, ubyte 0
Chris Lattner236c4a32002-08-21 22:44:39 +000043 %pi = load float* %I3
Chris Lattner30e2d912003-09-09 18:14:37 +000044 %I4 = getelementptr %MixedB* %ArrayB, long 2, ubyte 1, ubyte 0
Chris Lattner236c4a32002-08-21 22:44:39 +000045 %five = load float* %I4
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +000046
47 %dsqrtTwo = cast float %sqrtTwo to double
48 %dexp = cast float %exp to double
49 %dpi = cast float %pi to double
50 %dfive = cast float %five to double
51
Chris Lattner30e2d912003-09-09 18:14:37 +000052 %castFmt = getelementptr [44 x sbyte]* %fmtArg, long 0, long 0
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +000053 call int (sbyte*, ...)* %printf(sbyte* %castFmt, double %dsqrtTwo, double %dexp, double %dpi, double %dfive)
54
55 ret int 0
56end