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 9define <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 18define <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 27define <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 36define <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 45define <2 x i1> @ult_min_signed_value(<2 x i8> %x) { 46; CHECK-LABEL: @ult_min_signed_value( 47; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[X:%.*]], <i8 -1, i8 -1> 48; CHECK-NEXT: ret <2 x i1> [[CMP]] 49; 50 %cmp = icmp ult <2 x i8> %x, <i8 128, i8 128> 51 ret <2 x i1> %cmp 52} 53 54; Zeros are special: they're ConstantAggregateZero. 55 56define <2 x i1> @sge_zero(<2 x i8> %x) { 57; CHECK-LABEL: @sge_zero( 58; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[X:%.*]], <i8 -1, i8 -1> 59; CHECK-NEXT: ret <2 x i1> [[CMP]] 60; 61 %cmp = icmp sge <2 x i8> %x, <i8 0, i8 0> 62 ret <2 x i1> %cmp 63} 64 65define <2 x i1> @uge_zero(<2 x i8> %x) { 66; CHECK-LABEL: @uge_zero( 67; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true> 68; 69 %cmp = icmp uge <2 x i8> %x, <i8 0, i8 0> 70 ret <2 x i1> %cmp 71} 72 73define <2 x i1> @sle_zero(<2 x i8> %x) { 74; CHECK-LABEL: @sle_zero( 75; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[X:%.*]], <i8 1, i8 1> 76; CHECK-NEXT: ret <2 x i1> [[CMP]] 77; 78 %cmp = icmp sle <2 x i8> %x, <i8 0, i8 0> 79 ret <2 x i1> %cmp 80} 81 82define <2 x i1> @ule_zero(<2 x i8> %x) { 83; CHECK-LABEL: @ule_zero( 84; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i8> [[X:%.*]], zeroinitializer 85; CHECK-NEXT: ret <2 x i1> [[CMP]] 86; 87 %cmp = icmp ule <2 x i8> %x, <i8 0, i8 0> 88 ret <2 x i1> %cmp 89} 90 91; Weird types are ConstantVectors, not ConstantDataVectors. For an i3 type: 92; Signed min = -4 93; Unsigned min = 0 94; Signed max = 3 95; Unsigned max = 7 96 97define <3 x i1> @sge_weird(<3 x i3> %x) { 98; CHECK-LABEL: @sge_weird( 99; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <3 x i3> [[X:%.*]], <i3 -4, i3 2, i3 -1> 100; CHECK-NEXT: ret <3 x i1> [[CMP]] 101; 102 %cmp = icmp sge <3 x i3> %x, <i3 -3, i3 -5, i3 0> 103 ret <3 x i1> %cmp 104} 105 106define <3 x i1> @uge_weird(<3 x i3> %x) { 107; CHECK-LABEL: @uge_weird( 108; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <3 x i3> [[X:%.*]], <i3 -2, i3 0, i3 1> 109; CHECK-NEXT: ret <3 x i1> [[CMP]] 110; 111 %cmp = icmp uge <3 x i3> %x, <i3 -1, i3 1, i3 2> 112 ret <3 x i1> %cmp 113} 114 115define <3 x i1> @sle_weird(<3 x i3> %x) { 116; CHECK-LABEL: @sle_weird( 117; CHECK-NEXT: [[CMP:%.*]] = icmp slt <3 x i3> [[X:%.*]], <i3 3, i3 -3, i3 1> 118; CHECK-NEXT: ret <3 x i1> [[CMP]] 119; 120 %cmp = icmp sle <3 x i3> %x, <i3 2, i3 4, i3 0> 121 ret <3 x i1> %cmp 122} 123 124define <3 x i1> @ule_weird(<3 x i3> %x) { 125; CHECK-LABEL: @ule_weird( 126; CHECK-NEXT: [[CMP:%.*]] = icmp ult <3 x i3> [[X:%.*]], <i3 -1, i3 1, i3 2> 127; CHECK-NEXT: ret <3 x i1> [[CMP]] 128; 129 %cmp = icmp ule <3 x i3> %x, <i3 6, i3 0, i3 1> 130 ret <3 x i1> %cmp 131} 132 133; We can't do the transform if any constants are already at the limits. 134 135define <2 x i1> @sge_min(<2 x i3> %x) { 136; CHECK-LABEL: @sge_min( 137; CHECK-NEXT: [[CMP:%.*]] = icmp sge <2 x i3> [[X:%.*]], <i3 -4, i3 1> 138; CHECK-NEXT: ret <2 x i1> [[CMP]] 139; 140 %cmp = icmp sge <2 x i3> %x, <i3 -4, i3 1> 141 ret <2 x i1> %cmp 142} 143 144define <2 x i1> @uge_min(<2 x i3> %x) { 145; CHECK-LABEL: @uge_min( 146; CHECK-NEXT: [[CMP:%.*]] = icmp uge <2 x i3> [[X:%.*]], <i3 1, i3 0> 147; CHECK-NEXT: ret <2 x i1> [[CMP]] 148; 149 %cmp = icmp uge <2 x i3> %x, <i3 1, i3 0> 150 ret <2 x i1> %cmp 151} 152 153define <2 x i1> @sle_max(<2 x i3> %x) { 154; CHECK-LABEL: @sle_max( 155; CHECK-NEXT: [[CMP:%.*]] = icmp sle <2 x i3> [[X:%.*]], <i3 1, i3 3> 156; CHECK-NEXT: ret <2 x i1> [[CMP]] 157; 158 %cmp = icmp sle <2 x i3> %x, <i3 1, i3 3> 159 ret <2 x i1> %cmp 160} 161 162define <2 x i1> @ule_max(<2 x i3> %x) { 163; CHECK-LABEL: @ule_max( 164; CHECK-NEXT: [[CMP:%.*]] = icmp ule <2 x i3> [[X:%.*]], <i3 -1, i3 1> 165; CHECK-NEXT: ret <2 x i1> [[CMP]] 166; 167 %cmp = icmp ule <2 x i3> %x, <i3 7, i3 1> 168 ret <2 x i1> %cmp 169} 170 171define <2 x i1> @PR27756_1(<2 x i8> %a) { 172; CHECK-LABEL: @PR27756_1( 173; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[A:%.*]], <i8 34, i8 1> 174; CHECK-NEXT: ret <2 x i1> [[CMP]] 175; 176 %cmp = icmp sle <2 x i8> %a, <i8 bitcast (<2 x i4> <i4 1, i4 2> to i8), i8 0> 177 ret <2 x i1> %cmp 178} 179 180; Undef elements don't prevent the transform of the comparison. 181 182define <2 x i1> @PR27756_2(<2 x i8> %a) { 183; CHECK-LABEL: @PR27756_2( 184; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[A:%.*]], <i8 undef, i8 1> 185; CHECK-NEXT: ret <2 x i1> [[CMP]] 186; 187 %cmp = icmp sle <2 x i8> %a, <i8 undef, i8 0> 188 ret <2 x i1> %cmp 189} 190 191@someglobal = global i32 0 192 193define <2 x i1> @PR27786(<2 x i8> %a) { 194; CHECK-LABEL: @PR27786( 195; CHECK-NEXT: [[CMP:%.*]] = icmp sle <2 x i8> [[A:%.*]], bitcast (i16 ptrtoint (i32* @someglobal to i16) to <2 x i8>) 196; CHECK-NEXT: ret <2 x i1> [[CMP]] 197; 198 %cmp = icmp sle <2 x i8> %a, bitcast (i16 ptrtoint (i32* @someglobal to i16) to <2 x i8>) 199 ret <2 x i1> %cmp 200} 201 202; FIXME: 203; This is similar to a transform for shuffled binops: compare first, shuffle after. 204 205define <4 x i1> @same_shuffle_inputs_icmp(<4 x i8> %x, <4 x i8> %y) { 206; CHECK-LABEL: @same_shuffle_inputs_icmp( 207; CHECK-NEXT: [[SHUFX:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> undef, <4 x i32> <i32 3, i32 3, i32 2, i32 0> 208; CHECK-NEXT: [[SHUFY:%.*]] = shufflevector <4 x i8> [[Y:%.*]], <4 x i8> undef, <4 x i32> <i32 3, i32 3, i32 2, i32 0> 209; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <4 x i8> [[SHUFX]], [[SHUFY]] 210; CHECK-NEXT: ret <4 x i1> [[CMP]] 211; 212 %shufx = shufflevector <4 x i8> %x, <4 x i8> undef, <4 x i32> < i32 3, i32 3, i32 2, i32 0 > 213 %shufy = shufflevector <4 x i8> %y, <4 x i8> undef, <4 x i32> < i32 3, i32 3, i32 2, i32 0 > 214 %cmp = icmp sgt <4 x i8> %shufx, %shufy 215 ret <4 x i1> %cmp 216} 217 218; fcmp and size-changing shuffles are ok too. 219 220define <5 x i1> @same_shuffle_inputs_fcmp(<4 x float> %x, <4 x float> %y) { 221; CHECK-LABEL: @same_shuffle_inputs_fcmp( 222; CHECK-NEXT: [[SHUFX:%.*]] = shufflevector <4 x float> [[X:%.*]], <4 x float> undef, <5 x i32> <i32 0, i32 1, i32 3, i32 2, i32 0> 223; CHECK-NEXT: [[SHUFY:%.*]] = shufflevector <4 x float> [[Y:%.*]], <4 x float> undef, <5 x i32> <i32 0, i32 1, i32 3, i32 2, i32 0> 224; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq <5 x float> [[SHUFX]], [[SHUFY]] 225; CHECK-NEXT: ret <5 x i1> [[CMP]] 226; 227 %shufx = shufflevector <4 x float> %x, <4 x float> undef, <5 x i32> < i32 0, i32 1, i32 3, i32 2, i32 0 > 228 %shufy = shufflevector <4 x float> %y, <4 x float> undef, <5 x i32> < i32 0, i32 1, i32 3, i32 2, i32 0 > 229 %cmp = fcmp oeq <5 x float> %shufx, %shufy 230 ret <5 x i1> %cmp 231} 232 233declare void @use_v4i8(<4 x i8>) 234 235define <4 x i1> @same_shuffle_inputs_icmp_extra_use1(<4 x i8> %x, <4 x i8> %y) { 236; CHECK-LABEL: @same_shuffle_inputs_icmp_extra_use1( 237; CHECK-NEXT: [[SHUFX:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> undef, <4 x i32> <i32 3, i32 3, i32 3, i32 3> 238; CHECK-NEXT: [[SHUFY:%.*]] = shufflevector <4 x i8> [[Y:%.*]], <4 x i8> undef, <4 x i32> <i32 3, i32 3, i32 3, i32 3> 239; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <4 x i8> [[SHUFX]], [[SHUFY]] 240; CHECK-NEXT: call void @use_v4i8(<4 x i8> [[SHUFX]]) 241; CHECK-NEXT: ret <4 x i1> [[CMP]] 242; 243 %shufx = shufflevector <4 x i8> %x, <4 x i8> undef, <4 x i32> < i32 3, i32 3, i32 3, i32 3 > 244 %shufy = shufflevector <4 x i8> %y, <4 x i8> undef, <4 x i32> < i32 3, i32 3, i32 3, i32 3 > 245 %cmp = icmp ugt <4 x i8> %shufx, %shufy 246 call void @use_v4i8(<4 x i8> %shufx) 247 ret <4 x i1> %cmp 248} 249 250declare void @use_v2i8(<2 x i8>) 251 252define <2 x i1> @same_shuffle_inputs_icmp_extra_use2(<4 x i8> %x, <4 x i8> %y) { 253; CHECK-LABEL: @same_shuffle_inputs_icmp_extra_use2( 254; CHECK-NEXT: [[SHUFX:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> undef, <2 x i32> <i32 3, i32 2> 255; CHECK-NEXT: [[SHUFY:%.*]] = shufflevector <4 x i8> [[Y:%.*]], <4 x i8> undef, <2 x i32> <i32 3, i32 2> 256; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i8> [[SHUFX]], [[SHUFY]] 257; CHECK-NEXT: call void @use_v2i8(<2 x i8> [[SHUFY]]) 258; CHECK-NEXT: ret <2 x i1> [[CMP]] 259; 260 %shufx = shufflevector <4 x i8> %x, <4 x i8> undef, <2 x i32> < i32 3, i32 2 > 261 %shufy = shufflevector <4 x i8> %y, <4 x i8> undef, <2 x i32> < i32 3, i32 2 > 262 %cmp = icmp eq <2 x i8> %shufx, %shufy 263 call void @use_v2i8(<2 x i8> %shufy) 264 ret <2 x i1> %cmp 265} 266 267; Negative test: if both shuffles have extra uses, don't transform because that would increase instruction count. 268 269define <2 x i1> @same_shuffle_inputs_icmp_extra_use3(<4 x i8> %x, <4 x i8> %y) { 270; CHECK-LABEL: @same_shuffle_inputs_icmp_extra_use3( 271; CHECK-NEXT: [[SHUFX:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> undef, <2 x i32> zeroinitializer 272; CHECK-NEXT: [[SHUFY:%.*]] = shufflevector <4 x i8> [[Y:%.*]], <4 x i8> undef, <2 x i32> zeroinitializer 273; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i8> [[SHUFX]], [[SHUFY]] 274; CHECK-NEXT: call void @use_v2i8(<2 x i8> [[SHUFX]]) 275; CHECK-NEXT: call void @use_v2i8(<2 x i8> [[SHUFY]]) 276; CHECK-NEXT: ret <2 x i1> [[CMP]] 277; 278 %shufx = shufflevector <4 x i8> %x, <4 x i8> undef, <2 x i32> < i32 0, i32 0 > 279 %shufy = shufflevector <4 x i8> %y, <4 x i8> undef, <2 x i32> < i32 0, i32 0 > 280 %cmp = icmp eq <2 x i8> %shufx, %shufy 281 call void @use_v2i8(<2 x i8> %shufx) 282 call void @use_v2i8(<2 x i8> %shufy) 283 ret <2 x i1> %cmp 284} 285 286