1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=i686-- | FileCheck %s
4 define i32 @t1(i8* %X, i32 %i) {
6 ; CHECK: # %bb.0: # %entry
7 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
8 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
9 ; CHECK-NEXT: movzbl %cl, %ecx
10 ; CHECK-NEXT: movl (%eax,%ecx,4), %eax
15 %tmp4 = and i32 %tmp2, 1020
16 %tmp7 = getelementptr i8, i8* %X, i32 %tmp4
17 %tmp78 = bitcast i8* %tmp7 to i32*
18 %tmp9 = load i32, i32* %tmp78
22 define i32 @t2(i16* %X, i32 %i) {
24 ; CHECK: # %bb.0: # %entry
25 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
26 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
27 ; CHECK-NEXT: movzwl %cx, %ecx
28 ; CHECK-NEXT: movl (%eax,%ecx,4), %eax
33 %tmp4 = and i32 %tmp2, 131070
34 %tmp7 = getelementptr i16, i16* %X, i32 %tmp4
35 %tmp78 = bitcast i16* %tmp7 to i32*
36 %tmp9 = load i32, i32* %tmp78
40 define i32 @t3(i16* %i.ptr, i32* %arr) {
41 ; This case is tricky. The lshr followed by a gep will produce a lshr followed
42 ; by an and to remove the low bits. This can be simplified by doing the lshr by
43 ; a greater constant and using the addressing mode to scale the result back up.
44 ; To make matters worse, because of the two-phase zext of %i and their reuse in
45 ; the function, the DAG can get confusing trying to re-use both of them and
46 ; prevent easy analysis of the mask in order to match this.
48 ; CHECK: # %bb.0: # %entry
49 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
50 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
51 ; CHECK-NEXT: movzwl (%eax), %eax
52 ; CHECK-NEXT: movl %eax, %edx
53 ; CHECK-NEXT: shrl $11, %edx
54 ; CHECK-NEXT: addl (%ecx,%edx,4), %eax
58 %i = load i16, i16* %i.ptr
59 %i.zext = zext i16 %i to i32
60 %index = lshr i32 %i.zext, 11
61 %val.ptr = getelementptr inbounds i32, i32* %arr, i32 %index
62 %val = load i32, i32* %val.ptr
63 %sum = add i32 %val, %i.zext
67 define i32 @t4(i16* %i.ptr, i32* %arr) {
68 ; A version of @t3 that has more zero extends and more re-use of intermediate
69 ; values. This exercise slightly different bits of canonicalization.
71 ; CHECK: # %bb.0: # %entry
72 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
73 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
74 ; CHECK-NEXT: movzwl (%eax), %eax
75 ; CHECK-NEXT: movl %eax, %edx
76 ; CHECK-NEXT: shrl $11, %edx
77 ; CHECK-NEXT: addl (%ecx,%edx,4), %eax
78 ; CHECK-NEXT: addl %edx, %eax
82 %i = load i16, i16* %i.ptr
83 %i.zext = zext i16 %i to i32
84 %index = lshr i32 %i.zext, 11
85 %index.zext = zext i32 %index to i64
86 %val.ptr = getelementptr inbounds i32, i32* %arr, i64 %index.zext
87 %val = load i32, i32* %val.ptr
88 %sum.1 = add i32 %val, %i.zext
89 %sum.2 = add i32 %sum.1, %index
93 define i8 @t5(i8* %X, i32 %i) {
95 ; CHECK: # %bb.0: # %entry
96 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
97 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
98 ; CHECK-NEXT: andl $-14, %ecx
99 ; CHECK-NEXT: movb (%eax,%ecx,4), %al
103 %tmp2 = shl i32 %i, 2
104 %tmp4 = and i32 %tmp2, -56
105 %tmp7 = getelementptr i8, i8* %X, i32 %tmp4
106 %tmp9 = load i8, i8* %tmp7
110 define i8 @t6(i8* %X, i32 %i) {
112 ; CHECK: # %bb.0: # %entry
113 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
114 ; CHECK-NEXT: movl $-255, %ecx
115 ; CHECK-NEXT: andl {{[0-9]+}}(%esp), %ecx
116 ; CHECK-NEXT: movb (%eax,%ecx,4), %al
120 %tmp2 = shl i32 %i, 2
121 %tmp4 = and i32 %tmp2, -1020
122 %tmp7 = getelementptr i8, i8* %X, i32 %tmp4
123 %tmp9 = load i8, i8* %tmp7