1; RUN: opt -O3 -S -analyze -scalar-evolution < %s | FileCheck %s
2;
3; This file contains phase ordering tests for scalar evolution.
4; Test that the standard passes don't obfuscate the IR so scalar evolution can't
5; recognize expressions.
6
7; CHECK: test1
8; The loop body contains two increments by %div.
9; Make sure that 2*%div is recognizable, and not expressed as a bit mask of %d.
10; CHECK: -->  {%p,+,(8 * (%d /u 4))}
11define void @test1(i64 %d, i32* %p) nounwind uwtable ssp {
12entry:
13  %div = udiv i64 %d, 4
14  br label %for.cond
15
16for.cond:                                         ; preds = %for.inc, %entry
17  %p.addr.0 = phi i32* [ %p, %entry ], [ %add.ptr1, %for.inc ]
18  %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
19  %cmp = icmp ne i32 %i.0, 64
20  br i1 %cmp, label %for.body, label %for.end
21
22for.body:                                         ; preds = %for.cond
23  store i32 0, i32* %p.addr.0, align 4
24  %add.ptr = getelementptr inbounds i32, i32* %p.addr.0, i64 %div
25  store i32 1, i32* %add.ptr, align 4
26  %add.ptr1 = getelementptr inbounds i32, i32* %add.ptr, i64 %div
27  br label %for.inc
28
29for.inc:                                          ; preds = %for.body
30  %inc = add i32 %i.0, 1
31  br label %for.cond
32
33for.end:                                          ; preds = %for.cond
34  ret void
35}
36
37; CHECK: test1a
38; Same thing as test1, but it is even more tempting to fold 2 * (%d /u 2)
39; CHECK: -->  {%p,+,(8 * (%d /u 2))}
40define void @test1a(i64 %d, i32* %p) nounwind uwtable ssp {
41entry:
42  %div = udiv i64 %d, 2
43  br label %for.cond
44
45for.cond:                                         ; preds = %for.inc, %entry
46  %p.addr.0 = phi i32* [ %p, %entry ], [ %add.ptr1, %for.inc ]
47  %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
48  %cmp = icmp ne i32 %i.0, 64
49  br i1 %cmp, label %for.body, label %for.end
50
51for.body:                                         ; preds = %for.cond
52  store i32 0, i32* %p.addr.0, align 4
53  %add.ptr = getelementptr inbounds i32, i32* %p.addr.0, i64 %div
54  store i32 1, i32* %add.ptr, align 4
55  %add.ptr1 = getelementptr inbounds i32, i32* %add.ptr, i64 %div
56  br label %for.inc
57
58for.inc:                                          ; preds = %for.body
59  %inc = add i32 %i.0, 1
60  br label %for.cond
61
62for.end:                                          ; preds = %for.cond
63  ret void
64}
65