blob: a719f6cfb48d916dd80caf88fd15d1ec9a6ec516 [file] [log] [blame]
Chris Lattner55190132009-10-20 20:33:46 +00001; RUN: opt < %s -sccp -S | FileCheck %s
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002
Chris Lattner55190132009-10-20 20:33:46 +00003; This is a basic sanity check for constant propagation. The add instruction
4; should be eliminated.
5
6define i32 @test1(i1 %B) {
7 br i1 %B, label %BB1, label %BB2
8BB1: ; preds = %0
9 %Val = add i32 0, 0 ; <i32> [#uses=1]
10 br label %BB3
11BB2: ; preds = %0
12 br label %BB3
13BB3: ; preds = %BB2, %BB1
14 %Ret = phi i32 [ %Val, %BB1 ], [ 1, %BB2 ] ; <i32> [#uses=1]
15 ret i32 %Ret
16
17; CHECK: @test1
18; CHECK: %Ret = phi i32 [ 0, %BB1 ], [ 1, %BB2 ]
19}
20
21; This is the test case taken from appel's book that illustrates a hard case
22; that SCCP gets right.
23;
24define i32 @test2(i32 %i0, i32 %j0) {
25; CHECK: @test2
Dan Gohmanf17a25c2007-07-18 16:29:46 +000026BB1:
27 br label %BB2
Chris Lattner55190132009-10-20 20:33:46 +000028BB2:
29 %j2 = phi i32 [ %j4, %BB7 ], [ 1, %BB1 ]
30 %k2 = phi i32 [ %k4, %BB7 ], [ 0, %BB1 ]
31 %kcond = icmp slt i32 %k2, 100
Tanya Lattnerba93e2d2008-03-19 04:14:49 +000032 br i1 %kcond, label %BB3, label %BB4
Chris Lattner55190132009-10-20 20:33:46 +000033BB3:
34 %jcond = icmp slt i32 %j2, 20
Tanya Lattnerba93e2d2008-03-19 04:14:49 +000035 br i1 %jcond, label %BB5, label %BB6
Chris Lattner55190132009-10-20 20:33:46 +000036; CHECK: BB3:
37; CHECK-NEXT: br i1 true, label %BB5, label %BB6
38BB4:
Tanya Lattnerba93e2d2008-03-19 04:14:49 +000039 ret i32 %j2
Chris Lattner55190132009-10-20 20:33:46 +000040; CHECK: BB4:
41; CHECK-NEXT: ret i32 1
42BB5:
43 %k3 = add i32 %k2, 1
Dan Gohmanf17a25c2007-07-18 16:29:46 +000044 br label %BB7
Chris Lattner55190132009-10-20 20:33:46 +000045BB6:
46 %k5 = add i32 %k2, 1
Dan Gohmanf17a25c2007-07-18 16:29:46 +000047 br label %BB7
Chris Lattner55190132009-10-20 20:33:46 +000048; CHECK: BB6:
49; CHECK-NEXT: br label %BB7
50BB7:
51 %j4 = phi i32 [ 1, %BB5 ], [ %k2, %BB6 ]
52 %k4 = phi i32 [ %k3, %BB5 ], [ %k5, %BB6 ]
Dan Gohmanf17a25c2007-07-18 16:29:46 +000053 br label %BB2
Chris Lattner55190132009-10-20 20:33:46 +000054; CHECK: BB7:
55; CHECK-NEXT: %k4 = phi i32 [ %k3, %BB5 ], [ undef, %BB6 ]
56; CHECK-NEXT: br label %BB2
Dan Gohmanf17a25c2007-07-18 16:29:46 +000057}
Tanya Lattnerba93e2d2008-03-19 04:14:49 +000058