Home | History | Annotate | Download | only in CorrelatedValuePropagation
      1 ; RUN: opt < %s -correlated-propagation -S | FileCheck %s
      2 ; PR2581
      3 
      4 ; CHECK: @test1
      5 define i32 @test1(i1 %C) nounwind  {
      6         br i1 %C, label %exit, label %body
      7 
      8 body:           ; preds = %0
      9 ; CHECK-NOT: select
     10         %A = select i1 %C, i32 10, i32 11               ; <i32> [#uses=1]
     11 ; CHECK: ret i32 11
     12         ret i32 %A
     13 
     14 exit:           ; preds = %0
     15 ; CHECK: ret i32 10
     16         ret i32 10
     17 }
     18 
     19 ; PR4420
     20 declare i1 @ext()
     21 ; CHECK: @test2
     22 define i1 @test2() {
     23 entry:
     24         %cond = tail call i1 @ext()             ; <i1> [#uses=2]
     25         br i1 %cond, label %bb1, label %bb2
     26 
     27 bb1:            ; preds = %entry
     28         %cond2 = tail call i1 @ext()            ; <i1> [#uses=1]
     29         br i1 %cond2, label %bb3, label %bb2
     30 
     31 bb2:            ; preds = %bb1, %entry
     32 ; CHECK-NOT: phi i1
     33         %cond_merge = phi i1 [ %cond, %entry ], [ false, %bb1 ]         ; <i1> [#uses=1]
     34 ; CHECK: ret i1 false
     35         ret i1 %cond_merge
     36 
     37 bb3:            ; preds = %bb1
     38         %res = tail call i1 @ext()              ; <i1> [#uses=1]
     39 ; CHECK: ret i1 %res
     40         ret i1 %res
     41 }
     42 
     43 ; PR4855
     44 @gv = internal constant i8 7
     45 ; CHECK: @test3
     46 define i8 @test3(i8* %a) nounwind {
     47 entry:
     48         %cond = icmp eq i8* %a, @gv
     49         br i1 %cond, label %bb2, label %bb
     50 
     51 bb:             ; preds = %entry
     52         ret i8 0
     53 
     54 bb2:            ; preds = %entry
     55 ; CHECK: %should_be_const = load i8* @gv
     56         %should_be_const = load i8* %a
     57         ret i8 %should_be_const
     58 }
     59 
     60 ; PR1757
     61 ; CHECK: @test4
     62 define i32 @test4(i32) {
     63 EntryBlock:
     64 ; CHECK: icmp sgt i32 %0, 2  
     65   %.demorgan = icmp sgt i32 %0, 2    
     66   br i1 %.demorgan, label %GreaterThanTwo, label %LessThanOrEqualToTwo
     67 
     68 GreaterThanTwo:
     69 ; CHECK-NOT: icmp eq i32 %0, 2
     70   icmp eq i32 %0, 2
     71 ; CHECK: br i1 false
     72   br i1 %1, label %Impossible, label %NotTwoAndGreaterThanTwo
     73 
     74 NotTwoAndGreaterThanTwo:
     75   ret i32 2
     76 
     77 Impossible:
     78   ret i32 1
     79 
     80 LessThanOrEqualToTwo:
     81   ret i32 0
     82 }
     83 
     84 define i32 @switch1(i32 %s) {
     85 ; CHECK: @switch1
     86 entry:
     87   %cmp = icmp slt i32 %s, 0
     88   br i1 %cmp, label %negative, label %out
     89 
     90 negative:
     91   switch i32 %s, label %out [
     92 ; CHECK: switch i32 %s, label %out
     93     i32 0, label %out
     94 ; CHECK-NOT: i32 0
     95     i32 1, label %out
     96 ; CHECK-NOT: i32 1
     97     i32 -1, label %next
     98 ; CHECK: i32 -1, label %next
     99     i32 -2, label %next
    100 ; CHECK: i32 -2, label %next
    101     i32 2, label %out
    102 ; CHECK-NOT: i32 2
    103     i32 3, label %out
    104 ; CHECK-NOT: i32 3
    105   ]
    106 
    107 out:
    108   %p = phi i32 [ 1, %entry ], [ -1, %negative ], [ -1, %negative ], [ -1, %negative ], [ -1, %negative ]
    109   ret i32 %p
    110 
    111 next:
    112   %q = phi i32 [ 0, %negative ], [ 0, %negative ]
    113   ret i32 %q
    114 }
    115 
    116 define i32 @switch2(i32 %s) {
    117 ; CHECK: @switch2
    118 entry:
    119   %cmp = icmp sgt i32 %s, 0
    120   br i1 %cmp, label %positive, label %out
    121 
    122 positive:
    123   switch i32 %s, label %out [
    124     i32 0, label %out
    125     i32 -1, label %next
    126     i32 -2, label %next
    127   ]
    128 ; CHECK: br label %out
    129 
    130 out:
    131   %p = phi i32 [ -1, %entry ], [ 1, %positive ], [ 1, %positive ]
    132   ret i32 %p
    133 
    134 next:
    135   %q = phi i32 [ 0, %positive ], [ 0, %positive ]
    136   ret i32 %q
    137 }
    138 
    139 define i32 @switch3(i32 %s) {
    140 ; CHECK: @switch3
    141 entry:
    142   %cmp = icmp sgt i32 %s, 0
    143   br i1 %cmp, label %positive, label %out
    144 
    145 positive:
    146   switch i32 %s, label %out [
    147     i32 -1, label %out
    148     i32 -2, label %next
    149     i32 -3, label %next
    150   ]
    151 ; CHECK: br label %out
    152 
    153 out:
    154   %p = phi i32 [ -1, %entry ], [ 1, %positive ], [ 1, %positive ]
    155   ret i32 %p
    156 
    157 next:
    158   %q = phi i32 [ 0, %positive ], [ 0, %positive ]
    159   ret i32 %q
    160 }
    161 
    162 define void @switch4(i32 %s) {
    163 ; CHECK: @switch4
    164 entry:
    165   %cmp = icmp eq i32 %s, 0
    166   br i1 %cmp, label %zero, label %out
    167 
    168 zero:
    169   switch i32 %s, label %out [
    170     i32 0, label %next
    171     i32 1, label %out
    172     i32 -1, label %out
    173   ]
    174 ; CHECK: br label %next
    175 
    176 out:
    177   ret void
    178 
    179 next:
    180   ret void
    181 }
    182