• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -sccp -S | FileCheck %s
2
3; 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
26BB1:
27	br label %BB2
28BB2:
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
33BB3:
34	%jcond = icmp slt i32 %j2, 20
35	br i1 %jcond, label %BB5, label %BB6
36; CHECK: BB3:
37; CHECK-NEXT: br i1 true, label %BB5, label %BB6
38BB4:
39	ret i32 %j2
40; CHECK: BB4:
41; CHECK-NEXT: ret i32 1
42BB5:
43	%k3 = add i32 %k2, 1
44	br label %BB7
45BB6:
46	%k5 = add i32 %k2, 1
47	br label %BB7
48; 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 ]
53	br label %BB2
54; CHECK: BB7:
55; CHECK-NEXT: %k4 = phi i32 [ %k3, %BB5 ], [ undef, %BB6 ]
56; CHECK-NEXT: br label %BB2
57}
58
59