Home | History | Annotate | Download | only in GVN
      1 ; RUN: opt < %s -basicaa -gvn -S | FileCheck %s
      2 
      3 @a = external global i32		; <i32*> [#uses=7]
      4 
      5 ; CHECK: @test1
      6 define i32 @test1() nounwind {
      7 entry:
      8 	%0 = load i32* @a, align 4
      9 	%1 = icmp eq i32 %0, 4
     10 	br i1 %1, label %bb, label %bb1
     11 
     12 bb:		; preds = %entry
     13 	br label %bb8
     14 
     15 bb1:		; preds = %entry
     16 	%2 = load i32* @a, align 4
     17 	%3 = icmp eq i32 %2, 5
     18 	br i1 %3, label %bb2, label %bb3
     19 
     20 bb2:		; preds = %bb1
     21 	br label %bb8
     22 
     23 bb3:		; preds = %bb1
     24 	%4 = load i32* @a, align 4
     25 	%5 = icmp eq i32 %4, 4
     26 ; CHECK: br i1 false, label %bb4, label %bb5
     27 	br i1 %5, label %bb4, label %bb5
     28 
     29 bb4:		; preds = %bb3
     30 	%6 = load i32* @a, align 4
     31 	%7 = add i32 %6, 5
     32 	br label %bb8
     33 
     34 bb5:		; preds = %bb3
     35 	%8 = load i32* @a, align 4
     36 	%9 = icmp eq i32 %8, 5
     37 ; CHECK: br i1 false, label %bb6, label %bb7
     38 	br i1 %9, label %bb6, label %bb7
     39 
     40 bb6:		; preds = %bb5
     41 	%10 = load i32* @a, align 4
     42 	%11 = add i32 %10, 4
     43 	br label %bb8
     44 
     45 bb7:		; preds = %bb5
     46 	%12 = load i32* @a, align 4
     47 	br label %bb8
     48 
     49 bb8:		; preds = %bb7, %bb6, %bb4, %bb2, %bb
     50 	%.0 = phi i32 [ %12, %bb7 ], [ %11, %bb6 ], [ %7, %bb4 ], [ 4, %bb2 ], [ 5, %bb ]
     51 	br label %return
     52 
     53 return:		; preds = %bb8
     54 	ret i32 %.0
     55 }
     56 
     57 declare void @foo(i1)
     58 declare void @bar(i32)
     59 
     60 ; CHECK: @test3
     61 define void @test3(i32 %x, i32 %y) {
     62   %xz = icmp eq i32 %x, 0
     63   %yz = icmp eq i32 %y, 0
     64   %z = and i1 %xz, %yz
     65   br i1 %z, label %both_zero, label %nope
     66 both_zero:
     67   call void @foo(i1 %xz)
     68 ; CHECK: call void @foo(i1 true)
     69   call void @foo(i1 %yz)
     70 ; CHECK: call void @foo(i1 true)
     71   call void @bar(i32 %x)
     72 ; CHECK: call void @bar(i32 0)
     73   call void @bar(i32 %y)
     74 ; CHECK: call void @bar(i32 0)
     75   ret void
     76 nope:
     77   call void @foo(i1 %z)
     78 ; CHECK: call void @foo(i1 false)
     79   ret void
     80 }
     81 
     82 ; CHECK: @test4
     83 define void @test4(i1 %b, i32 %x) {
     84   br i1 %b, label %sw, label %case3
     85 sw:
     86   switch i32 %x, label %default [
     87     i32 0, label %case0
     88     i32 1, label %case1
     89     i32 2, label %case0
     90     i32 3, label %case3
     91     i32 4, label %default
     92   ]
     93 default:
     94 ; CHECK: default:
     95   call void @bar(i32 %x)
     96 ; CHECK: call void @bar(i32 %x)
     97   ret void
     98 case0:
     99 ; CHECK: case0:
    100   call void @bar(i32 %x)
    101 ; CHECK: call void @bar(i32 %x)
    102   ret void
    103 case1:
    104 ; CHECK: case1:
    105   call void @bar(i32 %x)
    106 ; CHECK: call void @bar(i32 1)
    107   ret void
    108 case3:
    109 ; CHECK: case3:
    110   call void @bar(i32 %x)
    111 ; CHECK: call void @bar(i32 %x)
    112   ret void
    113 }
    114 
    115 ; CHECK: @test5
    116 define i1 @test5(i32 %x, i32 %y) {
    117   %cmp = icmp eq i32 %x, %y
    118   br i1 %cmp, label %same, label %different
    119 
    120 same:
    121   %cmp2 = icmp ne i32 %x, %y
    122 ; CHECK: ret i1 false
    123   ret i1 %cmp2
    124 
    125 different:
    126   %cmp3 = icmp eq i32 %x, %y
    127 ; CHECK: ret i1 false
    128   ret i1 %cmp3
    129 }
    130 
    131 ; CHECK: @test6
    132 define i1 @test6(i32 %x, i32 %y) {
    133   %cmp2 = icmp ne i32 %x, %y
    134   %cmp = icmp eq i32 %x, %y
    135   %cmp3 = icmp eq i32 %x, %y
    136   br i1 %cmp, label %same, label %different
    137 
    138 same:
    139 ; CHECK: ret i1 false
    140   ret i1 %cmp2
    141 
    142 different:
    143 ; CHECK: ret i1 false
    144   ret i1 %cmp3
    145 }
    146 
    147 ; CHECK: @test7
    148 define i1 @test7(i32 %x, i32 %y) {
    149   %cmp = icmp sgt i32 %x, %y
    150   br i1 %cmp, label %same, label %different
    151 
    152 same:
    153   %cmp2 = icmp sle i32 %x, %y
    154 ; CHECK: ret i1 false
    155   ret i1 %cmp2
    156 
    157 different:
    158   %cmp3 = icmp sgt i32 %x, %y
    159 ; CHECK: ret i1 false
    160   ret i1 %cmp3
    161 }
    162 
    163 ; CHECK: @test8
    164 define i1 @test8(i32 %x, i32 %y) {
    165   %cmp2 = icmp sle i32 %x, %y
    166   %cmp = icmp sgt i32 %x, %y
    167   %cmp3 = icmp sgt i32 %x, %y
    168   br i1 %cmp, label %same, label %different
    169 
    170 same:
    171 ; CHECK: ret i1 false
    172   ret i1 %cmp2
    173 
    174 different:
    175 ; CHECK: ret i1 false
    176   ret i1 %cmp3
    177 }
    178 
    179 ; PR1768
    180 ; CHECK: @test9
    181 define i32 @test9(i32 %i, i32 %j) {
    182   %cmp = icmp eq i32 %i, %j
    183   br i1 %cmp, label %cond_true, label %ret
    184 
    185 cond_true:
    186   %diff = sub i32 %i, %j
    187   ret i32 %diff
    188 ; CHECK: ret i32 0
    189 
    190 ret:
    191   ret i32 5
    192 ; CHECK: ret i32 5
    193 }
    194 
    195 ; PR1768
    196 ; CHECK: @test10
    197 define i32 @test10(i32 %j, i32 %i) {
    198   %cmp = icmp eq i32 %i, %j
    199   br i1 %cmp, label %cond_true, label %ret
    200 
    201 cond_true:
    202   %diff = sub i32 %i, %j
    203   ret i32 %diff
    204 ; CHECK: ret i32 0
    205 
    206 ret:
    207   ret i32 5
    208 ; CHECK: ret i32 5
    209 }
    210 
    211 declare i32 @yogibar()
    212 
    213 ; CHECK: @test11
    214 define i32 @test11(i32 %x) {
    215   %v0 = call i32 @yogibar()
    216   %v1 = call i32 @yogibar()
    217   %cmp = icmp eq i32 %v0, %v1
    218   br i1 %cmp, label %cond_true, label %next
    219 
    220 cond_true:
    221   ret i32 %v1
    222 ; CHECK: ret i32 %v0
    223 
    224 next:
    225   %cmp2 = icmp eq i32 %x, %v0
    226   br i1 %cmp2, label %cond_true2, label %next2
    227 
    228 cond_true2:
    229   ret i32 %v0
    230 ; CHECK: ret i32 %x
    231 
    232 next2:
    233   ret i32 0
    234 }
    235 
    236 ; CHECK: @test12
    237 define i32 @test12(i32 %x) {
    238   %cmp = icmp eq i32 %x, 0
    239   br i1 %cmp, label %cond_true, label %cond_false
    240 
    241 cond_true:
    242   br label %ret
    243 
    244 cond_false:
    245   br label %ret
    246 
    247 ret:
    248   %res = phi i32 [ %x, %cond_true ], [ %x, %cond_false ]
    249 ; CHECK: %res = phi i32 [ 0, %cond_true ], [ %x, %cond_false ]
    250   ret i32 %res
    251 }
    252