357 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4; If the (shl x, C) preserved the sign and this is a sign test,5; compare the LHS operand instead6 7define i1 @icmp_shl_nsw_sgt(i32 %x) {8; CHECK-LABEL: @icmp_shl_nsw_sgt(9; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], 010; CHECK-NEXT: ret i1 [[CMP]]11;12 %shl = shl nsw i32 %x, 2113 %cmp = icmp sgt i32 %shl, 014 ret i1 %cmp15}16 17define i1 @icmp_shl_nsw_sge0(i32 %x) {18; CHECK-LABEL: @icmp_shl_nsw_sge0(19; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], -120; CHECK-NEXT: ret i1 [[CMP]]21;22 %shl = shl nsw i32 %x, 2123 %cmp = icmp sge i32 %shl, 024 ret i1 %cmp25}26 27define i1 @icmp_shl_nsw_sge1(i32 %x) {28; CHECK-LABEL: @icmp_shl_nsw_sge1(29; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], 030; CHECK-NEXT: ret i1 [[CMP]]31;32 %shl = shl nsw i32 %x, 2133 %cmp = icmp sge i32 %shl, 134 ret i1 %cmp35}36 37define <2 x i1> @icmp_shl_nsw_sge1_vec(<2 x i32> %x) {38; CHECK-LABEL: @icmp_shl_nsw_sge1_vec(39; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> [[X:%.*]], zeroinitializer40; CHECK-NEXT: ret <2 x i1> [[CMP]]41;42 %shl = shl nsw <2 x i32> %x, <i32 21, i32 21>43 %cmp = icmp sge <2 x i32> %shl, <i32 1, i32 1>44 ret <2 x i1> %cmp45}46 47; Checks for icmp (eq|ne) (shl x, C), 048 49define i1 @icmp_shl_nsw_eq(i32 %x) {50; CHECK-LABEL: @icmp_shl_nsw_eq(51; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], 052; CHECK-NEXT: ret i1 [[CMP]]53;54 %mul = shl nsw i32 %x, 555 %cmp = icmp eq i32 %mul, 056 ret i1 %cmp57}58 59define <2 x i1> @icmp_shl_nsw_eq_vec(<2 x i32> %x) {60; CHECK-LABEL: @icmp_shl_nsw_eq_vec(61; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[X:%.*]], zeroinitializer62; CHECK-NEXT: ret <2 x i1> [[CMP]]63;64 %mul = shl nsw <2 x i32> %x, <i32 5, i32 5>65 %cmp = icmp eq <2 x i32> %mul, zeroinitializer66 ret <2 x i1> %cmp67}68 69; icmp sgt with shl nsw with a constant compare operand and constant70; shift amount can always be reduced to icmp sgt alone.71 72; Known bits analysis turns this into an equality predicate.73 74define i1 @icmp_sgt1(i8 %x) {75; CHECK-LABEL: @icmp_sgt1(76; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X:%.*]], -6477; CHECK-NEXT: ret i1 [[CMP]]78;79 %shl = shl nsw i8 %x, 180 %cmp = icmp sgt i8 %shl, -12881 ret i1 %cmp82}83 84define i1 @icmp_sgt2(i8 %x) {85; CHECK-LABEL: @icmp_sgt2(86; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -6487; CHECK-NEXT: ret i1 [[CMP]]88;89 %shl = shl nsw i8 %x, 190 %cmp = icmp sgt i8 %shl, -12791 ret i1 %cmp92}93 94define i1 @icmp_sgt3(i8 %x) {95; CHECK-LABEL: @icmp_sgt3(96; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -897; CHECK-NEXT: ret i1 [[CMP]]98;99 %shl = shl nsw i8 %x, 1100 %cmp = icmp sgt i8 %shl, -16101 ret i1 %cmp102}103 104define i1 @icmp_sgt4(i8 %x) {105; CHECK-LABEL: @icmp_sgt4(106; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -1107; CHECK-NEXT: ret i1 [[CMP]]108;109 %shl = shl nsw i8 %x, 1110 %cmp = icmp sgt i8 %shl, -2111 ret i1 %cmp112}113 114; x >s -1 is a sign bit test.115; x >s 0 is a sign bit test.116 117define i1 @icmp_sgt5(i8 %x) {118; CHECK-LABEL: @icmp_sgt5(119; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], 0120; CHECK-NEXT: ret i1 [[CMP]]121;122 %shl = shl nsw i8 %x, 1123 %cmp = icmp sgt i8 %shl, 1124 ret i1 %cmp125}126 127define i1 @icmp_sgt6(i8 %x) {128; CHECK-LABEL: @icmp_sgt6(129; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], 8130; CHECK-NEXT: ret i1 [[CMP]]131;132 %shl = shl nsw i8 %x, 1133 %cmp = icmp sgt i8 %shl, 16134 ret i1 %cmp135}136 137define i1 @icmp_sgt7(i8 %x) {138; CHECK-LABEL: @icmp_sgt7(139; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], 62140; CHECK-NEXT: ret i1 [[CMP]]141;142 %shl = shl nsw i8 %x, 1143 %cmp = icmp sgt i8 %shl, 124144 ret i1 %cmp145}146 147; Known bits analysis turns this into an equality predicate.148 149define i1 @icmp_sgt8(i8 %x) {150; CHECK-LABEL: @icmp_sgt8(151; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], 63152; CHECK-NEXT: ret i1 [[CMP]]153;154 %shl = shl nsw i8 %x, 1155 %cmp = icmp sgt i8 %shl, 125156 ret i1 %cmp157}158 159; Compares with 126 and 127 are recognized as always false.160 161; Known bits analysis turns this into an equality predicate.162 163define i1 @icmp_sgt9(i8 %x) {164; CHECK-LABEL: @icmp_sgt9(165; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], 0166; CHECK-NEXT: ret i1 [[CMP]]167;168 %shl = shl nsw i8 %x, 7169 %cmp = icmp sgt i8 %shl, -128170 ret i1 %cmp171}172 173define i1 @icmp_sgt10(i8 %x) {174; CHECK-LABEL: @icmp_sgt10(175; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -1176; CHECK-NEXT: ret i1 [[CMP]]177;178 %shl = shl nsw i8 %x, 7179 %cmp = icmp sgt i8 %shl, -127180 ret i1 %cmp181}182 183define i1 @icmp_sgt11(i8 %x) {184; CHECK-LABEL: @icmp_sgt11(185; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -1186; CHECK-NEXT: ret i1 [[CMP]]187;188 %shl = shl nsw i8 %x, 7189 %cmp = icmp sgt i8 %shl, -2190 ret i1 %cmp191}192 193; Splat vector version should fold the same way.194 195define <2 x i1> @icmp_sgt11_vec(<2 x i8> %x) {196; CHECK-LABEL: @icmp_sgt11_vec(197; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[X:%.*]], splat (i8 -1)198; CHECK-NEXT: ret <2 x i1> [[CMP]]199;200 %shl = shl nsw <2 x i8> %x, <i8 7, i8 7>201 %cmp = icmp sgt <2 x i8> %shl, <i8 -2, i8 -2>202 ret <2 x i1> %cmp203}204 205; Known bits analysis returns false for compares with >=0.206 207;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;208;209; Repeat the shl nsw + sgt tests with predicate changed to 'sle'.210;211;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;212 213; Known bits analysis turns this into an equality predicate.214 215define i1 @icmp_sle1(i8 %x) {216; CHECK-LABEL: @icmp_sle1(217; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], -64218; CHECK-NEXT: ret i1 [[CMP]]219;220 %shl = shl nsw i8 %x, 1221 %cmp = icmp sle i8 %shl, -128222 ret i1 %cmp223}224 225define i1 @icmp_sle2(i8 %x) {226; CHECK-LABEL: @icmp_sle2(227; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], -63228; CHECK-NEXT: ret i1 [[CMP]]229;230 %shl = shl nsw i8 %x, 1231 %cmp = icmp sle i8 %shl, -127232 ret i1 %cmp233}234 235define i1 @icmp_sle3(i8 %x) {236; CHECK-LABEL: @icmp_sle3(237; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], -7238; CHECK-NEXT: ret i1 [[CMP]]239;240 %shl = shl nsw i8 %x, 1241 %cmp = icmp sle i8 %shl, -16242 ret i1 %cmp243}244 245define i1 @icmp_sle4(i8 %x) {246; CHECK-LABEL: @icmp_sle4(247; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0248; CHECK-NEXT: ret i1 [[CMP]]249;250 %shl = shl nsw i8 %x, 1251 %cmp = icmp sle i8 %shl, -2252 ret i1 %cmp253}254 255; x <=s -1 is a sign bit test.256; x <=s 0 is a sign bit test.257 258define i1 @icmp_sle5(i8 %x) {259; CHECK-LABEL: @icmp_sle5(260; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 1261; CHECK-NEXT: ret i1 [[CMP]]262;263 %shl = shl nsw i8 %x, 1264 %cmp = icmp sle i8 %shl, 1265 ret i1 %cmp266}267 268define i1 @icmp_sle6(i8 %x) {269; CHECK-LABEL: @icmp_sle6(270; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 9271; CHECK-NEXT: ret i1 [[CMP]]272;273 %shl = shl nsw i8 %x, 1274 %cmp = icmp sle i8 %shl, 16275 ret i1 %cmp276}277 278define i1 @icmp_sle7(i8 %x) {279; CHECK-LABEL: @icmp_sle7(280; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 63281; CHECK-NEXT: ret i1 [[CMP]]282;283 %shl = shl nsw i8 %x, 1284 %cmp = icmp sle i8 %shl, 124285 ret i1 %cmp286}287 288; Known bits analysis turns this into an equality predicate.289 290define i1 @icmp_sle8(i8 %x) {291; CHECK-LABEL: @icmp_sle8(292; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X:%.*]], 63293; CHECK-NEXT: ret i1 [[CMP]]294;295 %shl = shl nsw i8 %x, 1296 %cmp = icmp sle i8 %shl, 125297 ret i1 %cmp298}299 300; Compares with 126 and 127 are recognized as always true.301 302; Known bits analysis turns this into an equality predicate.303 304define i1 @icmp_sle9(i8 %x) {305; CHECK-LABEL: @icmp_sle9(306; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X:%.*]], 0307; CHECK-NEXT: ret i1 [[CMP]]308;309 %shl = shl nsw i8 %x, 7310 %cmp = icmp sle i8 %shl, -128311 ret i1 %cmp312}313 314define i1 @icmp_sle10(i8 %x) {315; CHECK-LABEL: @icmp_sle10(316; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0317; CHECK-NEXT: ret i1 [[CMP]]318;319 %shl = shl nsw i8 %x, 7320 %cmp = icmp sle i8 %shl, -127321 ret i1 %cmp322}323 324define i1 @icmp_sle11(i8 %x) {325; CHECK-LABEL: @icmp_sle11(326; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0327; CHECK-NEXT: ret i1 [[CMP]]328;329 %shl = shl nsw i8 %x, 7330 %cmp = icmp sle i8 %shl, -2331 ret i1 %cmp332}333 334; Some of the earlier sgt/sle tests are transformed to eq/ne, but try a couple335; of those explicitly, so we know no intermediate transforms are necessary.336 337define i1 @icmp_eq1(i8 %x) {338; CHECK-LABEL: @icmp_eq1(339; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], 6340; CHECK-NEXT: ret i1 [[CMP]]341;342 %shl = shl nsw i8 %x, 1343 %cmp = icmp eq i8 %shl, 12344 ret i1 %cmp345}346 347define i1 @icmp_ne1(i8 %x) {348; CHECK-LABEL: @icmp_ne1(349; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X:%.*]], -2350; CHECK-NEXT: ret i1 [[CMP]]351;352 %shl = shl nsw i8 %x, 6353 %cmp = icmp ne i8 %shl, -128354 ret i1 %cmp355}356 357