Home | History | Annotate | Download | only in SimplifyCFG
      1 ; RUN: opt < %s -simplifycfg -S | FileCheck %s
      2 
      3 define void @test1(i1 %C, i1* %BP) {
      4 ; CHECK-LABEL: @test1(
      5 ; CHECK: entry:
      6 ; CHECK-NEXT: ret void
      7 entry:
      8         br i1 %C, label %T, label %F
      9 T:
     10         store i1 %C, i1* %BP
     11         unreachable
     12 F:
     13         ret void
     14 }
     15 
     16 define void @test2() personality i32 (...)* @__gxx_personality_v0 {
     17 ; CHECK-LABEL: @test2(
     18 ; CHECK: entry:
     19 ; CHECK-NEXT: call void @test2()
     20 ; CHECK-NEXT: ret void
     21 entry:
     22         invoke void @test2( )
     23                         to label %N unwind label %U
     24 U:
     25   %res = landingpad { i8* }
     26           cleanup
     27         unreachable
     28 N:
     29         ret void
     30 }
     31 
     32 declare i32 @__gxx_personality_v0(...)
     33 
     34 define i32 @test3(i32 %v) {
     35 ; CHECK-LABEL: @test3(
     36 ; CHECK: entry:
     37 ; CHECK-NEXT: [[CMP:%[A-Za-z0-9]+]] = icmp eq i32 %v, 2
     38 ; CHECK-NEXT: select i1 [[CMP]], i32 2, i32 1
     39 ; CHECK-NEXT: ret
     40 entry:
     41         switch i32 %v, label %default [
     42                  i32 1, label %U
     43                  i32 2, label %T
     44         ]
     45 default:
     46         ret i32 1
     47 U:
     48         unreachable
     49 T:
     50         ret i32 2
     51 }
     52 
     53 
     54 ;; We can either convert the following control-flow to a select or remove the
     55 ;; unreachable control flow because of the undef store of null. Make sure we do
     56 ;; the latter.
     57 
     58 define void @test5(i1 %cond, i8* %ptr) {
     59 
     60 ; CHECK-LABEL: test5
     61 ; CHECK: entry:
     62 ; CHECK-NOT: select
     63 ; CHECK:  store i8 2, i8* %ptr
     64 ; CHECK:  ret
     65 
     66 entry:
     67   br i1 %cond, label %bb1, label %bb3
     68 
     69 bb3:
     70  br label %bb2
     71 
     72 bb1:
     73  br label %bb2
     74 
     75 bb2:
     76   %ptr.2 = phi i8* [ %ptr, %bb3 ], [ null, %bb1 ]
     77   store i8 2, i8* %ptr.2, align 8
     78   ret void
     79 }
     80 
     81 ; CHECK-LABEL: test6
     82 ; CHECK: entry:
     83 ; CHECK-NOT: select
     84 ; CHECK:  store i8 2, i8* %ptr
     85 ; CHECK:  ret
     86 
     87 define void @test6(i1 %cond, i8* %ptr) {
     88 entry:
     89   br i1 %cond, label %bb1, label %bb2
     90 
     91 bb1:
     92   br label %bb2
     93 
     94 bb2:
     95   %ptr.2 = phi i8* [ %ptr, %entry ], [ null, %bb1 ]
     96   store i8 2, i8* %ptr.2, align 8
     97   ret void
     98 }
     99