Home | History | Annotate | Download | only in LoopUnroll
      1 ; Check that we don't crash on corner cases.
      2 ; RUN: opt < %s -S -loop-unroll -unroll-max-iteration-count-to-analyze=1000 -unroll-threshold=1 -unroll-max-percent-threshold-boost=200 -o /dev/null
      3 ; RUN: opt < %s -S -passes='require<opt-remark-emit>,loop(unroll-full)' -unroll-max-iteration-count-to-analyze=1000 -unroll-threshold=1 -unroll-max-percent-threshold-boost=200 -o /dev/null
      4 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
      5 
      6 @known_constant = internal unnamed_addr constant [10 x i32] [i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1], align 16
      7 
      8 define void @foo1() {
      9 entry:
     10   br label %for.body
     11 
     12 for.body:
     13   %phi = phi i64 [ 0, %entry ], [ %inc, %for.body ]
     14   %idx = zext i32 undef to i64
     15   %add.ptr = getelementptr inbounds i64, i64* null, i64 %idx
     16   %inc = add nuw nsw i64 %phi, 1
     17   %cmp = icmp ult i64 %inc, 999
     18   br i1 %cmp, label %for.body, label %for.exit
     19 
     20 for.exit:
     21   ret void
     22 }
     23 
     24 define void @foo2() {
     25 entry:
     26   br label %for.body
     27 
     28 for.body:
     29   %phi = phi i64 [ 0, %entry ], [ %inc, %for.body ]
     30   %x = getelementptr i32, <4 x i32*> undef, <4 x i32> <i32 1, i32 1, i32 1, i32 1>
     31   %inc = add nuw nsw i64 %phi, 1
     32   %cmp = icmp ult i64 %inc, 999
     33   br i1 %cmp, label %for.body, label %for.exit
     34 
     35 for.exit:
     36   ret void
     37 }
     38 
     39 define void @cmp_undef() {
     40 entry:
     41   br label %for.body
     42 
     43 for.body:                                         ; preds = %for.inc, %entry
     44   %iv.0 = phi i64 [ 0, %entry ], [ %iv.1, %for.inc ]
     45   %arrayidx1 = getelementptr inbounds [10 x i32], [10 x i32]* @known_constant, i64 0, i64 %iv.0
     46   %x1 = load i32, i32* %arrayidx1, align 4
     47   %cmp = icmp eq i32 %x1, undef
     48   br i1 %cmp, label %if.then, label %for.inc
     49 
     50 if.then:                                          ; preds = %for.body
     51   br label %for.inc
     52 
     53 for.inc:                                          ; preds = %for.body, %if.then
     54   %iv.1 = add nuw nsw i64 %iv.0, 1
     55   %exitcond = icmp eq i64 %iv.1, 10
     56   br i1 %exitcond, label %for.end, label %for.body
     57 
     58 for.end:                                          ; preds = %for.inc
     59   ret void
     60 }
     61 
     62 define void @switch() {
     63 entry:
     64   br label %for.body
     65 
     66 for.body:
     67   %iv.0 = phi i64 [ 0, %entry ], [ %iv.1, %for.inc ]
     68   %arrayidx1 = getelementptr inbounds [10 x i32], [10 x i32]* @known_constant, i64 0, i64 %iv.0
     69   %x1 = load i32, i32* %arrayidx1, align 4
     70   switch i32 %x1, label %l1 [
     71   ]
     72 
     73 l1:
     74   %x2 = add i32 %x1, 2
     75   br label %for.inc
     76 
     77 for.inc:
     78   %iv.1 = add nuw nsw i64 %iv.0, 1
     79   %exitcond = icmp eq i64 %iv.1, 10
     80   br i1 %exitcond, label %for.end, label %for.body
     81 
     82 for.end:
     83   ret void
     84 }
     85 
     86 define <4 x i32> @vec_load() {
     87 entry:
     88   br label %for.body
     89 
     90 for.body:
     91   %phi = phi i64 [ 0, %entry ], [ %inc, %for.body ]
     92   %vec_phi = phi <4 x i32> [ <i32 0, i32 0, i32 0, i32 0>, %entry ], [ %r, %for.body ]
     93   %arrayidx = getelementptr inbounds [10 x i32], [10 x i32]* @known_constant, i64 0, i64 %phi
     94   %bc = bitcast i32* %arrayidx to <4 x i32>*
     95   %x = load <4 x i32>, < 4 x i32>* %bc, align 4
     96   %r = add <4 x i32> %x, %vec_phi
     97   %inc = add nuw nsw i64 %phi, 1
     98   %cmp = icmp ult i64 %inc, 999
     99   br i1 %cmp, label %for.body, label %for.exit
    100 
    101 for.exit:
    102   ret <4 x i32> %r
    103 }
    104 
    105 define void @ptrtoint_cast() optsize {
    106 entry:
    107   br label %for.body
    108 
    109 for.body:
    110   br i1 true, label %for.inc, label %if.then
    111 
    112 if.then:
    113   %arraydecay = getelementptr inbounds [1 x i32], [1 x i32]* null, i64 0, i64 0
    114   %x = ptrtoint i32* %arraydecay to i64
    115   br label %for.inc
    116 
    117 for.inc:
    118   br i1 false, label %for.body, label %for.cond.cleanup
    119 
    120 for.cond.cleanup:
    121   ret void
    122 }
    123 
    124 define void @ptrtoint_cast2() {
    125 entry:
    126   br i1 false, label %for.body.lr.ph, label %exit
    127 
    128 for.body.lr.ph:
    129   br label %for.body
    130 
    131 for.body:
    132   %iv = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
    133   %offset = getelementptr inbounds float, float* null, i32 3
    134   %bc = bitcast float* %offset to i64*
    135   %inc = add nuw nsw i32 %iv, 1
    136   br i1 false, label %for.body, label %exit
    137 
    138 exit:
    139   ret void
    140 }
    141 
    142 @i = external global i32, align 4
    143 
    144 define void @folded_not_to_constantint() {
    145 entry:
    146   br label %for.body
    147 
    148 for.body:
    149   %iv = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
    150   %m = phi i32* [ @i, %entry ], [ %m, %for.inc ]
    151   br i1 undef, label %if.else, label %if.then
    152 
    153 if.then:
    154   unreachable
    155 
    156 if.else:
    157   %cmp = icmp ult i32* %m, null
    158   br i1 %cmp, label %cond.false, label %for.inc
    159 
    160 cond.false:
    161   unreachable
    162 
    163 for.inc:
    164   %inc = add nuw nsw i32 %iv, 1
    165   %cmp2 = icmp ult i32 %inc, 10
    166   br i1 %cmp2, label %for.body, label %for.end
    167 
    168 for.end:
    169   ret void
    170 }
    171 
    172 define void @index_too_large() {
    173 entry:
    174   br label %for.body
    175 
    176 for.body:
    177   %iv = phi i64 [ -73631599, %entry ], [ %iv.next, %for.inc ]
    178   br i1 undef, label %for.body2, label %for.inc
    179 
    180 for.body2:
    181   %idx = getelementptr inbounds [10 x i32], [10 x i32]* @known_constant, i64 0, i64 %iv
    182   %x = load i32, i32* %idx, align 1
    183   br label %for.inc
    184 
    185 for.inc:
    186   %iv.next = add nsw i64 %iv, -1
    187   br i1 undef, label %for.body, label %for.end
    188 
    189 for.end:
    190   ret void
    191 }
    192 
    193 define void @cmp_type_mismatch() {
    194 entry:
    195   br label %for.header
    196 
    197 for.header:
    198   br label %for.body
    199 
    200 for.body:
    201   %d = phi i32* [ null, %for.header ]
    202   %cmp = icmp eq i32* %d, null
    203   br i1 undef, label %for.end, label %for.header
    204 
    205 for.end:
    206   ret void
    207 }
    208 
    209 define void @load_type_mismatch() {
    210 entry:
    211   br label %for.body
    212 
    213 for.body:
    214   %iv.0 = phi i64 [ 0, %entry ], [ %iv.1, %for.body ]
    215   %arrayidx1 = getelementptr inbounds [10 x i32], [10 x i32]* @known_constant, i64 0, i64 %iv.0
    216   %bc = bitcast i32* %arrayidx1 to i64*
    217   %x1 = load i64, i64* %bc, align 4
    218   %x2 = add i64 10, %x1
    219   %iv.1 = add nuw nsw i64 %iv.0, 1
    220   %exitcond = icmp eq i64 %iv.1, 10
    221   br i1 %exitcond, label %for.end, label %for.body
    222 
    223 for.end:
    224   ret void
    225 }
    226