1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=sccp -S | FileCheck %s
4 ; This is a basic correctness check for constant propagation. The add
5 ; instruction should be eliminated.
7 define i32 @test1(i1 %B) {
9 ; CHECK-NEXT: br i1 [[B:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
11 ; CHECK-NEXT: br label [[BB3:%.*]]
13 ; CHECK-NEXT: br label [[BB3]]
15 ; CHECK-NEXT: [[RET:%.*]] = phi i32 [ 0, [[BB1]] ], [ 1, [[BB2]] ]
16 ; CHECK-NEXT: ret i32 [[RET]]
18 br i1 %B, label %BB1, label %BB2
20 %Val = add i32 0, 0 ; <i32> [#uses=1]
24 BB3: ; preds = %BB2, %BB1
25 %Ret = phi i32 [ %Val, %BB1 ], [ 1, %BB2 ] ; <i32> [#uses=1]
30 ; This is the test case taken from appel's book that illustrates a hard case
31 ; that SCCP gets right.
33 define i32 @test2(i32 %i0, i32 %j0) {
34 ; CHECK-LABEL: @test2(
36 ; CHECK-NEXT: br label [[BB2:%.*]]
38 ; CHECK-NEXT: [[K2:%.*]] = phi i32 [ [[K3:%.*]], [[BB7:%.*]] ], [ 0, [[BB1:%.*]] ]
39 ; CHECK-NEXT: [[KCOND:%.*]] = icmp slt i32 [[K2]], 100
40 ; CHECK-NEXT: br i1 [[KCOND]], label [[BB3:%.*]], label [[BB4:%.*]]
42 ; CHECK-NEXT: br label [[BB5:%.*]]
44 ; CHECK-NEXT: ret i32 1
46 ; CHECK-NEXT: [[K3]] = add i32 [[K2]], 1
47 ; CHECK-NEXT: br label [[BB7]]
49 ; CHECK-NEXT: br label [[BB2]]
54 %j2 = phi i32 [ %j4, %BB7 ], [ 1, %BB1 ]
55 %k2 = phi i32 [ %k4, %BB7 ], [ 0, %BB1 ]
56 %kcond = icmp slt i32 %k2, 100
57 br i1 %kcond, label %BB3, label %BB4
59 %jcond = icmp slt i32 %j2, 20
60 br i1 %jcond, label %BB5, label %BB6
70 %j4 = phi i32 [ 1, %BB5 ], [ %k2, %BB6 ]
71 %k4 = phi i32 [ %k3, %BB5 ], [ %k5, %BB6 ]