1 ; RUN: opt < %s -sccp -S | FileCheck %s
3 ; This is a basic sanity check for constant propagation. The add instruction
4 ; should be eliminated.
6 define i32 @test1(i1 %B) {
7 br i1 %B, label %BB1, label %BB2
9 %Val = add i32 0, 0 ; <i32> [#uses=1]
13 BB3: ; preds = %BB2, %BB1
14 %Ret = phi i32 [ %Val, %BB1 ], [ 1, %BB2 ] ; <i32> [#uses=1]
17 ; CHECK-LABEL: @test1(
18 ; CHECK: %Ret = phi i32 [ 0, %BB1 ], [ 1, %BB2 ]
21 ; This is the test case taken from appel's book that illustrates a hard case
22 ; that SCCP gets right.
24 define i32 @test2(i32 %i0, i32 %j0) {
25 ; CHECK-LABEL: @test2(
29 %j2 = phi i32 [ %j4, %BB7 ], [ 1, %BB1 ]
30 %k2 = phi i32 [ %k4, %BB7 ], [ 0, %BB1 ]
31 %kcond = icmp slt i32 %k2, 100
32 br i1 %kcond, label %BB3, label %BB4
34 %jcond = icmp slt i32 %j2, 20
35 br i1 %jcond, label %BB5, label %BB6
37 ; CHECK-NEXT: br i1 true, label %BB5, label %BB6
41 ; CHECK-NEXT: ret i32 1
49 ; CHECK-NEXT: br label %BB7
51 %j4 = phi i32 [ 1, %BB5 ], [ %k2, %BB6 ]
52 %k4 = phi i32 [ %k3, %BB5 ], [ %k5, %BB6 ]
55 ; CHECK-NEXT: %k4 = phi i32 [ %k3, %BB5 ], [ undef, %BB6 ]
56 ; CHECK-NEXT: br label %BB2