Home | History | Annotate | Download | only in JumpThreading
      1 ; RUN: opt -S -jump-threading < %s | FileCheck %s
      2 
      3 ; Check that the heuristic for avoiding accidental introduction of irreducible
      4 ; loops doesn't also prevent us from threading simple constructs where this
      5 ; isn't a problem.
      6 
      7 declare void @opaque_body()
      8 
      9 define void @jump_threading_loopheader() {
     10 ; CHECK-LABEL: @jump_threading_loopheader
     11 top:
     12     br label %entry
     13 
     14 entry:
     15     %ind = phi i32 [0, %top], [%nextind, %latch]
     16     %nextind = add i32 %ind, 1
     17     %cmp = icmp ule i32 %ind, 10
     18 ; CHECK: br i1 %cmp, label %latch, label %exit
     19     br i1 %cmp, label %body, label %latch
     20 
     21 body:
     22     call void @opaque_body()
     23 ; CHECK: br label %entry
     24     br label %latch
     25 
     26 latch:
     27     %cond = phi i2 [1, %entry], [2, %body]
     28     switch i2 %cond, label %unreach [
     29         i2 2, label %entry
     30         i2 1, label %exit
     31     ]
     32 
     33 unreach:
     34     unreachable
     35 
     36 exit:
     37     ret void
     38 }
     39 
     40 ; We also need to check the opposite order of the branches, in the switch
     41 ; instruction because jump-threading relies on that to decide which edge to
     42 ; try to thread first.
     43 define void @jump_threading_loopheader2() {
     44 ; CHECK-LABEL: @jump_threading_loopheader2
     45 top:
     46     br label %entry
     47 
     48 entry:
     49     %ind = phi i32 [0, %top], [%nextind, %latch]
     50     %nextind = add i32 %ind, 1
     51     %cmp = icmp ule i32 %ind, 10
     52 ; CHECK: br i1 %cmp, label %exit, label %latch
     53     br i1 %cmp, label %body, label %latch
     54 
     55 body:
     56     call void @opaque_body()
     57 ; CHECK: br label %entry
     58     br label %latch
     59 
     60 latch:
     61     %cond = phi i2 [1, %entry], [2, %body]
     62     switch i2 %cond, label %unreach [
     63         i2 1, label %entry
     64         i2 2, label %exit
     65     ]
     66 
     67 unreach:
     68     unreachable
     69 
     70 exit:
     71     ret void
     72 }
     73 
     74 ; Check if we can handle undef branch condition.
     75 define void @jump_threading_loopheader3() {
     76 ; CHECK-LABEL: @jump_threading_loopheader3
     77 top:
     78     br label %entry
     79 
     80 entry:
     81     %ind = phi i32 [0, %top], [%nextind, %latch]
     82     %nextind = add i32 %ind, 1
     83     %cmp = icmp ule i32 %ind, 10
     84 ; CHECK: br i1 %cmp, label %latch, label %exit
     85     br i1 %cmp, label %body, label %latch
     86 
     87 body:
     88     call void @opaque_body()
     89 ; CHECK: br label %entry
     90     br label %latch
     91 
     92 latch:
     93    %phi = phi i32 [undef, %entry], [0, %body]
     94    %cmp1 = icmp eq i32 %phi, 0
     95    br i1 %cmp1, label %entry, label %exit
     96 
     97 exit:
     98     ret void
     99 }
    100