blob: 843fb073087c65b70fdfd23da2162a6c63a3d089 [file] [log] [blame]
Dan Gohman4ee87392010-08-11 00:12:36 +00001; RUN: opt < %s -analyze -scalar-evolution | FileCheck %s
Dan Gohman7a7be362009-08-19 23:19:36 +00002
3; ScalarEvolution should be able to understand the loop and eliminate the casts.
Dan Gohmana1af7572009-04-30 20:47:05 +00004
Dan Gohman4ee87392010-08-11 00:12:36 +00005; CHECK: {%d,+,sizeof(i32)}
6
Dan Gohmana1af7572009-04-30 20:47:05 +00007define void @foo(i32* nocapture %d, i32 %n) nounwind {
8entry:
9 %0 = icmp sgt i32 %n, 0 ; <i1> [#uses=1]
10 br i1 %0, label %bb.nph, label %return
11
12bb.nph: ; preds = %entry
13 br label %bb
14
15bb: ; preds = %bb1, %bb.nph
16 %i.02 = phi i32 [ %5, %bb1 ], [ 0, %bb.nph ] ; <i32> [#uses=2]
17 %p.01 = phi i8 [ %4, %bb1 ], [ -1, %bb.nph ] ; <i8> [#uses=2]
18 %1 = sext i8 %p.01 to i32 ; <i32> [#uses=1]
19 %2 = sext i32 %i.02 to i64 ; <i64> [#uses=1]
20 %3 = getelementptr i32* %d, i64 %2 ; <i32*> [#uses=1]
21 store i32 %1, i32* %3, align 4
22 %4 = add i8 %p.01, 1 ; <i8> [#uses=1]
23 %5 = add i32 %i.02, 1 ; <i32> [#uses=2]
24 br label %bb1
25
26bb1: ; preds = %bb
27 %6 = icmp slt i32 %5, %n ; <i1> [#uses=1]
28 br i1 %6, label %bb, label %bb1.return_crit_edge
29
30bb1.return_crit_edge: ; preds = %bb1
31 br label %return
32
33return: ; preds = %bb1.return_crit_edge, %entry
34 ret void
35}
Dan Gohman4ee87392010-08-11 00:12:36 +000036
37; ScalarEvolution should be able to find the maximum tripcount
38; of this multiple-exit loop, and if it doesn't know the exact
39; count, it should say so.
40
41; PR7845
42; CHECK: Loop %for.cond: <multiple exits> Unpredictable backedge-taken count.
43; CHECK: Loop %for.cond: max backedge-taken count is 5
44
45@.str = private constant [4 x i8] c"%d\0A\00" ; <[4 x i8]*> [#uses=2]
46
47define i32 @main() nounwind {
48entry:
49 br label %for.cond
50
51for.cond: ; preds = %for.inc, %entry
52 %g_4.0 = phi i32 [ 0, %entry ], [ %add, %for.inc ] ; <i32> [#uses=5]
53 %cmp = icmp slt i32 %g_4.0, 5 ; <i1> [#uses=1]
54 br i1 %cmp, label %for.body, label %for.end
55
56for.body: ; preds = %for.cond
57 %conv = trunc i32 %g_4.0 to i16 ; <i16> [#uses=1]
58 %tobool.not = icmp eq i16 %conv, 0 ; <i1> [#uses=1]
59 %tobool3 = icmp ne i32 %g_4.0, 0 ; <i1> [#uses=1]
60 %or.cond = and i1 %tobool.not, %tobool3 ; <i1> [#uses=1]
61 br i1 %or.cond, label %for.end, label %for.inc
62
63for.inc: ; preds = %for.body
64 %add = add nsw i32 %g_4.0, 1 ; <i32> [#uses=1]
65 br label %for.cond
66
67for.end: ; preds = %for.body, %for.cond
68 %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([4 x i8]* @.str, i64 0, i64 0), i32 %g_4.0) nounwind ; <i32> [#uses=0]
69 ret i32 0
70}
71
72declare i32 @printf(i8*, ...)