616 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4; https://bugs.llvm.org/show_bug.cgi?id=376035; https://reviews.llvm.org/D46760#11237136 7; Pattern:8; x >> y << y9; Should be transformed into:10; x & (-1 << y)11 12; ============================================================================ ;13; Basic positive tests14; ============================================================================ ;15 16define i8 @positive_samevar(i8 %x, i8 %y) {17; CHECK-LABEL: @positive_samevar(18; CHECK-NEXT: [[TMP1:%.*]] = shl nsw i8 -1, [[Y:%.*]]19; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], [[X:%.*]]20; CHECK-NEXT: ret i8 [[RET]]21;22 %t0 = lshr i8 %x, %y23 %ret = shl i8 %t0, %y24 ret i8 %ret25}26 27define i8 @positive_sameconst(i8 %x) {28; CHECK-LABEL: @positive_sameconst(29; CHECK-NEXT: [[T0:%.*]] = and i8 [[X:%.*]], -830; CHECK-NEXT: ret i8 [[T0]]31;32 %t0 = lshr i8 %x, 333 %ret = shl i8 %t0, 334 ret i8 %ret35}36 37define i8 @positive_biggerlshr(i8 %x) {38; CHECK-LABEL: @positive_biggerlshr(39; CHECK-NEXT: [[TMP1:%.*]] = lshr i8 [[X:%.*]], 340; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], 2441; CHECK-NEXT: ret i8 [[RET]]42;43 %t0 = lshr i8 %x, 644 %ret = shl i8 %t0, 345 ret i8 %ret46}47 48define i8 @positive_biggershl(i8 %x) {49; CHECK-LABEL: @positive_biggershl(50; CHECK-NEXT: [[TMP1:%.*]] = shl i8 [[X:%.*]], 351; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], -6452; CHECK-NEXT: ret i8 [[RET]]53;54 %t0 = lshr i8 %x, 355 %ret = shl i8 %t0, 656 ret i8 %ret57}58 59; ============================================================================ ;60; shl nuw61; ============================================================================ ;62 63define i8 @positive_samevar_shlnuw(i8 %x, i8 %y) {64; CHECK-LABEL: @positive_samevar_shlnuw(65; CHECK-NEXT: [[TMP1:%.*]] = shl nsw i8 -1, [[Y:%.*]]66; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], [[X:%.*]]67; CHECK-NEXT: ret i8 [[RET]]68;69 %t0 = lshr i8 %x, %y70 %ret = shl nuw i8 %t0, %y71 ret i8 %ret72}73 74define i8 @positive_sameconst_shlnuw(i8 %x) {75; CHECK-LABEL: @positive_sameconst_shlnuw(76; CHECK-NEXT: [[T0:%.*]] = and i8 [[X:%.*]], -877; CHECK-NEXT: ret i8 [[T0]]78;79 %t0 = lshr i8 %x, 380 %ret = shl nuw i8 %t0, 381 ret i8 %ret82}83 84define i8 @positive_biggerlshr_shlnuw(i8 %x) {85; CHECK-LABEL: @positive_biggerlshr_shlnuw(86; CHECK-NEXT: [[TMP1:%.*]] = lshr i8 [[X:%.*]], 387; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], 2488; CHECK-NEXT: ret i8 [[RET]]89;90 %t0 = lshr i8 %x, 691 %ret = shl nuw i8 %t0, 392 ret i8 %ret93}94 95define i8 @positive_biggershl_shlnuw(i8 %x) {96; CHECK-LABEL: @positive_biggershl_shlnuw(97; CHECK-NEXT: [[TMP1:%.*]] = shl nuw i8 [[X:%.*]], 398; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], -6499; CHECK-NEXT: ret i8 [[RET]]100;101 %t0 = lshr i8 %x, 3102 %ret = shl nuw i8 %t0, 6103 ret i8 %ret104}105 106; ============================================================================ ;107; shl nsw108; ============================================================================ ;109 110define i8 @positive_samevar_shlnsw(i8 %x, i8 %y) {111; CHECK-LABEL: @positive_samevar_shlnsw(112; CHECK-NEXT: [[TMP1:%.*]] = shl nsw i8 -1, [[Y:%.*]]113; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], [[X:%.*]]114; CHECK-NEXT: ret i8 [[RET]]115;116 %t0 = lshr i8 %x, %y117 %ret = shl nsw i8 %t0, %y118 ret i8 %ret119}120 121define i8 @positive_sameconst_shlnsw(i8 %x) {122; CHECK-LABEL: @positive_sameconst_shlnsw(123; CHECK-NEXT: [[T0:%.*]] = and i8 [[X:%.*]], -8124; CHECK-NEXT: ret i8 [[T0]]125;126 %t0 = lshr i8 %x, 3127 %ret = shl nsw i8 %t0, 3128 ret i8 %ret129}130 131define i8 @positive_biggerlshr_shlnsw(i8 %x) {132; CHECK-LABEL: @positive_biggerlshr_shlnsw(133; CHECK-NEXT: [[TMP1:%.*]] = lshr i8 [[X:%.*]], 3134; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], 24135; CHECK-NEXT: ret i8 [[RET]]136;137 %t0 = lshr i8 %x, 6138 %ret = shl nsw i8 %t0, 3139 ret i8 %ret140}141 142define i8 @positive_biggershl_shlnsw(i8 %x) {143; CHECK-LABEL: @positive_biggershl_shlnsw(144; CHECK-NEXT: [[TMP1:%.*]] = shl nuw nsw i8 [[X:%.*]], 3145; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], 64146; CHECK-NEXT: ret i8 [[RET]]147;148 %t0 = lshr i8 %x, 3149 %ret = shl nsw i8 %t0, 6150 ret i8 %ret151}152 153; ============================================================================ ;154; shl nuw nsw155; ============================================================================ ;156 157define i8 @positive_samevar_shlnuwnsw(i8 %x, i8 %y) {158; CHECK-LABEL: @positive_samevar_shlnuwnsw(159; CHECK-NEXT: [[TMP1:%.*]] = shl nsw i8 -1, [[Y:%.*]]160; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], [[X:%.*]]161; CHECK-NEXT: ret i8 [[RET]]162;163 %t0 = lshr i8 %x, %y164 %ret = shl nuw nsw i8 %t0, %y165 ret i8 %ret166}167 168define i8 @positive_sameconst_shlnuwnsw(i8 %x) {169; CHECK-LABEL: @positive_sameconst_shlnuwnsw(170; CHECK-NEXT: [[T0:%.*]] = and i8 [[X:%.*]], -8171; CHECK-NEXT: ret i8 [[T0]]172;173 %t0 = lshr i8 %x, 3174 %ret = shl nuw nsw i8 %t0, 3175 ret i8 %ret176}177 178define i8 @positive_biggerlshr_shlnuwnsw(i8 %x) {179; CHECK-LABEL: @positive_biggerlshr_shlnuwnsw(180; CHECK-NEXT: [[TMP1:%.*]] = lshr i8 [[X:%.*]], 3181; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], 24182; CHECK-NEXT: ret i8 [[RET]]183;184 %t0 = lshr i8 %x, 6185 %ret = shl nuw nsw i8 %t0, 3186 ret i8 %ret187}188 189define i8 @positive_biggershl_shlnuwnsw(i8 %x) {190; CHECK-LABEL: @positive_biggershl_shlnuwnsw(191; CHECK-NEXT: [[TMP1:%.*]] = shl nuw nsw i8 [[X:%.*]], 3192; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], 64193; CHECK-NEXT: ret i8 [[RET]]194;195 %t0 = lshr i8 %x, 3196 %ret = shl nuw nsw i8 %t0, 6197 ret i8 %ret198}199 200; ============================================================================ ;201; lshr exact202; ============================================================================ ;203 204define i8 @positive_samevar_lshrexact(i8 %x, i8 %y) {205; CHECK-LABEL: @positive_samevar_lshrexact(206; CHECK-NEXT: ret i8 [[X:%.*]]207;208 %t0 = lshr exact i8 %x, %y209 %ret = shl i8 %t0, %y210 ret i8 %ret211}212 213define i8 @positive_sameconst_lshrexact(i8 %x) {214; CHECK-LABEL: @positive_sameconst_lshrexact(215; CHECK-NEXT: ret i8 [[X:%.*]]216;217 %t0 = lshr exact i8 %x, 3218 %ret = shl i8 %t0, 3219 ret i8 %ret220}221 222define i8 @positive_biggerlshr_lshrexact(i8 %x) {223; CHECK-LABEL: @positive_biggerlshr_lshrexact(224; CHECK-NEXT: [[RET:%.*]] = lshr exact i8 [[X:%.*]], 3225; CHECK-NEXT: ret i8 [[RET]]226;227 %t0 = lshr exact i8 %x, 6228 %ret = shl i8 %t0, 3229 ret i8 %ret230}231 232define i8 @positive_biggershl_lshrexact(i8 %x) {233; CHECK-LABEL: @positive_biggershl_lshrexact(234; CHECK-NEXT: [[RET:%.*]] = shl i8 [[X:%.*]], 3235; CHECK-NEXT: ret i8 [[RET]]236;237 %t0 = lshr exact i8 %x, 3238 %ret = shl i8 %t0, 6239 ret i8 %ret240}241 242; ============================================================================ ;243; lshr exact, shl nsw244; ============================================================================ ;245 246define i8 @positive_samevar_shlnsw_lshrexact(i8 %x, i8 %y) {247; CHECK-LABEL: @positive_samevar_shlnsw_lshrexact(248; CHECK-NEXT: ret i8 [[X:%.*]]249;250 %t0 = lshr exact i8 %x, %y251 %ret = shl nsw i8 %t0, %y252 ret i8 %ret253}254 255define i8 @positive_sameconst_shlnsw_lshrexact(i8 %x) {256; CHECK-LABEL: @positive_sameconst_shlnsw_lshrexact(257; CHECK-NEXT: ret i8 [[X:%.*]]258;259 %t0 = lshr exact i8 %x, 3260 %ret = shl nsw i8 %t0, 3261 ret i8 %ret262}263 264define i8 @positive_biggerlshr_shlnsw_lshrexact(i8 %x) {265; CHECK-LABEL: @positive_biggerlshr_shlnsw_lshrexact(266; CHECK-NEXT: [[RET:%.*]] = lshr exact i8 [[X:%.*]], 3267; CHECK-NEXT: ret i8 [[RET]]268;269 %t0 = lshr exact i8 %x, 6270 %ret = shl nsw i8 %t0, 3271 ret i8 %ret272}273 274define i8 @positive_biggershl_shlnsw_lshrexact(i8 %x) {275; CHECK-LABEL: @positive_biggershl_shlnsw_lshrexact(276; CHECK-NEXT: [[RET:%.*]] = shl nuw nsw i8 [[X:%.*]], 3277; CHECK-NEXT: ret i8 [[RET]]278;279 %t0 = lshr exact i8 %x, 3280 %ret = shl nsw i8 %t0, 6281 ret i8 %ret282}283 284; ============================================================================ ;285; lshr exact, shl nuw286; ============================================================================ ;287 288define i8 @positive_samevar_shlnuw_lshrexact(i8 %x, i8 %y) {289; CHECK-LABEL: @positive_samevar_shlnuw_lshrexact(290; CHECK-NEXT: ret i8 [[X:%.*]]291;292 %t0 = lshr exact i8 %x, %y293 %ret = shl nuw i8 %t0, %y294 ret i8 %ret295}296 297define i8 @positive_sameconst_shlnuw_lshrexact(i8 %x) {298; CHECK-LABEL: @positive_sameconst_shlnuw_lshrexact(299; CHECK-NEXT: ret i8 [[X:%.*]]300;301 %t0 = lshr exact i8 %x, 3302 %ret = shl nuw i8 %t0, 3303 ret i8 %ret304}305 306define i8 @positive_biggerlshr_shlnuw_lshrexact(i8 %x) {307; CHECK-LABEL: @positive_biggerlshr_shlnuw_lshrexact(308; CHECK-NEXT: [[RET:%.*]] = lshr exact i8 [[X:%.*]], 3309; CHECK-NEXT: ret i8 [[RET]]310;311 %t0 = lshr exact i8 %x, 6312 %ret = shl nuw i8 %t0, 3313 ret i8 %ret314}315 316define i8 @positive_biggershl_shlnuw_lshrexact(i8 %x) {317; CHECK-LABEL: @positive_biggershl_shlnuw_lshrexact(318; CHECK-NEXT: [[RET:%.*]] = shl nuw i8 [[X:%.*]], 3319; CHECK-NEXT: ret i8 [[RET]]320;321 %t0 = lshr exact i8 %x, 3322 %ret = shl nuw i8 %t0, 6323 ret i8 %ret324}325 326; ============================================================================ ;327; lshr exact, shl nuw nsw328; ============================================================================ ;329 330define i8 @positive_samevar_shlnuwnsw_lshrexact(i8 %x, i8 %y) {331; CHECK-LABEL: @positive_samevar_shlnuwnsw_lshrexact(332; CHECK-NEXT: ret i8 [[X:%.*]]333;334 %t0 = lshr exact i8 %x, %y335 %ret = shl nuw nsw i8 %t0, %y336 ret i8 %ret337}338 339define i8 @positive_sameconst_shlnuwnsw_lshrexact(i8 %x) {340; CHECK-LABEL: @positive_sameconst_shlnuwnsw_lshrexact(341; CHECK-NEXT: ret i8 [[X:%.*]]342;343 %t0 = lshr exact i8 %x, 3344 %ret = shl nuw nsw i8 %t0, 3345 ret i8 %ret346}347 348define i8 @positive_biggerlshr_shlnuwnsw_lshrexact(i8 %x) {349; CHECK-LABEL: @positive_biggerlshr_shlnuwnsw_lshrexact(350; CHECK-NEXT: [[RET:%.*]] = lshr exact i8 [[X:%.*]], 3351; CHECK-NEXT: ret i8 [[RET]]352;353 %t0 = lshr exact i8 %x, 6354 %ret = shl nuw nsw i8 %t0, 3355 ret i8 %ret356}357 358define i8 @positive_biggershl_shlnuwnsw_lshrexact(i8 %x) {359; CHECK-LABEL: @positive_biggershl_shlnuwnsw_lshrexact(360; CHECK-NEXT: [[RET:%.*]] = shl nuw nsw i8 [[X:%.*]], 3361; CHECK-NEXT: ret i8 [[RET]]362;363 %t0 = lshr exact i8 %x, 3364 %ret = shl nuw nsw i8 %t0, 6365 ret i8 %ret366}367 368; ============================================================================ ;369; Vector370; ============================================================================ ;371 372define <2 x i8> @positive_samevar_vec(<2 x i8> %x, <2 x i8> %y) {373; CHECK-LABEL: @positive_samevar_vec(374; CHECK-NEXT: [[TMP1:%.*]] = shl nsw <2 x i8> splat (i8 -1), [[Y:%.*]]375; CHECK-NEXT: [[RET:%.*]] = and <2 x i8> [[TMP1]], [[X:%.*]]376; CHECK-NEXT: ret <2 x i8> [[RET]]377;378 %t0 = lshr <2 x i8> %x, %y379 %ret = shl <2 x i8> %t0, %y380 ret <2 x i8> %ret381}382 383; ============================================================================ ;384; Constant Vectors385; ============================================================================ ;386 387define <2 x i8> @positive_sameconst_vec(<2 x i8> %x) {388; CHECK-LABEL: @positive_sameconst_vec(389; CHECK-NEXT: [[T0:%.*]] = and <2 x i8> [[X:%.*]], splat (i8 -8)390; CHECK-NEXT: ret <2 x i8> [[T0]]391;392 %t0 = lshr <2 x i8> %x, <i8 3, i8 3>393 %ret = shl <2 x i8> %t0, <i8 3, i8 3>394 ret <2 x i8> %ret395}396 397define <3 x i8> @positive_sameconst_vec_undef0(<3 x i8> %x) {398; CHECK-LABEL: @positive_sameconst_vec_undef0(399; CHECK-NEXT: [[T0:%.*]] = lshr <3 x i8> [[X:%.*]], <i8 3, i8 undef, i8 3>400; CHECK-NEXT: [[RET:%.*]] = shl <3 x i8> [[T0]], splat (i8 3)401; CHECK-NEXT: ret <3 x i8> [[RET]]402;403 %t0 = lshr <3 x i8> %x, <i8 3, i8 undef, i8 3>404 %ret = shl <3 x i8> %t0, <i8 3, i8 3, i8 3>405 ret <3 x i8> %ret406}407 408define <3 x i8> @positive_sameconst_vec_undef1(<3 x i8> %x) {409; CHECK-LABEL: @positive_sameconst_vec_undef1(410; CHECK-NEXT: [[T0:%.*]] = lshr <3 x i8> [[X:%.*]], splat (i8 3)411; CHECK-NEXT: [[RET:%.*]] = shl <3 x i8> [[T0]], <i8 3, i8 undef, i8 3>412; CHECK-NEXT: ret <3 x i8> [[RET]]413;414 %t0 = lshr <3 x i8> %x, <i8 3, i8 3, i8 3>415 %ret = shl <3 x i8> %t0, <i8 3, i8 undef, i8 3>416 ret <3 x i8> %ret417}418 419define <3 x i8> @positive_sameconst_vec_undef2(<3 x i8> %x) {420; CHECK-LABEL: @positive_sameconst_vec_undef2(421; CHECK-NEXT: [[RET:%.*]] = and <3 x i8> [[X:%.*]], <i8 -8, i8 poison, i8 -8>422; CHECK-NEXT: ret <3 x i8> [[RET]]423;424 %t0 = lshr <3 x i8> %x, <i8 3, i8 undef, i8 3>425 %ret = shl <3 x i8> %t0, <i8 3, i8 undef, i8 3>426 ret <3 x i8> %ret427}428 429define <2 x i8> @positive_biggerlshr_vec(<2 x i8> %x) {430; CHECK-LABEL: @positive_biggerlshr_vec(431; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i8> [[X:%.*]], splat (i8 3)432; CHECK-NEXT: [[RET:%.*]] = and <2 x i8> [[TMP1]], splat (i8 24)433; CHECK-NEXT: ret <2 x i8> [[RET]]434;435 %t0 = lshr <2 x i8> %x, <i8 6, i8 6>436 %ret = shl <2 x i8> %t0, <i8 3, i8 3>437 ret <2 x i8> %ret438}439 440define <3 x i8> @positive_biggerlshr_vec_undef0(<3 x i8> %x) {441; CHECK-LABEL: @positive_biggerlshr_vec_undef0(442; CHECK-NEXT: [[T0:%.*]] = lshr <3 x i8> [[X:%.*]], <i8 6, i8 undef, i8 6>443; CHECK-NEXT: [[RET:%.*]] = shl <3 x i8> [[T0]], splat (i8 3)444; CHECK-NEXT: ret <3 x i8> [[RET]]445;446 %t0 = lshr <3 x i8> %x, <i8 6, i8 undef, i8 6>447 %ret = shl <3 x i8> %t0, <i8 3, i8 3, i8 3>448 ret <3 x i8> %ret449}450 451define <3 x i8> @positive_biggerlshr_vec_undef1(<3 x i8> %x) {452; CHECK-LABEL: @positive_biggerlshr_vec_undef1(453; CHECK-NEXT: [[T0:%.*]] = lshr <3 x i8> [[X:%.*]], splat (i8 6)454; CHECK-NEXT: [[RET:%.*]] = shl <3 x i8> [[T0]], <i8 3, i8 undef, i8 3>455; CHECK-NEXT: ret <3 x i8> [[RET]]456;457 %t0 = lshr <3 x i8> %x, <i8 6, i8 6, i8 6>458 %ret = shl <3 x i8> %t0, <i8 3, i8 undef, i8 3>459 ret <3 x i8> %ret460}461 462define <3 x i8> @positive_biggerlshr_vec_undef2(<3 x i8> %x) {463; CHECK-LABEL: @positive_biggerlshr_vec_undef2(464; CHECK-NEXT: [[T0:%.*]] = lshr <3 x i8> [[X:%.*]], <i8 6, i8 undef, i8 6>465; CHECK-NEXT: [[RET:%.*]] = shl <3 x i8> [[T0]], <i8 3, i8 undef, i8 3>466; CHECK-NEXT: ret <3 x i8> [[RET]]467;468 %t0 = lshr <3 x i8> %x, <i8 6, i8 undef, i8 6>469 %ret = shl <3 x i8> %t0, <i8 3, i8 undef, i8 3>470 ret <3 x i8> %ret471}472 473define <2 x i8> @positive_biggershl_vec(<2 x i8> %x) {474; CHECK-LABEL: @positive_biggershl_vec(475; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i8> [[X:%.*]], splat (i8 3)476; CHECK-NEXT: [[RET:%.*]] = and <2 x i8> [[TMP1]], splat (i8 -64)477; CHECK-NEXT: ret <2 x i8> [[RET]]478;479 %t0 = lshr <2 x i8> %x, <i8 3, i8 3>480 %ret = shl <2 x i8> %t0, <i8 6, i8 6>481 ret <2 x i8> %ret482}483 484define <3 x i8> @positive_biggershl_vec_undef0(<3 x i8> %x) {485; CHECK-LABEL: @positive_biggershl_vec_undef0(486; CHECK-NEXT: [[T0:%.*]] = lshr <3 x i8> [[X:%.*]], <i8 3, i8 undef, i8 3>487; CHECK-NEXT: [[RET:%.*]] = shl <3 x i8> [[T0]], splat (i8 6)488; CHECK-NEXT: ret <3 x i8> [[RET]]489;490 %t0 = lshr <3 x i8> %x, <i8 3, i8 undef, i8 3>491 %ret = shl <3 x i8> %t0, <i8 6, i8 6, i8 6>492 ret <3 x i8> %ret493}494 495define <3 x i8> @positive_biggershl_vec_undef1(<3 x i8> %x) {496; CHECK-LABEL: @positive_biggershl_vec_undef1(497; CHECK-NEXT: [[T0:%.*]] = lshr <3 x i8> [[X:%.*]], splat (i8 3)498; CHECK-NEXT: [[RET:%.*]] = shl <3 x i8> [[T0]], <i8 6, i8 undef, i8 6>499; CHECK-NEXT: ret <3 x i8> [[RET]]500;501 %t0 = lshr <3 x i8> %x, <i8 3, i8 3, i8 3>502 %ret = shl <3 x i8> %t0, <i8 6, i8 undef, i8 6>503 ret <3 x i8> %ret504}505 506define <3 x i8> @positive_biggershl_vec_undef2(<3 x i8> %x) {507; CHECK-LABEL: @positive_biggershl_vec_undef2(508; CHECK-NEXT: [[T0:%.*]] = lshr <3 x i8> [[X:%.*]], <i8 3, i8 undef, i8 3>509; CHECK-NEXT: [[RET:%.*]] = shl <3 x i8> [[T0]], <i8 6, i8 undef, i8 6>510; CHECK-NEXT: ret <3 x i8> [[RET]]511;512 %t0 = lshr <3 x i8> %x, <i8 3, i8 undef, i8 3>513 %ret = shl <3 x i8> %t0, <i8 6, i8 undef, i8 6>514 ret <3 x i8> %ret515}516 517; ============================================================================ ;518; Positive multi-use tests with constant519; ============================================================================ ;520 521define i8 @positive_sameconst_multiuse(i8 %x) {522; CHECK-LABEL: @positive_sameconst_multiuse(523; CHECK-NEXT: [[T0:%.*]] = lshr i8 [[X:%.*]], 3524; CHECK-NEXT: call void @use32(i8 [[T0]])525; CHECK-NEXT: [[RET:%.*]] = and i8 [[X]], -8526; CHECK-NEXT: ret i8 [[RET]]527;528 %t0 = lshr i8 %x, 3529 call void @use32(i8 %t0)530 %ret = shl i8 %t0, 3531 ret i8 %ret532}533 534define i8 @positive_biggerlshr_multiuse(i8 %x) {535; CHECK-LABEL: @positive_biggerlshr_multiuse(536; CHECK-NEXT: [[T0:%.*]] = lshr i8 [[X:%.*]], 6537; CHECK-NEXT: call void @use32(i8 [[T0]])538; CHECK-NEXT: [[RET:%.*]] = shl nuw nsw i8 [[T0]], 3539; CHECK-NEXT: ret i8 [[RET]]540;541 %t0 = lshr i8 %x, 6542 call void @use32(i8 %t0)543 %ret = shl i8 %t0, 3544 ret i8 %ret545}546 547define i8 @positive_biggershl_multiuse(i8 %x) {548; CHECK-LABEL: @positive_biggershl_multiuse(549; CHECK-NEXT: [[T0:%.*]] = lshr i8 [[X:%.*]], 3550; CHECK-NEXT: call void @use32(i8 [[T0]])551; CHECK-NEXT: [[RET:%.*]] = shl i8 [[T0]], 6552; CHECK-NEXT: ret i8 [[RET]]553;554 %t0 = lshr i8 %x, 3555 call void @use32(i8 %t0)556 %ret = shl i8 %t0, 6557 ret i8 %ret558}559 560; ============================================================================ ;561; Constant Non-Splat Vectors562; ============================================================================ ;563 564define <2 x i8> @positive_biggerlshr_vec_nonsplat(<2 x i8> %x) {565; CHECK-LABEL: @positive_biggerlshr_vec_nonsplat(566; CHECK-NEXT: [[T0:%.*]] = lshr <2 x i8> [[X:%.*]], splat (i8 3)567; CHECK-NEXT: [[RET:%.*]] = shl <2 x i8> [[T0]], <i8 3, i8 6>568; CHECK-NEXT: ret <2 x i8> [[RET]]569;570 %t0 = lshr <2 x i8> %x, <i8 3, i8 3>571 %ret = shl <2 x i8> %t0, <i8 3, i8 6>572 ret <2 x i8> %ret573}574 575define <2 x i8> @positive_biggerLlshr_vec_nonsplat(<2 x i8> %x) {576; CHECK-LABEL: @positive_biggerLlshr_vec_nonsplat(577; CHECK-NEXT: [[T0:%.*]] = lshr <2 x i8> [[X:%.*]], <i8 3, i8 6>578; CHECK-NEXT: [[RET:%.*]] = shl <2 x i8> [[T0]], splat (i8 3)579; CHECK-NEXT: ret <2 x i8> [[RET]]580;581 %t0 = lshr <2 x i8> %x, <i8 3, i8 6>582 %ret = shl <2 x i8> %t0, <i8 3, i8 3>583 ret <2 x i8> %ret584}585 586; ============================================================================ ;587; Negative tests. Should not be folded.588; ============================================================================ ;589 590define i8 @negative_twovars(i8 %x, i8 %y, i8 %z) {591; CHECK-LABEL: @negative_twovars(592; CHECK-NEXT: [[T0:%.*]] = lshr i8 [[X:%.*]], [[Y:%.*]]593; CHECK-NEXT: [[RET:%.*]] = shl i8 [[T0]], [[Z:%.*]]594; CHECK-NEXT: ret i8 [[RET]]595;596 %t0 = lshr i8 %x, %y597 %ret = shl i8 %t0, %z ; $z, not %y598 ret i8 %ret599}600 601declare void @use32(i8)602 603; One use only.604define i8 @negative_oneuse(i8 %x, i8 %y) {605; CHECK-LABEL: @negative_oneuse(606; CHECK-NEXT: [[T0:%.*]] = lshr i8 [[X:%.*]], [[Y:%.*]]607; CHECK-NEXT: call void @use32(i8 [[T0]])608; CHECK-NEXT: [[RET:%.*]] = shl i8 [[T0]], [[Y]]609; CHECK-NEXT: ret i8 [[RET]]610;611 %t0 = lshr i8 %x, %y612 call void @use32(i8 %t0)613 %ret = shl i8 %t0, %y614 ret i8 %ret615}616