Home | History | Annotate | Download | only in GVN
      1 ; RUN: opt %s -gvn -S -o - | FileCheck %s
      2 
      3 define i32 @f1(i32 %x) {
      4   ; CHECK: define i32 @f1(
      5 bb0:
      6   %cmp = icmp eq i32 %x, 0
      7   br i1 %cmp, label %bb2, label %bb1
      8 bb1:
      9   br label %bb2
     10 bb2:
     11   %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]
     12   %foo = add i32 %cond, %x
     13   ret i32 %foo
     14   ; CHECK: bb2:
     15   ; CHECK: ret i32 %x
     16 }
     17 
     18 define i32 @f2(i32 %x) {
     19   ; CHECK: define i32 @f2(
     20 bb0:
     21   %cmp = icmp ne i32 %x, 0
     22   br i1 %cmp, label %bb1, label %bb2
     23 bb1:
     24   br label %bb2
     25 bb2:
     26   %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]
     27   %foo = add i32 %cond, %x
     28   ret i32 %foo
     29   ; CHECK: bb2:
     30   ; CHECK: ret i32 %x
     31 }
     32 
     33 define i32 @f3(i32 %x) {
     34   ; CHECK: define i32 @f3(
     35 bb0:
     36   switch i32 %x, label %bb1 [ i32 0, label %bb2]
     37 bb1:
     38   br label %bb2
     39 bb2:
     40   %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]
     41   %foo = add i32 %cond, %x
     42   ret i32 %foo
     43   ; CHECK: bb2:
     44   ; CHECK: ret i32 %x
     45 }
     46 
     47 declare void @g(i1)
     48 define void @f4(i8 * %x)  {
     49 ; CHECK: define void @f4(
     50 bb0:
     51   %y = icmp eq i8* null, %x
     52   br i1 %y, label %bb2, label %bb1
     53 bb1:
     54   br label %bb2
     55 bb2:
     56   %zed = icmp eq i8* null, %x
     57   call void @g(i1 %zed)
     58 ; CHECK: call void @g(i1 %y)
     59   ret void
     60 }
     61