brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.0 KiB · 410a441 Raw
197 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S -data-layout="E-n64" | FileCheck %s --check-prefixes=ALL,BE3; RUN: opt < %s -passes=instcombine -S -data-layout="e-n64" | FileCheck %s --check-prefixes=ALL,LE4 5declare void @use(<2 x i8>)6 7; i16 is a common type, so we can convert independently of the data layout.8; Endian determines if a shift is needed (and so the transform is avoided).9 10define i16 @insert0_v2i8(i16 %x, i8 %y) {11; BE-LABEL: @insert0_v2i8(12; BE-NEXT:    [[V:%.*]] = bitcast i16 [[X:%.*]] to <2 x i8>13; BE-NEXT:    [[I:%.*]] = insertelement <2 x i8> [[V]], i8 [[Y:%.*]], i64 014; BE-NEXT:    [[R:%.*]] = bitcast <2 x i8> [[I]] to i1615; BE-NEXT:    ret i16 [[R]]16;17; LE-LABEL: @insert0_v2i8(18; LE-NEXT:    [[TMP1:%.*]] = and i16 [[X:%.*]], -25619; LE-NEXT:    [[TMP2:%.*]] = zext i8 [[Y:%.*]] to i1620; LE-NEXT:    [[R:%.*]] = or disjoint i16 [[TMP1]], [[TMP2]]21; LE-NEXT:    ret i16 [[R]]22;23  %v = bitcast i16 %x to <2 x i8>24  %i = insertelement <2 x i8> %v, i8 %y, i8 025  %r = bitcast <2 x i8> %i to i1626  ret i16 %r27}28 29; i16 is a common type, so we can convert independently of the data layout.30; Endian determines if a shift is needed (and so the transform is avoided).31 32define i16 @insert1_v2i8(i16 %x, i8 %y) {33; BE-LABEL: @insert1_v2i8(34; BE-NEXT:    [[TMP1:%.*]] = and i16 [[X:%.*]], -25635; BE-NEXT:    [[TMP2:%.*]] = zext i8 [[Y:%.*]] to i1636; BE-NEXT:    [[R:%.*]] = or disjoint i16 [[TMP1]], [[TMP2]]37; BE-NEXT:    ret i16 [[R]]38;39; LE-LABEL: @insert1_v2i8(40; LE-NEXT:    [[V:%.*]] = bitcast i16 [[X:%.*]] to <2 x i8>41; LE-NEXT:    [[I:%.*]] = insertelement <2 x i8> [[V]], i8 [[Y:%.*]], i64 142; LE-NEXT:    [[R:%.*]] = bitcast <2 x i8> [[I]] to i1643; LE-NEXT:    ret i16 [[R]]44;45  %v = bitcast i16 %x to <2 x i8>46  %i = insertelement <2 x i8> %v, i8 %y, i8 147  %r = bitcast <2 x i8> %i to i1648  ret i16 %r49}50 51; i32 is a common type, so we can convert independently of the data layout.52; Endian determines if a shift is needed (and so the transform is avoided).53 54define i32 @insert0_v4i8(i32 %x, i8 %y) {55; BE-LABEL: @insert0_v4i8(56; BE-NEXT:    [[V:%.*]] = bitcast i32 [[X:%.*]] to <4 x i8>57; BE-NEXT:    [[I:%.*]] = insertelement <4 x i8> [[V]], i8 [[Y:%.*]], i64 058; BE-NEXT:    [[R:%.*]] = bitcast <4 x i8> [[I]] to i3259; BE-NEXT:    ret i32 [[R]]60;61; LE-LABEL: @insert0_v4i8(62; LE-NEXT:    [[TMP1:%.*]] = and i32 [[X:%.*]], -25663; LE-NEXT:    [[TMP2:%.*]] = zext i8 [[Y:%.*]] to i3264; LE-NEXT:    [[R:%.*]] = or disjoint i32 [[TMP1]], [[TMP2]]65; LE-NEXT:    ret i32 [[R]]66;67  %v = bitcast i32 %x to <4 x i8>68  %i = insertelement <4 x i8> %v, i8 %y, i8 069  %r = bitcast <4 x i8> %i to i3270  ret i32 %r71}72 73; i32 is a common type, so we can convert independently of the data layout.74; Endian determines if a shift is needed (and so the transform is avoided).75; half type can not be used in zext instruction (and so the transform is avoided).76 77define i32 @insert0_v2half(i32 %x, half %y) {78; ALL-LABEL: @insert0_v2half(79; ALL-NEXT:    [[V:%.*]] = bitcast i32 [[X:%.*]] to <2 x half>80; ALL-NEXT:    [[I:%.*]] = insertelement <2 x half> [[V]], half [[Y:%.*]], i64 081; ALL-NEXT:    [[R:%.*]] = bitcast <2 x half> [[I]] to i3282; ALL-NEXT:    ret i32 [[R]]83;84  %v = bitcast i32 %x to <2 x half>85  %i = insertelement <2 x half> %v, half %y, i8 086  %r = bitcast <2 x half> %i to i3287  ret i32 %r88}89 90; i64 is a legal type, so we can convert based on the data layout.91; Endian determines if a shift is needed (and so the transform is avoided).92 93define i64 @insert0_v4i16(i64 %x, i16 %y) {94; BE-LABEL: @insert0_v4i16(95; BE-NEXT:    [[V:%.*]] = bitcast i64 [[X:%.*]] to <4 x i16>96; BE-NEXT:    [[I:%.*]] = insertelement <4 x i16> [[V]], i16 [[Y:%.*]], i64 097; BE-NEXT:    [[R:%.*]] = bitcast <4 x i16> [[I]] to i6498; BE-NEXT:    ret i64 [[R]]99;100; LE-LABEL: @insert0_v4i16(101; LE-NEXT:    [[TMP1:%.*]] = and i64 [[X:%.*]], -65536102; LE-NEXT:    [[TMP2:%.*]] = zext i16 [[Y:%.*]] to i64103; LE-NEXT:    [[R:%.*]] = or disjoint i64 [[TMP1]], [[TMP2]]104; LE-NEXT:    ret i64 [[R]]105;106  %v = bitcast i64 %x to <4 x i16>107  %i = insertelement <4 x i16> %v, i16 %y, i8 0108  %r = bitcast <4 x i16> %i to i64109  ret i64 %r110}111 112; Negative test - shifts needed for both endians.113 114define i64 @insert1_v4i16(i64 %x, i16 %y) {115; ALL-LABEL: @insert1_v4i16(116; ALL-NEXT:    [[V:%.*]] = bitcast i64 [[X:%.*]] to <4 x i16>117; ALL-NEXT:    [[I:%.*]] = insertelement <4 x i16> [[V]], i16 [[Y:%.*]], i64 1118; ALL-NEXT:    [[R:%.*]] = bitcast <4 x i16> [[I]] to i64119; ALL-NEXT:    ret i64 [[R]]120;121  %v = bitcast i64 %x to <4 x i16>122  %i = insertelement <4 x i16> %v, i16 %y, i8 1123  %r = bitcast <4 x i16> %i to i64124  ret i64 %r125}126 127; i64 is a legal type, so we can convert based on the data layout.128; Endian determines if a shift is needed (and so the transform is avoided).129 130define i64 @insert3_v4i16(i64 %x, i16 %y) {131; BE-LABEL: @insert3_v4i16(132; BE-NEXT:    [[TMP1:%.*]] = and i64 [[X:%.*]], -65536133; BE-NEXT:    [[TMP2:%.*]] = zext i16 [[Y:%.*]] to i64134; BE-NEXT:    [[R:%.*]] = or disjoint i64 [[TMP1]], [[TMP2]]135; BE-NEXT:    ret i64 [[R]]136;137; LE-LABEL: @insert3_v4i16(138; LE-NEXT:    [[V:%.*]] = bitcast i64 [[X:%.*]] to <4 x i16>139; LE-NEXT:    [[I:%.*]] = insertelement <4 x i16> [[V]], i16 [[Y:%.*]], i64 3140; LE-NEXT:    [[R:%.*]] = bitcast <4 x i16> [[I]] to i64141; LE-NEXT:    ret i64 [[R]]142;143  %v = bitcast i64 %x to <4 x i16>144  %i = insertelement <4 x i16> %v, i16 %y, i8 3145  %r = bitcast <4 x i16> %i to i64146  ret i64 %r147}148 149; Negative test - i128 is not a legal type, so we do not convert based on the data layout.150 151define i128 @insert0_v4i32(i128 %x, i32 %y) {152; ALL-LABEL: @insert0_v4i32(153; ALL-NEXT:    [[V:%.*]] = bitcast i128 [[X:%.*]] to <4 x i32>154; ALL-NEXT:    [[I:%.*]] = insertelement <4 x i32> [[V]], i32 [[Y:%.*]], i64 0155; ALL-NEXT:    [[R:%.*]] = bitcast <4 x i32> [[I]] to i128156; ALL-NEXT:    ret i128 [[R]]157;158  %v = bitcast i128 %x to <4 x i32>159  %i = insertelement <4 x i32> %v, i32 %y, i8 0160  %r = bitcast <4 x i32> %i to i128161  ret i128 %r162}163 164; Negative test - extra use requires more instructions.165 166define i16 @insert0_v2i8_use1(i16 %x, i8 %y) {167; ALL-LABEL: @insert0_v2i8_use1(168; ALL-NEXT:    [[V:%.*]] = bitcast i16 [[X:%.*]] to <2 x i8>169; ALL-NEXT:    call void @use(<2 x i8> [[V]])170; ALL-NEXT:    [[I:%.*]] = insertelement <2 x i8> [[V]], i8 [[Y:%.*]], i64 0171; ALL-NEXT:    [[R:%.*]] = bitcast <2 x i8> [[I]] to i16172; ALL-NEXT:    ret i16 [[R]]173;174  %v = bitcast i16 %x to <2 x i8>175  call void @use(<2 x i8> %v)176  %i = insertelement <2 x i8> %v, i8 %y, i8 0177  %r = bitcast <2 x i8> %i to i16178  ret i16 %r179}180 181; Negative test - extra use requires more instructions.182 183define i16 @insert0_v2i8_use2(i16 %x, i8 %y) {184; ALL-LABEL: @insert0_v2i8_use2(185; ALL-NEXT:    [[V:%.*]] = bitcast i16 [[X:%.*]] to <2 x i8>186; ALL-NEXT:    [[I:%.*]] = insertelement <2 x i8> [[V]], i8 [[Y:%.*]], i64 0187; ALL-NEXT:    call void @use(<2 x i8> [[I]])188; ALL-NEXT:    [[R:%.*]] = bitcast <2 x i8> [[I]] to i16189; ALL-NEXT:    ret i16 [[R]]190;191  %v = bitcast i16 %x to <2 x i8>192  %i = insertelement <2 x i8> %v, i8 %y, i8 0193  call void @use(<2 x i8> %i)194  %r = bitcast <2 x i8> %i to i16195  ret i16 %r196}197