xref: /llvm-project/llvm/test/CodeGen/X86/loop-strength-reduce4.ll (revision eecb99c5f66c8491766628a2925587e20f3b1dbd)
1; RUN: llc < %s -mtriple=i686-apple-darwin -relocation-model=static | FileCheck %s -check-prefix=STATIC
2; RUN: llc < %s -mtriple=i686-apple-darwin -relocation-model=pic | FileCheck %s -check-prefix=PIC
3
4; By starting the IV at -64 instead of 0, a cmp is eliminated,
5; as the flags from the add can be used directly.
6
7; STATIC: movl    $-64, [[EAX:%e..]]
8
9; STATIC: movl    %{{.+}}, _state+76([[EAX]])
10; STATIC: addl    $16, [[EAX]]
11; STATIC: jne
12
13; The same for PIC mode.
14
15; PIC: movl    $-64, [[EAX:%e..]]
16
17; PIC: movl    %{{.+}}, 76(%{{.+}},[[EAX]])
18; PIC: addl    $16, [[EAX]]
19; PIC: jne
20
21@state = external global [0 x i32]		; <ptr> [#uses=4]
22@S = external global [0 x i32]		; <ptr> [#uses=4]
23
24define i32 @foo() nounwind {
25entry:
26	br label %bb
27
28bb:		; preds = %bb, %entry
29	%indvar = phi i32 [ 0, %entry ], [ %indvar.next, %bb ]		; <i32> [#uses=2]
30	%t.063.0 = phi i32 [ 0, %entry ], [ %tmp47, %bb ]		; <i32> [#uses=1]
31	%j.065.0 = shl i32 %indvar, 2		; <i32> [#uses=4]
32	%tmp3 = getelementptr [0 x i32], ptr @state, i32 0, i32 %j.065.0		; <ptr> [#uses=2]
33	%tmp4 = load i32, ptr %tmp3, align 4		; <i32> [#uses=1]
34	%tmp6 = getelementptr [0 x i32], ptr @S, i32 0, i32 %t.063.0		; <ptr> [#uses=1]
35	%tmp7 = load i32, ptr %tmp6, align 4		; <i32> [#uses=1]
36	%tmp8 = xor i32 %tmp7, %tmp4		; <i32> [#uses=2]
37	store i32 %tmp8, ptr %tmp3, align 4
38	%tmp1378 = or disjoint i32 %j.065.0, 1		; <i32> [#uses=1]
39	%tmp16 = getelementptr [0 x i32], ptr @state, i32 0, i32 %tmp1378		; <ptr> [#uses=2]
40	%tmp17 = load i32, ptr %tmp16, align 4		; <i32> [#uses=1]
41	%tmp19 = getelementptr [0 x i32], ptr @S, i32 0, i32 %tmp8		; <ptr> [#uses=1]
42	%tmp20 = load i32, ptr %tmp19, align 4		; <i32> [#uses=1]
43	%tmp21 = xor i32 %tmp20, %tmp17		; <i32> [#uses=2]
44	store i32 %tmp21, ptr %tmp16, align 4
45	%tmp2680 = or disjoint i32 %j.065.0, 2		; <i32> [#uses=1]
46	%tmp29 = getelementptr [0 x i32], ptr @state, i32 0, i32 %tmp2680		; <ptr> [#uses=2]
47	%tmp30 = load i32, ptr %tmp29, align 4		; <i32> [#uses=1]
48	%tmp32 = getelementptr [0 x i32], ptr @S, i32 0, i32 %tmp21		; <ptr> [#uses=1]
49	%tmp33 = load i32, ptr %tmp32, align 4		; <i32> [#uses=1]
50	%tmp34 = xor i32 %tmp33, %tmp30		; <i32> [#uses=2]
51	store i32 %tmp34, ptr %tmp29, align 4
52	%tmp3982 = or disjoint i32 %j.065.0, 3		; <i32> [#uses=1]
53	%tmp42 = getelementptr [0 x i32], ptr @state, i32 0, i32 %tmp3982		; <ptr> [#uses=2]
54	%tmp43 = load i32, ptr %tmp42, align 4		; <i32> [#uses=1]
55	%tmp45 = getelementptr [0 x i32], ptr @S, i32 0, i32 %tmp34		; <ptr> [#uses=1]
56	%tmp46 = load i32, ptr %tmp45, align 4		; <i32> [#uses=1]
57	%tmp47 = xor i32 %tmp46, %tmp43		; <i32> [#uses=3]
58	store i32 %tmp47, ptr %tmp42, align 4
59	%indvar.next = add i32 %indvar, 1		; <i32> [#uses=2]
60	%exitcond = icmp eq i32 %indvar.next, 4		; <i1> [#uses=1]
61	br i1 %exitcond, label %bb57, label %bb
62
63bb57:		; preds = %bb
64	%tmp59 = and i32 %tmp47, 255		; <i32> [#uses=1]
65	ret i32 %tmp59
66}
67