1 ; RUN: opt -passes='default<O3>,print<scalar-evolution>' -S < %s 2>&1 | FileCheck %s
3 target datalayout = "e-m:m-p:40:64:64:32-i32:32-i16:16-i8:8-n32"
6 ; This file contains phase ordering tests for scalar evolution.
7 ; Test that the standard passes don't obfuscate the IR so scalar evolution can't
8 ; recognize expressions.
11 ; The loop body contains two increments by %div.
12 ; Make sure that 2*%div is recognizable, and not expressed as a bit mask of %d.
13 ; CHECK: --> {%p,+,(8 * (%d /u 4))}
14 define void @test1(i32 %d, ptr %p) nounwind uwtable ssp {
19 for.cond: ; preds = %for.inc, %entry
20 %p.addr.0 = phi ptr [ %p, %entry ], [ %add.ptr1, %for.inc ]
21 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
22 %cmp = icmp ne i32 %i.0, 64
23 br i1 %cmp, label %for.body, label %for.end
25 for.body: ; preds = %for.cond
26 store i32 0, ptr %p.addr.0, align 4
27 %add.ptr = getelementptr inbounds i32, ptr %p.addr.0, i32 %div
28 store i32 1, ptr %add.ptr, align 4
29 %add.ptr1 = getelementptr inbounds i32, ptr %add.ptr, i32 %div
32 for.inc: ; preds = %for.body
33 %inc = add i32 %i.0, 1
36 for.end: ; preds = %for.cond
41 ; Same thing as test1, but it is even more tempting to fold 2 * (%d /u 2)
42 ; CHECK: --> {%p,+,(8 * (%d /u 2))}
43 define void @test1a(i32 %d, ptr %p) nounwind uwtable ssp {
48 for.cond: ; preds = %for.inc, %entry
49 %p.addr.0 = phi ptr [ %p, %entry ], [ %add.ptr1, %for.inc ]
50 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
51 %cmp = icmp ne i32 %i.0, 64
52 br i1 %cmp, label %for.body, label %for.end
54 for.body: ; preds = %for.cond
55 store i32 0, ptr %p.addr.0, align 4
56 %add.ptr = getelementptr inbounds i32, ptr %p.addr.0, i32 %div
57 store i32 1, ptr %add.ptr, align 4
58 %add.ptr1 = getelementptr inbounds i32, ptr %add.ptr, i32 %div
61 for.inc: ; preds = %for.body
62 %inc = add i32 %i.0, 1
65 for.end: ; preds = %for.cond
69 @array = weak global [101 x i32] zeroinitializer, align 32 ; <ptr> [#uses=1]
71 ; CHECK: Loop %bb: backedge-taken count is 100
73 define void @test_range_ref1a(i32 %x) {
77 bb: ; preds = %bb, %entry
78 %i.01.0 = phi i32 [ 100, %entry ], [ %tmp4, %bb ] ; <i32> [#uses=2]
79 %tmp1 = getelementptr [101 x i32], ptr @array, i32 0, i32 %i.01.0 ; <ptr> [#uses=1]
80 store i32 %x, ptr %tmp1
81 %tmp4 = add i32 %i.01.0, -1 ; <i32> [#uses=2]
82 %tmp7 = icmp sgt i32 %tmp4, -1 ; <i1> [#uses=1]
83 br i1 %tmp7, label %bb, label %return
89 define i32 @test_loop_idiom_recogize(i32 %x, i32 %y, ptr %lam, ptr %alp) nounwind {
93 bb1: ; preds = %bb1, %bb1.thread
94 %indvar = phi i32 [ 0, %bb1.thread ], [ %indvar.next, %bb1 ] ; <i32> [#uses=4]
95 %i.0.reg2mem.0 = sub i32 255, %indvar ; <i32> [#uses=2]
96 %0 = getelementptr i32, ptr %alp, i32 %i.0.reg2mem.0 ; <ptr> [#uses=1]
97 %1 = load i32, ptr %0, align 4 ; <i32> [#uses=1]
98 %2 = getelementptr i32, ptr %lam, i32 %i.0.reg2mem.0 ; <ptr> [#uses=1]
99 store i32 %1, ptr %2, align 4
100 %3 = sub i32 254, %indvar ; <i32> [#uses=1]
101 %4 = icmp slt i32 %3, 0 ; <i1> [#uses=1]
102 %indvar.next = add i32 %indvar, 1 ; <i32> [#uses=1]
103 br i1 %4, label %bb2, label %bb1
106 %tmp10 = mul i32 %indvar, %x ; <i32> [#uses=1]
107 %z.0.reg2mem.0 = add i32 %tmp10, %y ; <i32> [#uses=1]
108 %5 = add i32 %z.0.reg2mem.0, %x ; <i32> [#uses=1]
112 declare void @use(i1)
114 declare void @llvm.experimental.guard(i1, ...)
116 ; This tests getRangeRef acts as intended with different idx size.
117 ; CHECK: Loop %loop: Unpredictable constant max backedge-taken count.
118 define void @test_range_ref1(i8 %t) {
120 %t.ptr = inttoptr i8 %t to ptr
121 %p.42 = inttoptr i8 42 to ptr
122 %cmp1 = icmp slt ptr %t.ptr, %p.42
123 call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
127 %idx = phi ptr [ %t.ptr, %entry ], [ %snext, %loop ]
128 %snext = getelementptr inbounds i8, ptr %idx, i64 1
129 %c = icmp slt ptr %idx, %p.42
130 call void @use(i1 %c)
131 %be = icmp slt ptr %snext, %p.42
132 br i1 %be, label %loop, label %exit