Home | History | Annotate | Download | only in ScalarEvolution
      1 ; RUN: opt -S -analyze -scalar-evolution < %s | FileCheck %s
      2 
      3 !0 = !{i8 0, i8 127}
      4 
      5 define void @f0(i8* %len_addr) {
      6 ; CHECK-LABEL: Classifying expressions for: @f0
      7  entry:
      8   %len = load i8, i8* %len_addr, !range !0
      9   %len_norange = load i8, i8* %len_addr
     10 ; CHECK:  %len = load i8, i8* %len_addr, !range !0
     11 ; CHECK-NEXT:  -->  %len U: [0,127) S: [0,127)
     12 ; CHECK:  %len_norange = load i8, i8* %len_addr
     13 ; CHECK-NEXT:  -->  %len_norange U: full-set S: full-set
     14 
     15   %t0 = add i8 %len, 1
     16   %t1 = add i8 %len, 2
     17 ; CHECK:  %t0 = add i8 %len, 1
     18 ; CHECK-NEXT:  -->  (1 + %len)<nuw><nsw> U: [1,-128) S: [1,-128)
     19 ; CHECK:  %t1 = add i8 %len, 2
     20 ; CHECK-NEXT:  -->  (2 + %len)<nuw> U: [2,-127) S: [2,-127)
     21 
     22   %t2 = sub i8 %len, 1
     23   %t3 = sub i8 %len, 2
     24 ; CHECK:  %t2 = sub i8 %len, 1
     25 ; CHECK-NEXT:  -->  (-1 + %len)<nsw> U: [-1,126) S: [-1,126)
     26 ; CHECK:  %t3 = sub i8 %len, 2
     27 ; CHECK-NEXT:  -->  (-2 + %len)<nsw> U: [-2,125) S: [-2,125)
     28 
     29   %q0 = add i8 %len_norange, 1
     30   %q1 = add i8 %len_norange, 2
     31 ; CHECK:  %q0 = add i8 %len_norange, 1
     32 ; CHECK-NEXT:  -->  (1 + %len_norange) U: full-set S: full-set
     33 ; CHECK:  %q1 = add i8 %len_norange, 2
     34 ; CHECK-NEXT:  -->  (2 + %len_norange) U: full-set S: full-set
     35 
     36   %q2 = sub i8 %len_norange, 1
     37   %q3 = sub i8 %len_norange, 2
     38 ; CHECK:  %q2 = sub i8 %len_norange, 1
     39 ; CHECK-NEXT:  -->  (-1 + %len_norange) U: full-set S: full-set
     40 ; CHECK:  %q3 = sub i8 %len_norange, 2
     41 ; CHECK-NEXT:  -->  (-2 + %len_norange) U: full-set S: full-set
     42 
     43   ret void
     44 }
     45 
     46 define void @f1(i8* %len_addr) {
     47 ; CHECK-LABEL: Classifying expressions for: @f1
     48  entry:
     49   %len = load i8, i8* %len_addr, !range !0
     50   %len_norange = load i8, i8* %len_addr
     51 ; CHECK:  %len = load i8, i8* %len_addr, !range !0
     52 ; CHECK-NEXT:  -->  %len U: [0,127) S: [0,127)
     53 ; CHECK:  %len_norange = load i8, i8* %len_addr
     54 ; CHECK-NEXT:  -->  %len_norange U: full-set S: full-set
     55 
     56   %t0 = add i8 %len, -1
     57   %t1 = add i8 %len, -2
     58 ; CHECK:  %t0 = add i8 %len, -1
     59 ; CHECK-NEXT:  -->  (-1 + %len)<nsw> U: [-1,126) S: [-1,126)
     60 ; CHECK:  %t1 = add i8 %len, -2
     61 ; CHECK-NEXT:  -->  (-2 + %len)<nsw> U: [-2,125) S: [-2,125)
     62 
     63   %t0.sext = sext i8 %t0 to i16
     64   %t1.sext = sext i8 %t1 to i16
     65 ; CHECK:  %t0.sext = sext i8 %t0 to i16
     66 ; CHECK-NEXT:  -->  (-1 + (zext i8 %len to i16))<nsw> U: [-1,126) S: [-1,126)
     67 ; CHECK:  %t1.sext = sext i8 %t1 to i16
     68 ; CHECK-NEXT:  -->  (-2 + (zext i8 %len to i16))<nsw> U: [-2,125) S: [-2,125)
     69 
     70   %q0 = add i8 %len_norange, 1
     71   %q1 = add i8 %len_norange, 2
     72 ; CHECK:  %q0 = add i8 %len_norange, 1
     73 ; CHECK-NEXT:  -->  (1 + %len_norange) U: full-set S: full-set
     74 ; CHECK:  %q1 = add i8 %len_norange, 2
     75 ; CHECK-NEXT:  -->  (2 + %len_norange) U: full-set S: full-set
     76 
     77   %q0.sext = sext i8 %q0 to i16
     78   %q1.sext = sext i8 %q1 to i16
     79 ; CHECK:  %q0.sext = sext i8 %q0 to i16
     80 ; CHECK-NEXT:  -->  (sext i8 (1 + %len_norange) to i16) U: [-128,128) S: [-128,128)
     81 ; CHECK:  %q1.sext = sext i8 %q1 to i16
     82 ; CHECK-NEXT:  -->  (sext i8 (2 + %len_norange) to i16) U: [-128,128) S: [-128,128)
     83 
     84   ret void
     85 }
     86 
     87 define void @f2(i8* %len_addr) {
     88 ; CHECK-LABEL: Classifying expressions for: @f2
     89  entry:
     90   %len = load i8, i8* %len_addr, !range !0
     91   %len_norange = load i8, i8* %len_addr
     92 ; CHECK:  %len = load i8, i8* %len_addr, !range !0
     93 ; CHECK-NEXT:  -->  %len U: [0,127) S: [0,127)
     94 ; CHECK:  %len_norange = load i8, i8* %len_addr
     95 ; CHECK-NEXT:  -->  %len_norange U: full-set S: full-set
     96 
     97   %t0 = add i8 %len, 1
     98   %t1 = add i8 %len, 2
     99 ; CHECK:  %t0 = add i8 %len, 1
    100 ; CHECK-NEXT:  -->  (1 + %len)<nuw><nsw>
    101 ; CHECK:  %t1 = add i8 %len, 2
    102 ; CHECK-NEXT:  -->  (2 + %len)<nuw>
    103 
    104   %t0.zext = zext i8 %t0 to i16
    105   %t1.zext = zext i8 %t1 to i16
    106 ; CHECK:  %t0.zext = zext i8 %t0 to i16
    107 ; CHECK-NEXT: -->  (1 + (zext i8 %len to i16))<nuw><nsw> U: [1,128) S: [1,128)
    108 ; CHECK:  %t1.zext = zext i8 %t1 to i16
    109 ; CHECK-NEXT:  -->  (2 + (zext i8 %len to i16))<nuw><nsw> U: [2,129) S: [2,129)
    110 
    111   %q0 = add i8 %len_norange, 1
    112   %q1 = add i8 %len_norange, 2
    113   %q0.zext = zext i8 %q0 to i16
    114   %q1.zext = zext i8 %q1 to i16
    115 
    116 ; CHECK:  %q0.zext = zext i8 %q0 to i16
    117 ; CHECK-NEXT:  -->  (zext i8 (1 + %len_norange) to i16) U: [0,256) S: [0,256)
    118 ; CHECK:  %q1.zext = zext i8 %q1 to i16
    119 ; CHECK-NEXT:  -->  (zext i8 (2 + %len_norange) to i16) U: [0,256) S: [0,256)
    120 
    121   ret void
    122 }
    123 
    124 @z_addr = external global [16 x i8], align 4
    125 @z_addr_noalign = external global [16 x i8]
    126 
    127 %union = type { [10 x [4 x float]] }
    128 @tmp_addr = external unnamed_addr global { %union, [2000 x i8] }
    129 
    130 define void @f3(i8* %x_addr, i8* %y_addr, i32* %tmp_addr) {
    131 ; CHECK-LABEL: Classifying expressions for: @f3
    132  entry:
    133   %x = load i8, i8* %x_addr
    134   %t0 = mul i8 %x, 4
    135   %t1 = add i8 %t0, 5
    136   %t1.zext = zext i8 %t1 to i16
    137 ; CHECK:  %t1.zext = zext i8 %t1 to i16
    138 ; CHECK-NEXT:  -->  (1 + (zext i8 (4 + (4 * %x)) to i16))<nuw><nsw> U: [1,254) S: [1,257)
    139 
    140   %q0 = mul i8 %x, 4
    141   %q1 = add i8 %q0, 7
    142   %q1.zext = zext i8 %q1 to i16
    143 ; CHECK:  %q1.zext = zext i8 %q1 to i16
    144 ; CHECK-NEXT:  -->  (3 + (zext i8 (4 + (4 * %x)) to i16))<nuw><nsw> U: [3,256) S: [3,259)
    145 
    146   %p0 = mul i8 %x, 4
    147   %p1 = add i8 %p0, 8
    148   %p1.zext = zext i8 %p1 to i16
    149 ; CHECK:  %p1.zext = zext i8 %p1 to i16
    150 ; CHECK-NEXT:  -->  (zext i8 (8 + (4 * %x)) to i16) U: [0,253) S: [0,256)
    151 
    152   %r0 = mul i8 %x, 4
    153   %r1 = add i8 %r0, 254
    154   %r1.zext = zext i8 %r1 to i16
    155 ; CHECK:  %r1.zext = zext i8 %r1 to i16
    156 ; CHECK-NEXT:  -->  (2 + (zext i8 (-4 + (4 * %x)) to i16))<nuw><nsw> U: [2,255) S: [2,258)
    157 
    158   %y = load i8, i8* %y_addr
    159   %s0 = mul i8 %x, 32
    160   %s1 = mul i8 %y, 36
    161   %s2 = add i8 %s0, %s1
    162   %s3 = add i8 %s2, 5
    163   %s3.zext = zext i8 %s3 to i16
    164 ; CHECK:  %s3.zext = zext i8 %s3 to i16
    165 ; CHECK-NEXT:  -->  (1 + (zext i8 (4 + (32 * %x) + (36 * %y)) to i16))<nuw><nsw> U: [1,254) S: [1,257)
    166 
    167   %ptr = bitcast [16 x i8]* @z_addr to i8*
    168   %int0 = ptrtoint i8* %ptr to i32
    169   %int5 = add i32 %int0, 5
    170   %int.zext = zext i32 %int5 to i64
    171 ; CHECK:  %int.zext = zext i32 %int5 to i64
    172 ; CHECK-NEXT:  -->  (1 + (zext i32 (4 + %int0) to i64))<nuw><nsw> U: [1,4294967294) S: [1,4294967297)
    173 
    174   %ptr_noalign = bitcast [16 x i8]* @z_addr_noalign to i8*
    175   %int0_na = ptrtoint i8* %ptr_noalign to i32
    176   %int5_na = add i32 %int0_na, 5
    177   %int.zext_na = zext i32 %int5_na to i64
    178 ; CHECK:  %int.zext_na = zext i32 %int5_na to i64
    179 ; CHECK-NEXT:  -->  (zext i32 (5 + %int0_na) to i64) U: [0,4294967296) S: [0,4294967296)
    180 
    181   %tmp = load i32, i32* %tmp_addr
    182   %mul = and i32 %tmp, -4
    183   %add4 = add i32 %mul, 4
    184   %add4.zext = zext i32 %add4 to i64
    185   %sunkaddr3 = mul i64 %add4.zext, 4
    186   %sunkaddr4 = getelementptr inbounds i8, i8* bitcast ({ %union, [2000 x i8] }* @tmp_addr to i8*), i64 %sunkaddr3
    187   %sunkaddr5 = getelementptr inbounds i8, i8* %sunkaddr4, i64 4096
    188   %addr4.cast = bitcast i8* %sunkaddr5 to i32*
    189   %addr4.incr = getelementptr i32, i32* %addr4.cast, i64 1
    190 ; CHECK:  %addr4.incr = getelementptr i32, i32* %addr4.cast, i64 1
    191 ; CHECK-NEXT:  -->  ([[C:4100]] + ([[SIZE:4]] * (zext i32 ([[OFFSET:4]] + ([[STRIDE:4]] * (%tmp /u [[STRIDE]]))<nuw>) to i64))<nuw><nsw> + @tmp_addr)
    192 
    193   %add5 = add i32 %mul, 5
    194   %add5.zext = zext i32 %add5 to i64
    195   %sunkaddr0 = mul i64 %add5.zext, 4
    196   %sunkaddr1 = getelementptr inbounds i8, i8* bitcast ({ %union, [2000 x i8] }* @tmp_addr to i8*), i64 %sunkaddr0
    197   %sunkaddr2 = getelementptr inbounds i8, i8* %sunkaddr1, i64 4096
    198   %addr5.cast = bitcast i8* %sunkaddr2 to i32*
    199 ; CHECK:  %addr5.cast = bitcast i8* %sunkaddr2 to i32*
    200 ; CHECK-NEXT:  -->  ([[C]]    +   ([[SIZE]]  *  (zext i32 ([[OFFSET]]  +  ([[STRIDE]]  *  (%tmp /u [[STRIDE]]))<nuw>) to i64))<nuw><nsw> + @tmp_addr)
    201 
    202   ret void
    203 }
    204