Home | History | Annotate | Download | only in InstCombine
      1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
      2 ; RUN: opt < %s -instcombine -S | FileCheck %s
      3 
      4 ; Canonicalize vector ge/le comparisons with constants to gt/lt.
      5 
      6 ; Normal types are ConstantDataVectors. Test the constant values adjacent to the
      7 ; min/max values that we're not allowed to transform.
      8 
      9 define <2 x i1> @sge(<2 x i8> %x) {
     10 ; CHECK-LABEL: @sge(
     11 ; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt <2 x i8> %x, <i8 -128, i8 126>
     12 ; CHECK-NEXT:    ret <2 x i1> [[CMP]]
     13 ;
     14   %cmp = icmp sge <2 x i8> %x, <i8 -127, i8 -129>
     15   ret <2 x i1> %cmp
     16 }
     17 
     18 define <2 x i1> @uge(<2 x i8> %x) {
     19 ; CHECK-LABEL: @uge(
     20 ; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt <2 x i8> %x, <i8 -2, i8 0>
     21 ; CHECK-NEXT:    ret <2 x i1> [[CMP]]
     22 ;
     23   %cmp = icmp uge <2 x i8> %x, <i8 -1, i8 1>
     24   ret <2 x i1> %cmp
     25 }
     26 
     27 define <2 x i1> @sle(<2 x i8> %x) {
     28 ; CHECK-LABEL: @sle(
     29 ; CHECK-NEXT:    [[CMP:%.*]] = icmp slt <2 x i8> %x, <i8 127, i8 -127>
     30 ; CHECK-NEXT:    ret <2 x i1> [[CMP]]
     31 ;
     32   %cmp = icmp sle <2 x i8> %x, <i8 126, i8 128>
     33   ret <2 x i1> %cmp
     34 }
     35 
     36 define <2 x i1> @ule(<2 x i8> %x) {
     37 ; CHECK-LABEL: @ule(
     38 ; CHECK-NEXT:    [[CMP:%.*]] = icmp ult <2 x i8> %x, <i8 -1, i8 1>
     39 ; CHECK-NEXT:    ret <2 x i1> [[CMP]]
     40 ;
     41   %cmp = icmp ule <2 x i8> %x, <i8 254, i8 0>
     42   ret <2 x i1> %cmp
     43 }
     44 
     45 ; Zeros are special: they're ConstantAggregateZero.
     46 
     47 define <2 x i1> @sge_zero(<2 x i8> %x) {
     48 ; CHECK-LABEL: @sge_zero(
     49 ; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt <2 x i8> %x, <i8 -1, i8 -1>
     50 ; CHECK-NEXT:    ret <2 x i1> [[CMP]]
     51 ;
     52   %cmp = icmp sge <2 x i8> %x, <i8 0, i8 0>
     53   ret <2 x i1> %cmp
     54 }
     55 
     56 define <2 x i1> @uge_zero(<2 x i8> %x) {
     57 ; CHECK-LABEL: @uge_zero(
     58 ; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true>
     59 ;
     60   %cmp = icmp uge <2 x i8> %x, <i8 0, i8 0>
     61   ret <2 x i1> %cmp
     62 }
     63 
     64 define <2 x i1> @sle_zero(<2 x i8> %x) {
     65 ; CHECK-LABEL: @sle_zero(
     66 ; CHECK-NEXT:    [[CMP:%.*]] = icmp slt <2 x i8> %x, <i8 1, i8 1>
     67 ; CHECK-NEXT:    ret <2 x i1> [[CMP]]
     68 ;
     69   %cmp = icmp sle <2 x i8> %x, <i8 0, i8 0>
     70   ret <2 x i1> %cmp
     71 }
     72 
     73 define <2 x i1> @ule_zero(<2 x i8> %x) {
     74 ; CHECK-LABEL: @ule_zero(
     75 ; CHECK-NEXT:    [[CMP:%.*]] = icmp ult <2 x i8> %x, <i8 1, i8 1>
     76 ; CHECK-NEXT:    ret <2 x i1> [[CMP]]
     77 ;
     78   %cmp = icmp ule <2 x i8> %x, <i8 0, i8 0>
     79   ret <2 x i1> %cmp
     80 }
     81 
     82 ; Weird types are ConstantVectors, not ConstantDataVectors. For an i3 type:
     83 ; Signed min = -4
     84 ; Unsigned min = 0
     85 ; Signed max = 3
     86 ; Unsigned max = 7
     87 
     88 define <3 x i1> @sge_weird(<3 x i3> %x) {
     89 ; CHECK-LABEL: @sge_weird(
     90 ; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt <3 x i3> %x, <i3 -4, i3 2, i3 -1>
     91 ; CHECK-NEXT:    ret <3 x i1> [[CMP]]
     92 ;
     93   %cmp = icmp sge <3 x i3> %x, <i3 -3, i3 -5, i3 0>
     94   ret <3 x i1> %cmp
     95 }
     96 
     97 define <3 x i1> @uge_weird(<3 x i3> %x) {
     98 ; CHECK-LABEL: @uge_weird(
     99 ; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt <3 x i3> %x, <i3 -2, i3 0, i3 1>
    100 ; CHECK-NEXT:    ret <3 x i1> [[CMP]]
    101 ;
    102   %cmp = icmp uge <3 x i3> %x, <i3 -1, i3 1, i3 2>
    103   ret <3 x i1> %cmp
    104 }
    105 
    106 define <3 x i1> @sle_weird(<3 x i3> %x) {
    107 ; CHECK-LABEL: @sle_weird(
    108 ; CHECK-NEXT:    [[CMP:%.*]] = icmp slt <3 x i3> %x, <i3 3, i3 -3, i3 1>
    109 ; CHECK-NEXT:    ret <3 x i1> [[CMP]]
    110 ;
    111   %cmp = icmp sle <3 x i3> %x, <i3 2, i3 4, i3 0>
    112   ret <3 x i1> %cmp
    113 }
    114 
    115 define <3 x i1> @ule_weird(<3 x i3> %x) {
    116 ; CHECK-LABEL: @ule_weird(
    117 ; CHECK-NEXT:    [[CMP:%.*]] = icmp ult <3 x i3> %x, <i3 -1, i3 1, i3 2>
    118 ; CHECK-NEXT:    ret <3 x i1> [[CMP]]
    119 ;
    120   %cmp = icmp ule <3 x i3> %x, <i3 6, i3 0, i3 1>
    121   ret <3 x i1> %cmp
    122 }
    123 
    124 ; We can't do the transform if any constants are already at the limits.
    125 
    126 define <2 x i1> @sge_min(<2 x i3> %x) {
    127 ; CHECK-LABEL: @sge_min(
    128 ; CHECK-NEXT:    [[CMP:%.*]] = icmp sge <2 x i3> %x, <i3 -4, i3 1>
    129 ; CHECK-NEXT:    ret <2 x i1> [[CMP]]
    130 ;
    131   %cmp = icmp sge <2 x i3> %x, <i3 -4, i3 1>
    132   ret <2 x i1> %cmp
    133 }
    134 
    135 define <2 x i1> @uge_min(<2 x i3> %x) {
    136 ; CHECK-LABEL: @uge_min(
    137 ; CHECK-NEXT:    [[CMP:%.*]] = icmp uge <2 x i3> %x, <i3 1, i3 0>
    138 ; CHECK-NEXT:    ret <2 x i1> [[CMP]]
    139 ;
    140   %cmp = icmp uge <2 x i3> %x, <i3 1, i3 0>
    141   ret <2 x i1> %cmp
    142 }
    143 
    144 define <2 x i1> @sle_max(<2 x i3> %x) {
    145 ; CHECK-LABEL: @sle_max(
    146 ; CHECK-NEXT:    [[CMP:%.*]] = icmp sle <2 x i3> %x, <i3 1, i3 3>
    147 ; CHECK-NEXT:    ret <2 x i1> [[CMP]]
    148 ;
    149   %cmp = icmp sle <2 x i3> %x, <i3 1, i3 3>
    150   ret <2 x i1> %cmp
    151 }
    152 
    153 define <2 x i1> @ule_max(<2 x i3> %x) {
    154 ; CHECK-LABEL: @ule_max(
    155 ; CHECK-NEXT:    [[CMP:%.*]] = icmp ule <2 x i3> %x, <i3 -1, i3 1>
    156 ; CHECK-NEXT:    ret <2 x i1> [[CMP]]
    157 ;
    158   %cmp = icmp ule <2 x i3> %x, <i3 7, i3 1>
    159   ret <2 x i1> %cmp
    160 }
    161 
    162 ; If we can't determine if a constant element is min/max (eg, it's a ConstantExpr), do nothing.
    163 
    164 define <2 x i1> @PR27756_1(<2 x i8> %a) {
    165 ; CHECK-LABEL: @PR27756_1(
    166 ; CHECK-NEXT:    [[CMP:%.*]] = icmp sle <2 x i8> %a, <i8 bitcast (<2 x i4> <i4 1, i4 2> to i8), i8 0>
    167 ; CHECK-NEXT:    ret <2 x i1> [[CMP]]
    168 ;
    169   %cmp = icmp sle <2 x i8> %a, <i8 bitcast (<2 x i4> <i4 1, i4 2> to i8), i8 0>
    170   ret <2 x i1> %cmp
    171 }
    172 
    173 ; Undef elements don't prevent the transform of the comparison.
    174 
    175 define <2 x i1> @PR27756_2(<2 x i8> %a) {
    176 ; CHECK-LABEL: @PR27756_2(
    177 ; CHECK-NEXT:    [[CMP:%.*]] = icmp slt <2 x i8> %a, <i8 undef, i8 1>
    178 ; CHECK-NEXT:    ret <2 x i1> [[CMP]]
    179 ;
    180   %cmp = icmp sle <2 x i8> %a, <i8 undef, i8 0>
    181   ret <2 x i1> %cmp
    182 }
    183 
    184 @someglobal = global i32 0
    185 
    186 define <2 x i1> @PR27786(<2 x i8> %a) {
    187 ; CHECK-LABEL: @PR27786(
    188 ; CHECK-NEXT:    [[CMP:%.*]] = icmp sle <2 x i8> %a, bitcast (i16 ptrtoint (i32* @someglobal to i16) to <2 x i8>)
    189 ; CHECK-NEXT:    ret <2 x i1> [[CMP]]
    190 ;
    191   %cmp = icmp sle <2 x i8> %a, bitcast (i16 ptrtoint (i32* @someglobal to i16) to <2 x i8>)
    192   ret <2 x i1> %cmp
    193 }
    194