brintos

brintos / llvm-project-archived public Read only

0
0
Text · 15.0 KiB · f5f1051 Raw
381 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S -data-layout="E" | FileCheck %s --check-prefixes=ALL,BE3; RUN: opt < %s -passes=instcombine -S -data-layout="e" | FileCheck %s --check-prefixes=ALL,LE4 5 6declare void @use(i16)7declare void @use_vec(<8 x i16>)8 9define <4 x i16> @insert_01_poison_v4i16(i32 %x) {10; BE-LABEL: @insert_01_poison_v4i16(11; BE-NEXT:    [[HI32:%.*]] = lshr i32 [[X:%.*]], 1612; BE-NEXT:    [[HI16:%.*]] = trunc nuw i32 [[HI32]] to i1613; BE-NEXT:    [[LO16:%.*]] = trunc i32 [[X]] to i1614; BE-NEXT:    [[INS0:%.*]] = insertelement <4 x i16> poison, i16 [[LO16]], i64 015; BE-NEXT:    [[INS1:%.*]] = insertelement <4 x i16> [[INS0]], i16 [[HI16]], i64 116; BE-NEXT:    ret <4 x i16> [[INS1]]17;18; LE-LABEL: @insert_01_poison_v4i16(19; LE-NEXT:    [[TMP1:%.*]] = insertelement <2 x i32> poison, i32 [[X:%.*]], i64 020; LE-NEXT:    [[INS1:%.*]] = bitcast <2 x i32> [[TMP1]] to <4 x i16>21; LE-NEXT:    ret <4 x i16> [[INS1]]22;23  %hi32 = lshr i32 %x, 1624  %hi16 = trunc i32 %hi32 to i1625  %lo16 = trunc i32 %x to i1626  %ins0 = insertelement <4 x i16> poison, i16 %lo16, i64 027  %ins1 = insertelement <4 x i16> %ins0, i16 %hi16, i64 128  ret <4 x i16> %ins129}30 31define <8 x i16> @insert_10_poison_v8i16(i32 %x) {32; BE-LABEL: @insert_10_poison_v8i16(33; BE-NEXT:    [[TMP1:%.*]] = insertelement <4 x i32> poison, i32 [[X:%.*]], i64 034; BE-NEXT:    [[INS1:%.*]] = bitcast <4 x i32> [[TMP1]] to <8 x i16>35; BE-NEXT:    ret <8 x i16> [[INS1]]36;37; LE-LABEL: @insert_10_poison_v8i16(38; LE-NEXT:    [[HI32:%.*]] = lshr i32 [[X:%.*]], 1639; LE-NEXT:    [[HI16:%.*]] = trunc nuw i32 [[HI32]] to i1640; LE-NEXT:    [[LO16:%.*]] = trunc i32 [[X]] to i1641; LE-NEXT:    [[TMP1:%.*]] = insertelement <8 x i16> poison, i16 [[HI16]], i64 042; LE-NEXT:    [[INS1:%.*]] = insertelement <8 x i16> [[TMP1]], i16 [[LO16]], i64 143; LE-NEXT:    ret <8 x i16> [[INS1]]44;45  %hi32 = lshr i32 %x, 1646  %hi16 = trunc i32 %hi32 to i1647  %lo16 = trunc i32 %x to i1648  %ins0 = insertelement <8 x i16> poison, i16 %lo16, i64 149  %ins1 = insertelement <8 x i16> %ins0, i16 %hi16, i64 050  ret <8 x i16> %ins151}52 53; negative test - larger element is not aligned in the vector54 55define <4 x i32> @insert_12_poison_v4i32(i64 %x) {56; ALL-LABEL: @insert_12_poison_v4i32(57; ALL-NEXT:    [[HI64:%.*]] = lshr i64 [[X:%.*]], 3258; ALL-NEXT:    [[HI32:%.*]] = trunc nuw i64 [[HI64]] to i3259; ALL-NEXT:    [[LO32:%.*]] = trunc i64 [[X]] to i3260; ALL-NEXT:    [[INS0:%.*]] = insertelement <4 x i32> poison, i32 [[LO32]], i64 161; ALL-NEXT:    [[INS1:%.*]] = insertelement <4 x i32> [[INS0]], i32 [[HI32]], i64 262; ALL-NEXT:    ret <4 x i32> [[INS1]]63;64  %hi64 = lshr i64 %x, 3265  %hi32 = trunc i64 %hi64 to i3266  %lo32 = trunc i64 %x to i3267  %ins0 = insertelement <4 x i32> poison, i32 %lo32, i64 168  %ins1 = insertelement <4 x i32> %ins0, i32 %hi32, i64 269  ret <4 x i32> %ins170}71 72; negative test - larger element is not aligned in the vector73 74define <4 x i16> @insert_21_poison_v4i16(i32 %x) {75; ALL-LABEL: @insert_21_poison_v4i16(76; ALL-NEXT:    [[HI32:%.*]] = lshr i32 [[X:%.*]], 1677; ALL-NEXT:    [[HI16:%.*]] = trunc nuw i32 [[HI32]] to i1678; ALL-NEXT:    [[LO16:%.*]] = trunc i32 [[X]] to i1679; ALL-NEXT:    [[TMP1:%.*]] = insertelement <4 x i16> poison, i16 [[HI16]], i64 180; ALL-NEXT:    [[INS1:%.*]] = insertelement <4 x i16> [[TMP1]], i16 [[LO16]], i64 281; ALL-NEXT:    ret <4 x i16> [[INS1]]82;83  %hi32 = lshr i32 %x, 1684  %hi16 = trunc i32 %hi32 to i1685  %lo16 = trunc i32 %x to i1686  %ins0 = insertelement <4 x i16> poison, i16 %lo16, i64 287  %ins1 = insertelement <4 x i16> %ins0, i16 %hi16, i64 188  ret <4 x i16> %ins189}90 91define <4 x i32> @insert_23_poison_v4i32(i64 %x) {92; BE-LABEL: @insert_23_poison_v4i32(93; BE-NEXT:    [[HI64:%.*]] = lshr i64 [[X:%.*]], 3294; BE-NEXT:    [[HI32:%.*]] = trunc nuw i64 [[HI64]] to i3295; BE-NEXT:    [[LO32:%.*]] = trunc i64 [[X]] to i3296; BE-NEXT:    [[INS0:%.*]] = insertelement <4 x i32> poison, i32 [[LO32]], i64 297; BE-NEXT:    [[INS1:%.*]] = insertelement <4 x i32> [[INS0]], i32 [[HI32]], i64 398; BE-NEXT:    ret <4 x i32> [[INS1]]99;100; LE-LABEL: @insert_23_poison_v4i32(101; LE-NEXT:    [[TMP1:%.*]] = insertelement <2 x i64> poison, i64 [[X:%.*]], i64 1102; LE-NEXT:    [[INS1:%.*]] = bitcast <2 x i64> [[TMP1]] to <4 x i32>103; LE-NEXT:    ret <4 x i32> [[INS1]]104;105  %hi64 = lshr i64 %x, 32106  %hi32 = trunc i64 %hi64 to i32107  %lo32 = trunc i64 %x to i32108  %ins0 = insertelement <4 x i32> poison, i32 %lo32, i64 2109  %ins1 = insertelement <4 x i32> %ins0, i32 %hi32, i64 3110  ret <4 x i32> %ins1111}112 113define <4 x i16> @insert_32_poison_v4i16(i32 %x) {114; BE-LABEL: @insert_32_poison_v4i16(115; BE-NEXT:    [[TMP1:%.*]] = insertelement <2 x i32> poison, i32 [[X:%.*]], i64 1116; BE-NEXT:    [[INS1:%.*]] = bitcast <2 x i32> [[TMP1]] to <4 x i16>117; BE-NEXT:    ret <4 x i16> [[INS1]]118;119; LE-LABEL: @insert_32_poison_v4i16(120; LE-NEXT:    [[HI32:%.*]] = lshr i32 [[X:%.*]], 16121; LE-NEXT:    [[HI16:%.*]] = trunc nuw i32 [[HI32]] to i16122; LE-NEXT:    [[LO16:%.*]] = trunc i32 [[X]] to i16123; LE-NEXT:    [[TMP1:%.*]] = insertelement <4 x i16> poison, i16 [[HI16]], i64 2124; LE-NEXT:    [[INS1:%.*]] = insertelement <4 x i16> [[TMP1]], i16 [[LO16]], i64 3125; LE-NEXT:    ret <4 x i16> [[INS1]]126;127  %hi32 = lshr i32 %x, 16128  %hi16 = trunc i32 %hi32 to i16129  %lo16 = trunc i32 %x to i16130  %ins0 = insertelement <4 x i16> poison, i16 %lo16, i64 3131  %ins1 = insertelement <4 x i16> %ins0, i16 %hi16, i64 2132  ret <4 x i16> %ins1133}134 135; Similar to the above tests but with a non-poison base vector.136 137; Vector is same size as scalar, so this is just a cast.138; TODO: Could be swapped/rotated into place.139 140define <2 x i16> @insert_01_v2i16(i32 %x, <2 x i16> %v) {141; BE-LABEL: @insert_01_v2i16(142; BE-NEXT:    [[HI32:%.*]] = lshr i32 [[X:%.*]], 16143; BE-NEXT:    [[HI16:%.*]] = trunc nuw i32 [[HI32]] to i16144; BE-NEXT:    [[LO16:%.*]] = trunc i32 [[X]] to i16145; BE-NEXT:    [[INS0:%.*]] = insertelement <2 x i16> poison, i16 [[LO16]], i64 0146; BE-NEXT:    [[INS1:%.*]] = insertelement <2 x i16> [[INS0]], i16 [[HI16]], i64 1147; BE-NEXT:    ret <2 x i16> [[INS1]]148;149; LE-LABEL: @insert_01_v2i16(150; LE-NEXT:    [[INS1:%.*]] = bitcast i32 [[X:%.*]] to <2 x i16>151; LE-NEXT:    ret <2 x i16> [[INS1]]152;153  %hi32 = lshr i32 %x, 16154  %hi16 = trunc i32 %hi32 to i16155  %lo16 = trunc i32 %x to i16156  %ins0 = insertelement <2 x i16> %v, i16 %lo16, i64 0157  %ins1 = insertelement <2 x i16> %ins0, i16 %hi16, i64 1158  ret <2 x i16> %ins1159}160 161; negative test - can't do this safely without knowing something about the base vector162 163define <8 x i16> @insert_10_v8i16(i32 %x, <8 x i16> %v) {164; ALL-LABEL: @insert_10_v8i16(165; ALL-NEXT:    [[HI32:%.*]] = lshr i32 [[X:%.*]], 16166; ALL-NEXT:    [[HI16:%.*]] = trunc nuw i32 [[HI32]] to i16167; ALL-NEXT:    [[LO16:%.*]] = trunc i32 [[X]] to i16168; ALL-NEXT:    [[TMP1:%.*]] = insertelement <8 x i16> [[V:%.*]], i16 [[HI16]], i64 0169; ALL-NEXT:    [[INS1:%.*]] = insertelement <8 x i16> [[TMP1]], i16 [[LO16]], i64 1170; ALL-NEXT:    ret <8 x i16> [[INS1]]171;172  %hi32 = lshr i32 %x, 16173  %hi16 = trunc i32 %hi32 to i16174  %lo16 = trunc i32 %x to i16175  %ins0 = insertelement <8 x i16> %v, i16 %lo16, i64 1176  %ins1 = insertelement <8 x i16> %ins0, i16 %hi16, i64 0177  ret <8 x i16> %ins1178}179 180; negative test - larger element is not aligned in the vector181 182define <4 x i32> @insert_12_v4i32(i64 %x, <4 x i32> %v) {183; ALL-LABEL: @insert_12_v4i32(184; ALL-NEXT:    [[HI64:%.*]] = lshr i64 [[X:%.*]], 32185; ALL-NEXT:    [[HI32:%.*]] = trunc nuw i64 [[HI64]] to i32186; ALL-NEXT:    [[LO32:%.*]] = trunc i64 [[X]] to i32187; ALL-NEXT:    [[INS0:%.*]] = insertelement <4 x i32> [[V:%.*]], i32 [[LO32]], i64 1188; ALL-NEXT:    [[INS1:%.*]] = insertelement <4 x i32> [[INS0]], i32 [[HI32]], i64 2189; ALL-NEXT:    ret <4 x i32> [[INS1]]190;191  %hi64 = lshr i64 %x, 32192  %hi32 = trunc i64 %hi64 to i32193  %lo32 = trunc i64 %x to i32194  %ins0 = insertelement <4 x i32> %v, i32 %lo32, i64 1195  %ins1 = insertelement <4 x i32> %ins0, i32 %hi32, i64 2196  ret <4 x i32> %ins1197}198 199; negative test - larger element is not aligned in the vector200 201define <4 x i16> @insert_21_v4i16(i32 %x, <4 x i16> %v) {202; ALL-LABEL: @insert_21_v4i16(203; ALL-NEXT:    [[HI32:%.*]] = lshr i32 [[X:%.*]], 16204; ALL-NEXT:    [[HI16:%.*]] = trunc nuw i32 [[HI32]] to i16205; ALL-NEXT:    [[LO16:%.*]] = trunc i32 [[X]] to i16206; ALL-NEXT:    [[TMP1:%.*]] = insertelement <4 x i16> [[V:%.*]], i16 [[HI16]], i64 1207; ALL-NEXT:    [[INS1:%.*]] = insertelement <4 x i16> [[TMP1]], i16 [[LO16]], i64 2208; ALL-NEXT:    ret <4 x i16> [[INS1]]209;210  %hi32 = lshr i32 %x, 16211  %hi16 = trunc i32 %hi32 to i16212  %lo16 = trunc i32 %x to i16213  %ins0 = insertelement <4 x i16> %v, i16 %lo16, i64 2214  %ins1 = insertelement <4 x i16> %ins0, i16 %hi16, i64 1215  ret <4 x i16> %ins1216}217 218; negative test - can't do this safely without knowing something about the base vector219 220define <4 x i32> @insert_23_v4i32(i64 %x, <4 x i32> %v) {221; ALL-LABEL: @insert_23_v4i32(222; ALL-NEXT:    [[HI64:%.*]] = lshr i64 [[X:%.*]], 32223; ALL-NEXT:    [[HI32:%.*]] = trunc nuw i64 [[HI64]] to i32224; ALL-NEXT:    [[LO32:%.*]] = trunc i64 [[X]] to i32225; ALL-NEXT:    [[INS0:%.*]] = insertelement <4 x i32> [[V:%.*]], i32 [[LO32]], i64 2226; ALL-NEXT:    [[INS1:%.*]] = insertelement <4 x i32> [[INS0]], i32 [[HI32]], i64 3227; ALL-NEXT:    ret <4 x i32> [[INS1]]228;229  %hi64 = lshr i64 %x, 32230  %hi32 = trunc i64 %hi64 to i32231  %lo32 = trunc i64 %x to i32232  %ins0 = insertelement <4 x i32> %v, i32 %lo32, i64 2233  %ins1 = insertelement <4 x i32> %ins0, i32 %hi32, i64 3234  ret <4 x i32> %ins1235}236 237; negative test - can't do this safely without knowing something about the base vector238 239define <4 x i16> @insert_32_v4i16(i32 %x, <4 x i16> %v) {240; ALL-LABEL: @insert_32_v4i16(241; ALL-NEXT:    [[HI32:%.*]] = lshr i32 [[X:%.*]], 16242; ALL-NEXT:    [[HI16:%.*]] = trunc nuw i32 [[HI32]] to i16243; ALL-NEXT:    [[LO16:%.*]] = trunc i32 [[X]] to i16244; ALL-NEXT:    [[TMP1:%.*]] = insertelement <4 x i16> [[V:%.*]], i16 [[HI16]], i64 2245; ALL-NEXT:    [[INS1:%.*]] = insertelement <4 x i16> [[TMP1]], i16 [[LO16]], i64 3246; ALL-NEXT:    ret <4 x i16> [[INS1]]247;248  %hi32 = lshr i32 %x, 16249  %hi16 = trunc i32 %hi32 to i16250  %lo16 = trunc i32 %x to i16251  %ins0 = insertelement <4 x i16> %v, i16 %lo16, i64 3252  %ins1 = insertelement <4 x i16> %ins0, i16 %hi16, i64 2253  ret <4 x i16> %ins1254}255 256; negative test - need half-width shift257 258define <4 x i16> @insert_01_v4i16_wrong_shift1(i32 %x) {259; ALL-LABEL: @insert_01_v4i16_wrong_shift1(260; ALL-NEXT:    [[HI32:%.*]] = lshr i32 [[X:%.*]], 8261; ALL-NEXT:    [[HI16:%.*]] = trunc i32 [[HI32]] to i16262; ALL-NEXT:    [[LO16:%.*]] = trunc i32 [[X]] to i16263; ALL-NEXT:    [[INS0:%.*]] = insertelement <4 x i16> poison, i16 [[LO16]], i64 0264; ALL-NEXT:    [[INS1:%.*]] = insertelement <4 x i16> [[INS0]], i16 [[HI16]], i64 1265; ALL-NEXT:    ret <4 x i16> [[INS1]]266;267  %hi32 = lshr i32 %x, 8268  %hi16 = trunc i32 %hi32 to i16269  %lo16 = trunc i32 %x to i16270  %ins0 = insertelement <4 x i16> poison, i16 %lo16, i64 0271  %ins1 = insertelement <4 x i16> %ins0, i16 %hi16, i64 1272  ret <4 x i16> %ins1273}274 275; negative test - need common scalar276 277define <4 x i16> @insert_01_v4i16_wrong_op(i32 %x, i32 %y) {278; ALL-LABEL: @insert_01_v4i16_wrong_op(279; ALL-NEXT:    [[HI32:%.*]] = lshr i32 [[X:%.*]], 16280; ALL-NEXT:    [[HI16:%.*]] = trunc nuw i32 [[HI32]] to i16281; ALL-NEXT:    [[LO16:%.*]] = trunc i32 [[Y:%.*]] to i16282; ALL-NEXT:    [[INS0:%.*]] = insertelement <4 x i16> poison, i16 [[LO16]], i64 0283; ALL-NEXT:    [[INS1:%.*]] = insertelement <4 x i16> [[INS0]], i16 [[HI16]], i64 1284; ALL-NEXT:    ret <4 x i16> [[INS1]]285;286  %hi32 = lshr i32 %x, 16287  %hi16 = trunc i32 %hi32 to i16288  %lo16 = trunc i32 %y to i16289  %ins0 = insertelement <4 x i16> poison, i16 %lo16, i64 0290  %ins1 = insertelement <4 x i16> %ins0, i16 %hi16, i64 1291  ret <4 x i16> %ins1292}293 294; TODO: extra use doesn't have to prevent the fold.295 296define <8 x i16> @insert_67_v4i16_uses1(i32 %x, <8 x i16> %v) {297; ALL-LABEL: @insert_67_v4i16_uses1(298; ALL-NEXT:    [[HI32:%.*]] = lshr i32 [[X:%.*]], 16299; ALL-NEXT:    [[HI16:%.*]] = trunc nuw i32 [[HI32]] to i16300; ALL-NEXT:    call void @use(i16 [[HI16]])301; ALL-NEXT:    [[LO16:%.*]] = trunc i32 [[X]] to i16302; ALL-NEXT:    [[INS0:%.*]] = insertelement <8 x i16> [[V:%.*]], i16 [[LO16]], i64 6303; ALL-NEXT:    [[INS1:%.*]] = insertelement <8 x i16> [[INS0]], i16 [[HI16]], i64 7304; ALL-NEXT:    ret <8 x i16> [[INS1]]305;306  %hi32 = lshr i32 %x, 16307  %hi16 = trunc i32 %hi32 to i16308  call void @use(i16 %hi16)309  %lo16 = trunc i32 %x to i16310  %ins0 = insertelement <8 x i16> %v, i16 %lo16, i64 6311  %ins1 = insertelement <8 x i16> %ins0, i16 %hi16, i64 7312  ret <8 x i16> %ins1313}314 315; negative test - can't do this safely without knowing something about the base vector316; extra use would be ok317 318define <8 x i16> @insert_76_v4i16_uses2(i32 %x, <8 x i16> %v) {319; ALL-LABEL: @insert_76_v4i16_uses2(320; ALL-NEXT:    [[HI32:%.*]] = lshr i32 [[X:%.*]], 16321; ALL-NEXT:    [[HI16:%.*]] = trunc nuw i32 [[HI32]] to i16322; ALL-NEXT:    [[LO16:%.*]] = trunc i32 [[X]] to i16323; ALL-NEXT:    call void @use(i16 [[LO16]])324; ALL-NEXT:    [[TMP1:%.*]] = insertelement <8 x i16> [[V:%.*]], i16 [[HI16]], i64 6325; ALL-NEXT:    [[INS1:%.*]] = insertelement <8 x i16> [[TMP1]], i16 [[LO16]], i64 7326; ALL-NEXT:    ret <8 x i16> [[INS1]]327;328  %hi32 = lshr i32 %x, 16329  %hi16 = trunc i32 %hi32 to i16330  %lo16 = trunc i32 %x to i16331  call void @use(i16 %lo16)332  %ins0 = insertelement <8 x i16> %v, i16 %lo16, i64 7333  %ins1 = insertelement <8 x i16> %ins0, i16 %hi16, i64 6334  ret <8 x i16> %ins1335}336 337; TODO: extra use doesn't have to prevent the fold.338 339define <8 x i16> @insert_67_v4i16_uses3(i32 %x, <8 x i16> %v) {340; ALL-LABEL: @insert_67_v4i16_uses3(341; ALL-NEXT:    [[HI32:%.*]] = lshr i32 [[X:%.*]], 16342; ALL-NEXT:    [[HI16:%.*]] = trunc nuw i32 [[HI32]] to i16343; ALL-NEXT:    [[LO16:%.*]] = trunc i32 [[X]] to i16344; ALL-NEXT:    [[INS0:%.*]] = insertelement <8 x i16> [[V:%.*]], i16 [[LO16]], i64 6345; ALL-NEXT:    call void @use_vec(<8 x i16> [[INS0]])346; ALL-NEXT:    [[INS1:%.*]] = insertelement <8 x i16> [[INS0]], i16 [[HI16]], i64 7347; ALL-NEXT:    ret <8 x i16> [[INS1]]348;349  %hi32 = lshr i32 %x, 16350  %hi16 = trunc i32 %hi32 to i16351  %lo16 = trunc i32 %x to i16352  %ins0 = insertelement <8 x i16> %v, i16 %lo16, i64 6353  call void @use_vec(<8 x i16> %ins0)354  %ins1 = insertelement <8 x i16> %ins0, i16 %hi16, i64 7355  ret <8 x i16> %ins1356}357 358; TODO: This is equivalent to the 1st test.359 360define <4 x i16> @insert_01_poison_v4i16_high_first(i32 %x) {361; BE-LABEL: @insert_01_poison_v4i16_high_first(362; BE-NEXT:    [[HI32:%.*]] = lshr i32 [[X:%.*]], 16363; BE-NEXT:    [[HI16:%.*]] = trunc nuw i32 [[HI32]] to i16364; BE-NEXT:    [[LO16:%.*]] = trunc i32 [[X]] to i16365; BE-NEXT:    [[TMP1:%.*]] = insertelement <4 x i16> poison, i16 [[LO16]], i64 0366; BE-NEXT:    [[INS0:%.*]] = insertelement <4 x i16> [[TMP1]], i16 [[HI16]], i64 1367; BE-NEXT:    ret <4 x i16> [[INS0]]368;369; LE-LABEL: @insert_01_poison_v4i16_high_first(370; LE-NEXT:    [[TMP1:%.*]] = insertelement <2 x i32> poison, i32 [[X:%.*]], i64 0371; LE-NEXT:    [[INS0:%.*]] = bitcast <2 x i32> [[TMP1]] to <4 x i16>372; LE-NEXT:    ret <4 x i16> [[INS0]]373;374  %hi32 = lshr i32 %x, 16375  %hi16 = trunc i32 %hi32 to i16376  %lo16 = trunc i32 %x to i16377  %ins1 = insertelement <4 x i16> poison, i16 %hi16, i64 1378  %ins0 = insertelement <4 x i16> %ins1, i16 %lo16, i64 0379  ret <4 x i16> %ins0380}381