Home | History | Annotate | Download | only in SCCP
      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 
      6 define i32 @test1(i1 %B) {
      7 	br i1 %B, label %BB1, label %BB2
      8 BB1:		; preds = %0
      9 	%Val = add i32 0, 0		; <i32> [#uses=1]
     10 	br label %BB3
     11 BB2:		; preds = %0
     12 	br label %BB3
     13 BB3:		; preds = %BB2, %BB1
     14 	%Ret = phi i32 [ %Val, %BB1 ], [ 1, %BB2 ]		; <i32> [#uses=1]
     15 	ret i32 %Ret
     16         
     17 ; CHECK-LABEL: @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 ;
     24 define i32 @test2(i32 %i0, i32 %j0) {
     25 ; CHECK-LABEL: @test2(
     26 BB1:
     27 	br label %BB2
     28 BB2:
     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
     33 BB3:
     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
     38 BB4:
     39 	ret i32 %j2
     40 ; CHECK: BB4:
     41 ; CHECK-NEXT: ret i32 1
     42 BB5:
     43 	%k3 = add i32 %k2, 1
     44 	br label %BB7
     45 BB6:
     46 	%k5 = add i32 %k2, 1
     47 	br label %BB7
     48 ; CHECK: BB6:
     49 ; CHECK-NEXT: br label %BB7
     50 BB7:
     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