824 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S -data-layout="n8:16:32:64" | FileCheck %s --check-prefixes=CHECK,DL643; RUN: opt < %s -passes=instcombine -S -data-layout="n8" | FileCheck %s --check-prefixes=CHECK,DL84 5declare void @use(i8)6declare void @use2(i4)7 8define i1 @ult_2(i32 %x) {9; CHECK-LABEL: @ult_2(10; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 25411; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[TMP1]], 012; CHECK-NEXT: ret i1 [[R]]13;14 %t = trunc i32 %x to i815 %r = icmp ult i8 %t, 216 ret i1 %r17}18 19define <2 x i1> @ult_16_splat(<2 x i16> %x) {20; CHECK-LABEL: @ult_16_splat(21; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i16> [[X:%.*]], splat (i16 2032)22; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i16> [[TMP1]], zeroinitializer23; CHECK-NEXT: ret <2 x i1> [[R]]24;25 %t = trunc <2 x i16> %x to <2 x i11>26 %r = icmp ult <2 x i11> %t, <i11 16, i11 16>27 ret <2 x i1> %r28}29 30; negative test - need power-of-2 constant31 32define i1 @ult_3(i32 %x) {33; CHECK-LABEL: @ult_3(34; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i835; CHECK-NEXT: [[R:%.*]] = icmp ult i8 [[T]], 336; CHECK-NEXT: ret i1 [[R]]37;38 %t = trunc i32 %x to i839 %r = icmp ult i8 %t, 340 ret i1 %r41}42 43; negative test - no extra use allowed44 45define i1 @ult_2_use(i32 %x) {46; CHECK-LABEL: @ult_2_use(47; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i848; CHECK-NEXT: call void @use(i8 [[T]])49; CHECK-NEXT: [[R:%.*]] = icmp ult i8 [[T]], 250; CHECK-NEXT: ret i1 [[R]]51;52 %t = trunc i32 %x to i853 call void @use(i8 %t)54 %r = icmp ult i8 %t, 255 ret i1 %r56}57 58@a = internal unnamed_addr constant [3 x i32] [i32 0, i32 0, i32 1], align 459 60define i1 @PR52260(i32 %x) {61; CHECK-LABEL: @PR52260(62; CHECK-NEXT: ret i1 true63;64 %idxprom = sext i32 %x to i6465 %idx = getelementptr inbounds [3 x i32], ptr @a, i64 0, i64 %idxprom66 %t1 = load i32, ptr %idx, align 467 %conv1 = lshr i32 %t1, 168 %t2 = trunc i32 %conv1 to i869 %conv2 = and i8 %t2, 12770 %tobool = icmp eq i8 %conv2, 071 ret i1 %tobool72}73 74define i1 @ult_192(i32 %x) {75; CHECK-LABEL: @ult_192(76; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 19277; CHECK-NEXT: [[R:%.*]] = icmp ne i32 [[TMP1]], 19278; CHECK-NEXT: ret i1 [[R]]79;80 %t = trunc i32 %x to i881 %r = icmp ult i8 %t, 192 ; 0b1100_000082 ret i1 %r83}84 85define <2 x i1> @ult_2044_splat(<2 x i16> %x) {86; CHECK-LABEL: @ult_2044_splat(87; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i16> [[X:%.*]], splat (i16 2044)88; CHECK-NEXT: [[R:%.*]] = icmp ne <2 x i16> [[TMP1]], splat (i16 2044)89; CHECK-NEXT: ret <2 x i1> [[R]]90;91 %t = trunc <2 x i16> %x to <2 x i11>92 %r = icmp ult <2 x i11> %t, <i11 2044, i11 2044> ; 0b111_1111_110093 ret <2 x i1> %r94}95 96; negative test - need high-bit-mask constant97 98define i1 @ult_96(i32 %x) {99; CHECK-LABEL: @ult_96(100; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8101; CHECK-NEXT: [[R:%.*]] = icmp ult i8 [[T]], 96102; CHECK-NEXT: ret i1 [[R]]103;104 %t = trunc i32 %x to i8105 %r = icmp ult i8 %t, 96 ; 0b0110_0000106 ret i1 %r107}108 109; negative test - no extra use allowed110 111define i1 @ult_192_use(i32 %x) {112; CHECK-LABEL: @ult_192_use(113; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8114; CHECK-NEXT: call void @use(i8 [[T]])115; CHECK-NEXT: [[R:%.*]] = icmp ult i8 [[T]], -64116; CHECK-NEXT: ret i1 [[R]]117;118 %t = trunc i32 %x to i8119 call void @use(i8 %t)120 %r = icmp ult i8 %t, 192121 ret i1 %r122}123 124define i1 @ugt_3(i32 %x) {125; CHECK-LABEL: @ugt_3(126; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 252127; CHECK-NEXT: [[R:%.*]] = icmp ne i32 [[TMP1]], 0128; CHECK-NEXT: ret i1 [[R]]129;130 %t = trunc i32 %x to i8131 %r = icmp ugt i8 %t, 3132 ret i1 %r133}134 135define <2 x i1> @ugt_7_splat(<2 x i16> %x) {136; CHECK-LABEL: @ugt_7_splat(137; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i16> [[X:%.*]], splat (i16 2040)138; CHECK-NEXT: [[R:%.*]] = icmp ne <2 x i16> [[TMP1]], zeroinitializer139; CHECK-NEXT: ret <2 x i1> [[R]]140;141 %t = trunc <2 x i16> %x to <2 x i11>142 %r = icmp ugt <2 x i11> %t, <i11 7, i11 7>143 ret <2 x i1> %r144}145 146; negative test - need low-bit-mask constant147 148define i1 @ugt_4(i32 %x) {149; CHECK-LABEL: @ugt_4(150; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8151; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[T]], 4152; CHECK-NEXT: ret i1 [[R]]153;154 %t = trunc i32 %x to i8155 %r = icmp ugt i8 %t, 4156 ret i1 %r157}158 159; negative test - no extra use allowed160 161define i1 @ugt_3_use(i32 %x) {162; CHECK-LABEL: @ugt_3_use(163; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8164; CHECK-NEXT: call void @use(i8 [[T]])165; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[T]], 3166; CHECK-NEXT: ret i1 [[R]]167;168 %t = trunc i32 %x to i8169 call void @use(i8 %t)170 %r = icmp ugt i8 %t, 3171 ret i1 %r172}173 174define i1 @ugt_253(i32 %x) {175; CHECK-LABEL: @ugt_253(176; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 254177; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[TMP1]], 254178; CHECK-NEXT: ret i1 [[R]]179;180 %t = trunc i32 %x to i8181 %r = icmp ugt i8 %t, 253182 ret i1 %r183}184 185define <2 x i1> @ugt_2043_splat(<2 x i16> %x) {186; CHECK-LABEL: @ugt_2043_splat(187; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i16> [[X:%.*]], splat (i16 2044)188; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i16> [[TMP1]], splat (i16 2044)189; CHECK-NEXT: ret <2 x i1> [[R]]190;191 %t = trunc <2 x i16> %x to <2 x i11>192 %r = icmp ugt <2 x i11> %t, <i11 2043, i11 2043> ; 0b111_1111_101193 ret <2 x i1> %r194}195 196; negative test - need not-of-power-of-2 constant197 198define i1 @ugt_252(i32 %x) {199; CHECK-LABEL: @ugt_252(200; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8201; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[T]], -4202; CHECK-NEXT: ret i1 [[R]]203;204 %t = trunc i32 %x to i8205 %r = icmp ugt i8 %t, 252206 ret i1 %r207}208 209; negative test - no extra use allowed210 211define i1 @ugt_253_use(i32 %x) {212; CHECK-LABEL: @ugt_253_use(213; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8214; CHECK-NEXT: call void @use(i8 [[T]])215; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[T]], -3216; CHECK-NEXT: ret i1 [[R]]217;218 %t = trunc i32 %x to i8219 call void @use(i8 %t)220 %r = icmp ugt i8 %t, 253221 ret i1 %r222}223 224define i1 @slt_0(i32 %x) {225; CHECK-LABEL: @slt_0(226; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 128227; CHECK-NEXT: [[R:%.*]] = icmp ne i32 [[TMP1]], 0228; CHECK-NEXT: ret i1 [[R]]229;230 %t = trunc i32 %x to i8231 %r = icmp slt i8 %t, 0232 ret i1 %r233}234 235define <2 x i1> @slt_0_splat(<2 x i16> %x) {236; CHECK-LABEL: @slt_0_splat(237; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i16> [[X:%.*]], splat (i16 1024)238; CHECK-NEXT: [[R:%.*]] = icmp ne <2 x i16> [[TMP1]], zeroinitializer239; CHECK-NEXT: ret <2 x i1> [[R]]240;241 %t = trunc <2 x i16> %x to <2 x i11>242 %r = icmp slt <2 x i11> %t, zeroinitializer243 ret <2 x i1> %r244}245 246define i1 @slt_1(i32 %x) {247; CHECK-LABEL: @slt_1(248; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8249; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[T]], 1250; CHECK-NEXT: ret i1 [[R]]251;252 %t = trunc i32 %x to i8253 %r = icmp slt i8 %t, 1254 ret i1 %r255}256 257define i1 @slt_0_use(i32 %x) {258; CHECK-LABEL: @slt_0_use(259; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8260; CHECK-NEXT: call void @use(i8 [[T]])261; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[T]], 0262; CHECK-NEXT: ret i1 [[R]]263;264 %t = trunc i32 %x to i8265 call void @use(i8 %t)266 %r = icmp slt i8 %t, 0267 ret i1 %r268}269 270define i1 @sgt_n1(i32 %x) {271; CHECK-LABEL: @sgt_n1(272; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 128273; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[TMP1]], 0274; CHECK-NEXT: ret i1 [[R]]275;276 %t = trunc i32 %x to i8277 %r = icmp sgt i8 %t, -1278 ret i1 %r279}280 281define <2 x i1> @sgt_n1_splat(<2 x i16> %x) {282; CHECK-LABEL: @sgt_n1_splat(283; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i16> [[X:%.*]], splat (i16 1024)284; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i16> [[TMP1]], zeroinitializer285; CHECK-NEXT: ret <2 x i1> [[R]]286;287 %t = trunc <2 x i16> %x to <2 x i11>288 %r = icmp sgt <2 x i11> %t, <i11 -1, i11 -1>289 ret <2 x i1> %r290}291 292define i1 @sgt_0(i32 %x) {293; CHECK-LABEL: @sgt_0(294; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8295; CHECK-NEXT: [[R:%.*]] = icmp sgt i8 [[T]], 0296; CHECK-NEXT: ret i1 [[R]]297;298 %t = trunc i32 %x to i8299 %r = icmp sgt i8 %t, 0300 ret i1 %r301}302 303define i1 @sgt_n1_use(i32 %x) {304; CHECK-LABEL: @sgt_n1_use(305; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8306; CHECK-NEXT: call void @use(i8 [[T]])307; CHECK-NEXT: [[R:%.*]] = icmp sgt i8 [[T]], -1308; CHECK-NEXT: ret i1 [[R]]309;310 %t = trunc i32 %x to i8311 call void @use(i8 %t)312 %r = icmp sgt i8 %t, -1313 ret i1 %r314}315 316define i1 @trunc_eq_i32_i8(i32 %x) {317; DL64-LABEL: @trunc_eq_i32_i8(318; DL64-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 255319; DL64-NEXT: [[R:%.*]] = icmp eq i32 [[TMP1]], 42320; DL64-NEXT: ret i1 [[R]]321;322; DL8-LABEL: @trunc_eq_i32_i8(323; DL8-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8324; DL8-NEXT: [[R:%.*]] = icmp eq i8 [[T]], 42325; DL8-NEXT: ret i1 [[R]]326;327 %t = trunc i32 %x to i8328 %r = icmp eq i8 %t, 42329 ret i1 %r330}331 332define <2 x i1> @trunc_eq_v2i32_v2i8(<2 x i32> %x) {333; CHECK-LABEL: @trunc_eq_v2i32_v2i8(334; CHECK-NEXT: [[T:%.*]] = trunc <2 x i32> [[X:%.*]] to <2 x i8>335; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i8> [[T]], splat (i8 42)336; CHECK-NEXT: ret <2 x i1> [[R]]337;338 %t = trunc <2 x i32> %x to <2 x i8>339 %r = icmp eq <2 x i8> %t, <i8 42, i8 42>340 ret <2 x i1> %r341}342 343define i1 @trunc_ne_i64_i10(i64 %x) {344; DL64-LABEL: @trunc_ne_i64_i10(345; DL64-NEXT: [[TMP1:%.*]] = and i64 [[X:%.*]], 1023346; DL64-NEXT: [[R:%.*]] = icmp eq i64 [[TMP1]], 42347; DL64-NEXT: ret i1 [[R]]348;349; DL8-LABEL: @trunc_ne_i64_i10(350; DL8-NEXT: [[T:%.*]] = trunc i64 [[X:%.*]] to i10351; DL8-NEXT: [[R:%.*]] = icmp eq i10 [[T]], 42352; DL8-NEXT: ret i1 [[R]]353;354 %t = trunc i64 %x to i10355 %r = icmp eq i10 %t, 42356 ret i1 %r357}358 359define i1 @shl1_trunc_eq0(i32 %a) {360; CHECK-LABEL: @shl1_trunc_eq0(361; CHECK-NEXT: [[R:%.*]] = icmp ugt i32 [[A:%.*]], 15362; CHECK-NEXT: ret i1 [[R]]363;364 %shl = shl i32 1, %a365 %t = trunc i32 %shl to i16366 %r = icmp eq i16 %t, 0367 ret i1 %r368}369 370define <2 x i1> @shl1_trunc_ne0(<2 x i8> %a) {371; CHECK-LABEL: @shl1_trunc_ne0(372; CHECK-NEXT: [[R:%.*]] = icmp ult <2 x i8> [[A:%.*]], splat (i8 5)373; CHECK-NEXT: ret <2 x i1> [[R]]374;375 %shl = shl <2 x i8> <i8 1, i8 poison>, %a376 %t = trunc <2 x i8> %shl to <2 x i5>377 %r = icmp ne <2 x i5> %t, zeroinitializer378 ret <2 x i1> %r379}380 381define i1 @shl1_trunc_eq0_use1(i8 %a) {382; CHECK-LABEL: @shl1_trunc_eq0_use1(383; CHECK-NEXT: [[SHL:%.*]] = shl nuw i8 1, [[A:%.*]]384; CHECK-NEXT: call void @use(i8 [[SHL]])385; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[A]], 5386; CHECK-NEXT: ret i1 [[R]]387;388 %shl = shl i8 1, %a389 call void @use(i8 %shl)390 %t = trunc i8 %shl to i6391 %r = icmp eq i6 %t, 0392 ret i1 %r393}394 395define i1 @shl1_trunc_ne0_use2(i37 %a) {396; CHECK-LABEL: @shl1_trunc_ne0_use2(397; CHECK-NEXT: [[SHL:%.*]] = shl nuw i37 1, [[A:%.*]]398; CHECK-NEXT: [[T:%.*]] = trunc i37 [[SHL]] to i8399; CHECK-NEXT: call void @use(i8 [[T]])400; CHECK-NEXT: [[R:%.*]] = icmp ult i37 [[A]], 8401; CHECK-NEXT: ret i1 [[R]]402;403 %shl = shl i37 1, %a404 %t = trunc i37 %shl to i8405 call void @use(i8 %t)406 %r = icmp ne i8 %t, 0407 ret i1 %r408}409 410define i1 @shl2_trunc_eq0(i9 %a) {411; CHECK-LABEL: @shl2_trunc_eq0(412; CHECK-NEXT: [[R:%.*]] = icmp ugt i9 [[A:%.*]], 4413; CHECK-NEXT: ret i1 [[R]]414;415 %shl = shl i9 2, %a416 %t = trunc i9 %shl to i6417 %r = icmp eq i6 %t, 0418 ret i1 %r419}420 421define i1 @shl2_trunc_ne0(i9 %a) {422; CHECK-LABEL: @shl2_trunc_ne0(423; CHECK-NEXT: [[R:%.*]] = icmp ult i9 [[A:%.*]], 5424; CHECK-NEXT: ret i1 [[R]]425;426 %shl = shl i9 2, %a427 %t = trunc i9 %shl to i6428 %r = icmp ne i6 %t, 0429 ret i1 %r430}431 432define i1 @shl3_trunc_eq0(i9 %a) {433; CHECK-LABEL: @shl3_trunc_eq0(434; CHECK-NEXT: [[SHL:%.*]] = shl i9 3, [[A:%.*]]435; CHECK-NEXT: [[T:%.*]] = trunc i9 [[SHL]] to i6436; CHECK-NEXT: [[R:%.*]] = icmp eq i6 [[T]], 0437; CHECK-NEXT: ret i1 [[R]]438;439 %shl = shl i9 3, %a440 %t = trunc i9 %shl to i6441 %r = icmp eq i6 %t, 0442 ret i1 %r443}444 445define <2 x i1> @shl4_trunc_ne0(<2 x i8> %a) {446; CHECK-LABEL: @shl4_trunc_ne0(447; CHECK-NEXT: [[R:%.*]] = icmp ult <2 x i8> [[A:%.*]], splat (i8 3)448; CHECK-NEXT: ret <2 x i1> [[R]]449;450 %shl = shl <2 x i8> <i8 4, i8 poison>, %a451 %t = trunc <2 x i8> %shl to <2 x i5>452 %r = icmp ne <2 x i5> %t, zeroinitializer453 ret <2 x i1> %r454}455 456define i1 @shl5_trunc_ne0(i9 %a) {457; CHECK-LABEL: @shl5_trunc_ne0(458; CHECK-NEXT: [[R:%.*]] = icmp ult i9 [[A:%.*]], 4459; CHECK-NEXT: ret i1 [[R]]460;461 %shl = shl i9 4, %a462 %t = trunc i9 %shl to i6463 %r = icmp ne i6 %t, 0464 ret i1 %r465}466 467; TODO: A < 5468 469define i1 @shl1_trunc_sgt0(i9 %a) {470; CHECK-LABEL: @shl1_trunc_sgt0(471; CHECK-NEXT: [[SHL:%.*]] = shl nuw i9 1, [[A:%.*]]472; CHECK-NEXT: [[T:%.*]] = trunc i9 [[SHL]] to i6473; CHECK-NEXT: [[R:%.*]] = icmp sgt i6 [[T]], 0474; CHECK-NEXT: ret i1 [[R]]475;476 %shl = shl i9 1, %a477 %t = trunc i9 %shl to i6478 %r = icmp sgt i6 %t, 0479 ret i1 %r480}481 482define i1 @shl1_trunc_eq1(i64 %a) {483; CHECK-LABEL: @shl1_trunc_eq1(484; CHECK-NEXT: [[SHL:%.*]] = shl nuw i64 1, [[A:%.*]]485; CHECK-NEXT: [[T:%.*]] = trunc i64 [[SHL]] to i8486; CHECK-NEXT: call void @use(i8 [[T]])487; CHECK-NEXT: [[R:%.*]] = icmp eq i64 [[A]], 0488; CHECK-NEXT: ret i1 [[R]]489;490 %shl = shl i64 1, %a491 %t = trunc i64 %shl to i8492 call void @use(i8 %t)493 %r = icmp eq i8 %t, 1494 ret i1 %r495}496 497define i1 @shl1_trunc_ne32(i8 %a) {498; CHECK-LABEL: @shl1_trunc_ne32(499; CHECK-NEXT: [[SHL:%.*]] = shl nuw i8 1, [[A:%.*]]500; CHECK-NEXT: call void @use(i8 [[SHL]])501; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[A]], 5502; CHECK-NEXT: ret i1 [[R]]503;504 %shl = shl i8 1, %a505 call void @use(i8 %shl)506 %t = trunc i8 %shl to i6507 %r = icmp ne i6 %t, 32508 ret i1 %r509}510 511define i1 @shl2_trunc_eq8_i32(i32 %a) {512; CHECK-LABEL: @shl2_trunc_eq8_i32(513; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[A:%.*]], 2514; CHECK-NEXT: ret i1 [[R]]515;516 %shl = shl i32 2, %a517 %t = trunc i32 %shl to i16518 %r = icmp eq i16 %t, 8519 ret i1 %r520}521 522define i1 @shl2_trunc_ne8_i32(i32 %a) {523; CHECK-LABEL: @shl2_trunc_ne8_i32(524; CHECK-NEXT: [[R:%.*]] = icmp ne i32 [[A:%.*]], 2525; CHECK-NEXT: ret i1 [[R]]526;527 %shl = shl i32 2, %a528 %t = trunc i32 %shl to i16529 %r = icmp ne i16 %t, 8530 ret i1 %r531}532 533define i1 @neg_shl2_trunc_eq0_i8(i8 %a) {534; CHECK-LABEL: @neg_shl2_trunc_eq0_i8(535; CHECK-NEXT: ret i1 true536;537 %shl = shl i8 128, %a538 %t = trunc i8 %shl to i6539 %r = icmp eq i6 %t, 0540 ret i1 %r541}542 543define i1 @neg_shl2_trunc_ne0_i8(i8 %a) {544; CHECK-LABEL: @neg_shl2_trunc_ne0_i8(545; CHECK-NEXT: ret i1 false546;547 %shl = shl i8 128, %a548 %t = trunc i8 %shl to i6549 %r = icmp ne i6 %t, 0550 ret i1 %r551}552 553define i1 @shl1_trunc_sgt4(i32 %a) {554; CHECK-LABEL: @shl1_trunc_sgt4(555; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 1, [[A:%.*]]556; CHECK-NEXT: [[T:%.*]] = trunc i32 [[SHL]] to i16557; CHECK-NEXT: [[R:%.*]] = icmp sgt i16 [[T]], 4558; CHECK-NEXT: ret i1 [[R]]559;560 %shl = shl i32 1, %a561 %t = trunc i32 %shl to i16562 %r = icmp sgt i16 %t, 4563 ret i1 %r564}565 566define i1 @eq_nuw(i32 %x) {567; DL64-LABEL: @eq_nuw(568; DL64-NEXT: [[R:%.*]] = icmp eq i32 [[X:%.*]], 123569; DL64-NEXT: ret i1 [[R]]570;571; DL8-LABEL: @eq_nuw(572; DL8-NEXT: [[T:%.*]] = trunc nuw i32 [[X:%.*]] to i8573; DL8-NEXT: [[R:%.*]] = icmp eq i8 [[T]], 123574; DL8-NEXT: ret i1 [[R]]575;576 %t = trunc nuw i32 %x to i8577 %r = icmp eq i8 %t, 123578 ret i1 %r579}580 581define i1 @ult_nuw(i32 %x) {582; DL64-LABEL: @ult_nuw(583; DL64-NEXT: [[R:%.*]] = icmp ult i32 [[X:%.*]], 45584; DL64-NEXT: ret i1 [[R]]585;586; DL8-LABEL: @ult_nuw(587; DL8-NEXT: [[T:%.*]] = trunc nuw i32 [[X:%.*]] to i8588; DL8-NEXT: [[R:%.*]] = icmp ult i8 [[T]], 45589; DL8-NEXT: ret i1 [[R]]590;591 %t = trunc nuw i32 %x to i8592 %r = icmp ult i8 %t, 45593 ret i1 %r594}595 596define i1 @ule_nuw(i32 %x) {597; DL64-LABEL: @ule_nuw(598; DL64-NEXT: [[T:%.*]] = trunc nuw i32 [[X:%.*]] to i8599; DL64-NEXT: [[R:%.*]] = icmp ult i32 [[X]], 46600; DL64-NEXT: call void @use(i8 [[T]])601; DL64-NEXT: ret i1 [[R]]602;603; DL8-LABEL: @ule_nuw(604; DL8-NEXT: [[T:%.*]] = trunc nuw i32 [[X:%.*]] to i8605; DL8-NEXT: [[R:%.*]] = icmp ult i8 [[T]], 46606; DL8-NEXT: call void @use(i8 [[T]])607; DL8-NEXT: ret i1 [[R]]608;609 %t = trunc nuw i32 %x to i8610 %r = icmp ule i8 %t, 45611 call void @use(i8 %t)612 ret i1 %r613}614 615define i1 @ugt_nuw(i32 %x) {616; DL64-LABEL: @ugt_nuw(617; DL64-NEXT: [[R:%.*]] = icmp ugt i32 [[X:%.*]], 12618; DL64-NEXT: ret i1 [[R]]619;620; DL8-LABEL: @ugt_nuw(621; DL8-NEXT: [[T:%.*]] = trunc nuw i32 [[X:%.*]] to i8622; DL8-NEXT: [[R:%.*]] = icmp ugt i8 [[T]], 12623; DL8-NEXT: ret i1 [[R]]624;625 %t = trunc nuw i32 %x to i8626 %r = icmp ugt i8 %t, 12627 ret i1 %r628}629 630define i1 @uge_nuw(i32 %x) {631; DL64-LABEL: @uge_nuw(632; DL64-NEXT: [[T:%.*]] = trunc nuw i32 [[X:%.*]] to i8633; DL64-NEXT: [[R:%.*]] = icmp ugt i32 [[X]], 98634; DL64-NEXT: call void @use(i8 [[T]])635; DL64-NEXT: ret i1 [[R]]636;637; DL8-LABEL: @uge_nuw(638; DL8-NEXT: [[T:%.*]] = trunc nuw i32 [[X:%.*]] to i8639; DL8-NEXT: [[R:%.*]] = icmp ugt i8 [[T]], 98640; DL8-NEXT: call void @use(i8 [[T]])641; DL8-NEXT: ret i1 [[R]]642;643 %t = trunc nuw i32 %x to i8644 %r = icmp uge i8 %t, 99645 call void @use(i8 %t)646 ret i1 %r647}648 649define i1 @uge_nuw_i48(i48 %x) {650; CHECK-LABEL: @uge_nuw_i48(651; CHECK-NEXT: [[T:%.*]] = trunc nuw i48 [[X:%.*]] to i8652; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[T]], 98653; CHECK-NEXT: call void @use(i8 [[T]])654; CHECK-NEXT: ret i1 [[R]]655;656 %t = trunc nuw i48 %x to i8657 %r = icmp uge i8 %t, 99658 call void @use(i8 %t)659 ret i1 %r660}661 662define i1 @sgt_nuw_fail(i32 %x) {663; CHECK-LABEL: @sgt_nuw_fail(664; CHECK-NEXT: [[T:%.*]] = trunc nuw i32 [[X:%.*]] to i8665; CHECK-NEXT: [[R:%.*]] = icmp sgt i8 [[T]], 12666; CHECK-NEXT: ret i1 [[R]]667;668 %t = trunc nuw i32 %x to i8669 %r = icmp sgt i8 %t, 12670 ret i1 %r671}672 673define i1 @ne_nsw(i32 %x) {674; DL64-LABEL: @ne_nsw(675; DL64-NEXT: [[R:%.*]] = icmp ne i32 [[X:%.*]], -123676; DL64-NEXT: ret i1 [[R]]677;678; DL8-LABEL: @ne_nsw(679; DL8-NEXT: [[T:%.*]] = trunc nsw i32 [[X:%.*]] to i8680; DL8-NEXT: [[R:%.*]] = icmp ne i8 [[T]], -123681; DL8-NEXT: ret i1 [[R]]682;683 %t = trunc nsw i32 %x to i8684 %r = icmp ne i8 %t, -123685 ret i1 %r686}687 688define i1 @slt_nsw(i32 %x) {689; DL64-LABEL: @slt_nsw(690; DL64-NEXT: [[R:%.*]] = icmp slt i32 [[X:%.*]], 45691; DL64-NEXT: ret i1 [[R]]692;693; DL8-LABEL: @slt_nsw(694; DL8-NEXT: [[T:%.*]] = trunc nsw i32 [[X:%.*]] to i8695; DL8-NEXT: [[R:%.*]] = icmp slt i8 [[T]], 45696; DL8-NEXT: ret i1 [[R]]697;698 %t = trunc nsw i32 %x to i8699 %r = icmp slt i8 %t, 45700 ret i1 %r701}702 703define i1 @sle_nsw(i16 %x) {704; DL64-LABEL: @sle_nsw(705; DL64-NEXT: [[T:%.*]] = trunc nsw i16 [[X:%.*]] to i8706; DL64-NEXT: [[R:%.*]] = icmp slt i16 [[X]], 46707; DL64-NEXT: call void @use(i8 [[T]])708; DL64-NEXT: ret i1 [[R]]709;710; DL8-LABEL: @sle_nsw(711; DL8-NEXT: [[T:%.*]] = trunc nsw i16 [[X:%.*]] to i8712; DL8-NEXT: [[R:%.*]] = icmp slt i8 [[T]], 46713; DL8-NEXT: call void @use(i8 [[T]])714; DL8-NEXT: ret i1 [[R]]715;716 %t = trunc nsw i16 %x to i8717 %r = icmp sle i8 %t, 45718 call void @use(i8 %t)719 ret i1 %r720}721 722define i1 @sgt_nsw(i32 %x) {723; DL64-LABEL: @sgt_nsw(724; DL64-NEXT: [[R:%.*]] = icmp sgt i32 [[X:%.*]], -12725; DL64-NEXT: ret i1 [[R]]726;727; DL8-LABEL: @sgt_nsw(728; DL8-NEXT: [[T:%.*]] = trunc nsw i32 [[X:%.*]] to i8729; DL8-NEXT: [[R:%.*]] = icmp sgt i8 [[T]], -12730; DL8-NEXT: ret i1 [[R]]731;732 %t = trunc nsw i32 %x to i8733 %r = icmp sgt i8 %t, -12734 ret i1 %r735}736 737define i1 @sge_nsw(i64 %x) {738; DL64-LABEL: @sge_nsw(739; DL64-NEXT: [[T:%.*]] = trunc nsw i64 [[X:%.*]] to i8740; DL64-NEXT: [[R:%.*]] = icmp sgt i64 [[X]], 98741; DL64-NEXT: call void @use(i8 [[T]])742; DL64-NEXT: ret i1 [[R]]743;744; DL8-LABEL: @sge_nsw(745; DL8-NEXT: [[T:%.*]] = trunc nsw i64 [[X:%.*]] to i8746; DL8-NEXT: [[R:%.*]] = icmp sgt i8 [[T]], 98747; DL8-NEXT: call void @use(i8 [[T]])748; DL8-NEXT: ret i1 [[R]]749;750 %t = trunc nsw i64 %x to i8751 %r = icmp sge i8 %t, 99752 call void @use(i8 %t)753 ret i1 %r754}755 756 757 758define i1 @sge_nsw_i48(i48 %x) {759; CHECK-LABEL: @sge_nsw_i48(760; CHECK-NEXT: [[T:%.*]] = trunc nsw i48 [[X:%.*]] to i8761; CHECK-NEXT: [[R:%.*]] = icmp sgt i8 [[T]], 98762; CHECK-NEXT: call void @use(i8 [[T]])763; CHECK-NEXT: ret i1 [[R]]764;765 %t = trunc nsw i48 %x to i8766 %r = icmp sge i8 %t, 99767 call void @use(i8 %t)768 ret i1 %r769}770 771 772define <2 x i1> @uge_nsw(<2 x i32> %x) {773; CHECK-LABEL: @uge_nsw(774; CHECK-NEXT: [[T:%.*]] = trunc nsw <2 x i32> [[X:%.*]] to <2 x i8>775; CHECK-NEXT: [[R:%.*]] = icmp ugt <2 x i8> [[T]], splat (i8 -46)776; CHECK-NEXT: ret <2 x i1> [[R]]777;778 %t = trunc nsw <2 x i32> %x to <2 x i8>779 %r = icmp uge <2 x i8> %t, <i8 -45, i8 -45>780 ret <2 x i1> %r781}782 783 784define <2 x i1> @uge_nsw_non_splat(<2 x i32> %x) {785; CHECK-LABEL: @uge_nsw_non_splat(786; CHECK-NEXT: [[T:%.*]] = trunc nsw <2 x i32> [[X:%.*]] to <2 x i8>787; CHECK-NEXT: [[R:%.*]] = icmp ugt <2 x i8> [[T]], <i8 44, i8 45>788; CHECK-NEXT: ret <2 x i1> [[R]]789;790 %t = trunc nsw <2 x i32> %x to <2 x i8>791 %r = icmp uge <2 x i8> %t, <i8 45, i8 46>792 ret <2 x i1> %r793}794 795define i1 @trunc_icmp(i8 %a0) {796; CHECK-LABEL: @trunc_icmp(797; CHECK-NEXT: [[TZ:%.*]] = tail call range(i8 0, 9) i8 @llvm.cttz.i8(i8 [[A0:%.*]], i1 false)798; CHECK-NEXT: [[TR:%.*]] = trunc nuw i8 [[TZ]] to i4799; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[A0]], 0800; CHECK-NEXT: call void @use2(i4 [[TR]])801; CHECK-NEXT: ret i1 [[C]]802;803 %tz = tail call range(i8 0, 9) i8 @llvm.cttz.i8(i8 %a0, i1 false)804 %tr = trunc i8 %tz to i4805 %c = icmp eq i4 %tr, 8806 call void @use2(i4 %tr)807 ret i1 %c808}809 810define i1 @do_not_mask_trunc_eq_i32_i8(i32 %x) {811; DL64-LABEL: @do_not_mask_trunc_eq_i32_i8(812; DL64-NEXT: [[R:%.*]] = icmp eq i32 [[X:%.*]], 42813; DL64-NEXT: ret i1 [[R]]814;815; DL8-LABEL: @do_not_mask_trunc_eq_i32_i8(816; DL8-NEXT: [[T:%.*]] = trunc nuw i32 [[X:%.*]] to i8817; DL8-NEXT: [[R:%.*]] = icmp eq i8 [[T]], 42818; DL8-NEXT: ret i1 [[R]]819;820 %t = trunc nuw i32 %x to i8821 %r = icmp eq i8 %t, 42822 ret i1 %r823}824