7fb19a6cad056c3fb699bb472e2c26617a2e6900
[oota-llvm.git] / test / CodeGen / X86 / shift-combine.ll
1 ; RUN: llc -march=x86 < %s | FileCheck %s
2
3 @array = weak global [4 x i32] zeroinitializer
4
5 define i32 @test_lshr_and(i32 %x) {
6 ; CHECK-LABEL: test_lshr_and:
7 ; CHECK-NOT: shrl
8 ; CHECK: andl $12,
9 ; CHECK: movl {{.*}}array{{.*}},
10 ; CHECK: ret
11
12 entry:
13   %tmp2 = lshr i32 %x, 2
14   %tmp3 = and i32 %tmp2, 3
15   %tmp4 = getelementptr [4 x i32], [4 x i32]* @array, i32 0, i32 %tmp3
16   %tmp5 = load i32, i32* %tmp4, align 4
17   ret i32 %tmp5
18 }
19
20 define i32* @test_exact1(i32 %a, i32 %b, i32* %x)  {
21 ; CHECK-LABEL: test_exact1:
22 ; CHECK: sarl %
23
24   %sub = sub i32 %b, %a
25   %shr = ashr exact i32 %sub, 3
26   %gep = getelementptr inbounds i32, i32* %x, i32 %shr
27   ret i32* %gep
28 }
29
30 define i32* @test_exact2(i32 %a, i32 %b, i32* %x)  {
31 ; CHECK-LABEL: test_exact2:
32 ; CHECK: sarl %
33
34   %sub = sub i32 %b, %a
35   %shr = ashr exact i32 %sub, 3
36   %gep = getelementptr inbounds i32, i32* %x, i32 %shr
37   ret i32* %gep
38 }
39
40 define i32* @test_exact4(i32 %a, i32 %b, i32* %x)  {
41 ; CHECK-LABEL: test_exact4:
42 ; CHECK: shrl %
43
44   %sub = sub i32 %b, %a
45   %shr = lshr exact i32 %sub, 3
46   %gep = getelementptr inbounds i32, i32* %x, i32 %shr
47   ret i32* %gep
48 }
49
50 define i32* @test_exact5(i32 %a, i32 %b, i32* %x)  {
51 ; CHECK-LABEL: test_exact5:
52 ; CHECK: shrl %
53
54   %sub = sub i32 %b, %a
55   %shr = lshr exact i32 %sub, 3
56   %gep = getelementptr inbounds i32, i32* %x, i32 %shr
57   ret i32* %gep
58 }
59
60 define i32* @test_exact6(i32 %a, i32 %b, i32* %x)  {
61 ; CHECK-LABEL: test_exact6:
62 ; CHECK-NOT: shrl
63
64   %sub = sub i32 %b, %a
65   %shr = lshr exact i32 %sub, 2
66   %gep = getelementptr inbounds i32, i32* %x, i32 %shr
67   ret i32* %gep
68 }