Pointer arithmetic should be done with the index the same size as the pointer.
[oota-llvm.git] / test / CodeGen / X86 / packed_struct.ll
1 ; RUN: llvm-upgrade < %s | llvm-as | llc -march=x86 | grep foos+5
2 ; RUN: llvm-upgrade < %s | llvm-as | llc -march=x86 | grep foos+1
3 ; RUN: llvm-upgrade < %s | llvm-as | llc -march=x86 | grep foos+9
4 ; RUN: llvm-upgrade < %s | llvm-as | llc -march=x86 | grep bara+19
5 ; RUN: llvm-upgrade < %s | llvm-as | llc -march=x86 | grep bara+4
6
7 ; make sure we compute the correct offset for a packed structure
8
9 ;Note: codegen for this could change rendering the above checks wrong
10
11 ; ModuleID = 'foo.c'
12 target datalayout = "e-p:32:32"
13 target endian = little
14 target pointersize = 32
15 target triple = "i686-pc-linux-gnu"
16         %struct.anon = type <{ sbyte, int, int, int }>
17 %foos = external global %struct.anon
18 %bara = weak global [4 x <{ int, sbyte }>] zeroinitializer
19
20 implementation   ; Functions:
21
22 int %foo() {
23 entry:
24         %tmp = load int*  getelementptr (%struct.anon* %foos, int 0, uint 1)
25         %tmp3 = load int* getelementptr (%struct.anon* %foos, int 0, uint 2)
26         %tmp6 = load int* getelementptr (%struct.anon* %foos, int 0, uint 3)
27         %tmp4 = add int %tmp3, %tmp
28         %tmp7 = add int %tmp4, %tmp6
29         ret int %tmp7
30 }
31
32 sbyte %bar() {
33 entry:
34         %tmp = load sbyte* getelementptr([4 x <{ int, sbyte }>]* %bara, int 0, int 0, uint 1 )
35         %tmp4 = load sbyte* getelementptr ([4 x <{ int, sbyte }>]* %bara, int 0, int 3, uint 1)
36         %tmp5 = add sbyte %tmp4, %tmp
37         ret sbyte %tmp5
38 }