Home | History | Annotate | Download | only in SimplifyCFG
      1 ; RUN: opt %s -S -simplifycfg | FileCheck %s
      2 ; Check for when one branch implies the value of a successors conditional and
      3 ; it's not simply the same conditional repeated.
      4 
      5 define void @test(i32 %length.i, i32 %i) {
      6 ; CHECK-LABEL: @test
      7   %iplus1 = add nsw i32 %i, 1
      8   %var29 = icmp slt i32 %iplus1, %length.i
      9 ; CHECK: br i1 %var29, label %in_bounds, label %out_of_bounds
     10   br i1 %var29, label %next, label %out_of_bounds
     11 
     12 next:
     13 ; CHECK-LABEL: in_bounds:
     14 ; CHECK-NEXT: ret void
     15   %var30 = icmp slt i32 %i, %length.i
     16   br i1 %var30, label %in_bounds, label %out_of_bounds2
     17 
     18 in_bounds:
     19   ret void
     20 
     21 out_of_bounds:
     22   call void @foo(i64 0)
     23   unreachable
     24 
     25 out_of_bounds2:
     26   call void @foo(i64 1)
     27   unreachable
     28 }
     29 
     30 ; If the add is not nsw, it's not safe to use the fact about i+1 to imply the
     31 ; i condition since it could have overflowed.
     32 define void @test_neg(i32 %length.i, i32 %i) {
     33 ; CHECK-LABEL: @test_neg
     34   %iplus1 = add i32 %i, 1
     35   %var29 = icmp slt i32 %iplus1, %length.i
     36 ; CHECK: br i1 %var29, label %next, label %out_of_bounds
     37   br i1 %var29, label %next, label %out_of_bounds
     38 
     39 next:
     40   %var30 = icmp slt i32 %i, %length.i
     41 ; CHECK: br i1 %var30, label %in_bounds, label %out_of_bounds2
     42   br i1 %var30, label %in_bounds, label %out_of_bounds2
     43 
     44 in_bounds:
     45   ret void
     46 
     47 out_of_bounds:
     48   call void @foo(i64 0)
     49   unreachable
     50 
     51 out_of_bounds2:
     52   call void @foo(i64 1)
     53   unreachable
     54 }
     55 
     56 
     57 define void @test2(i32 %length.i, i32 %i) {
     58 ; CHECK-LABEL: @test2
     59   %iplus100 = add nsw i32 %i, 100
     60   %var29 = icmp slt i32 %iplus100, %length.i
     61 ; CHECK: br i1 %var29, label %in_bounds, label %out_of_bounds
     62   br i1 %var29, label %next, label %out_of_bounds
     63 
     64 next:
     65   %var30 = icmp slt i32 %i, %length.i
     66   br i1 %var30, label %in_bounds, label %out_of_bounds2
     67 
     68 in_bounds:
     69   ret void
     70 
     71 out_of_bounds:
     72   call void @foo(i64 0)
     73   unreachable
     74 
     75 out_of_bounds2:
     76   call void @foo(i64 1)
     77   unreachable
     78 }
     79 
     80 declare void @foo(i64)
     81 
     82