1 ; RUN: opt -O3 -S -analyze -scalar-evolution < %s | FileCheck %s
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.
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,+,(2 * (%d /u 4) * sizeof(i32))}
11 define void @test1(i64 %d, i32* %p) nounwind uwtable ssp {
16 for.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
22 for.body: ; preds = %for.cond
23 store i32 0, i32* %p.addr.0, align 4
24 %add.ptr = getelementptr inbounds i32* %p.addr.0, i64 %div
25 store i32 1, i32* %add.ptr, align 4
26 %add.ptr1 = getelementptr inbounds i32* %add.ptr, i64 %div
29 for.inc: ; preds = %for.body
30 %inc = add i32 %i.0, 1
33 for.end: ; preds = %for.cond
38 ; Same thing as test1, but it is even more tempting to fold 2 * (%d /u 2)
39 ; CHECK: --> {%p,+,(2 * (%d /u 2) * sizeof(i32))}
40 define void @test1a(i64 %d, i32* %p) nounwind uwtable ssp {
45 for.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
51 for.body: ; preds = %for.cond
52 store i32 0, i32* %p.addr.0, align 4
53 %add.ptr = getelementptr inbounds i32* %p.addr.0, i64 %div
54 store i32 1, i32* %add.ptr, align 4
55 %add.ptr1 = getelementptr inbounds i32* %add.ptr, i64 %div
58 for.inc: ; preds = %for.body
59 %inc = add i32 %i.0, 1
62 for.end: ; preds = %for.cond