116 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4; insertelements should fold to shuffle5define <4 x float> @foo(<4 x float> %x) {6; CHECK-LABEL: @foo(7; CHECK-NEXT: [[INS2:%.*]] = shufflevector <4 x float> [[X:%.*]], <4 x float> <float poison, float 1.000000e+00, float 2.000000e+00, float poison>, <4 x i32> <i32 0, i32 5, i32 6, i32 3>8; CHECK-NEXT: ret <4 x float> [[INS2]]9;10 %ins1 = insertelement<4 x float> %x, float 1.0, i32 111 %ins2 = insertelement<4 x float> %ins1, float 2.0, i32 212 ret <4 x float> %ins213}14 15; Insert of a constant is canonicalized ahead of insert of a variable.16 17define <4 x float> @bar(<4 x float> %x, float %a) {18; CHECK-LABEL: @bar(19; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x float> [[X:%.*]], float 2.000000e+00, i64 220; CHECK-NEXT: [[INS2:%.*]] = insertelement <4 x float> [[TMP1]], float [[A:%.*]], i64 121; CHECK-NEXT: ret <4 x float> [[INS2]]22;23 %ins1 = insertelement<4 x float> %x, float %a, i32 124 %ins2 = insertelement<4 x float> %ins1, float 2.0, i32 225 ret <4 x float> %ins226}27 28define <4 x float> @baz(<4 x float> %x, i32 %a) {29; CHECK-LABEL: @baz(30; CHECK-NEXT: [[INS1:%.*]] = insertelement <4 x float> [[X:%.*]], float 1.000000e+00, i64 131; CHECK-NEXT: [[INS2:%.*]] = insertelement <4 x float> [[INS1]], float 2.000000e+00, i32 [[A:%.*]]32; CHECK-NEXT: ret <4 x float> [[INS2]]33;34 %ins1 = insertelement<4 x float> %x, float 1.0, i32 135 %ins2 = insertelement<4 x float> %ins1, float 2.0, i32 %a36 ret <4 x float> %ins237}38 39; insertelements should fold to shuffle40define <4 x float> @bazz(<4 x float> %x, i32 %a) {41; CHECK-LABEL: @bazz(42; CHECK-NEXT: [[INS1:%.*]] = insertelement <4 x float> [[X:%.*]], float 1.000000e+00, i64 343; CHECK-NEXT: [[INS2:%.*]] = insertelement <4 x float> [[INS1]], float 5.000000e+00, i32 [[A:%.*]]44; CHECK-NEXT: [[INS5:%.*]] = shufflevector <4 x float> [[INS2]], <4 x float> <float poison, float 1.000000e+00, float 2.000000e+00, float poison>, <4 x i32> <i32 0, i32 5, i32 6, i32 3>45; CHECK-NEXT: [[INS6:%.*]] = insertelement <4 x float> [[INS5]], float 7.000000e+00, i32 [[A]]46; CHECK-NEXT: ret <4 x float> [[INS6]]47;48 %ins1 = insertelement<4 x float> %x, float 1.0, i32 349 %ins2 = insertelement<4 x float> %ins1, float 5.0, i32 %a50 %ins3 = insertelement<4 x float> %ins2, float 3.0, i32 251 %ins4 = insertelement<4 x float> %ins3, float 1.0, i32 152 %ins5 = insertelement<4 x float> %ins4, float 2.0, i32 253 %ins6 = insertelement<4 x float> %ins5, float 7.0, i32 %a54 ret <4 x float> %ins655}56 57; Out of bounds index folds to poison58define <4 x float> @bazzz(<4 x float> %x) {59; CHECK-LABEL: @bazzz(60; CHECK-NEXT: ret <4 x float> <float poison, float poison, float 2.000000e+00, float poison>61;62 %ins1 = insertelement<4 x float> %x, float 1.0, i32 563 %ins2 = insertelement<4 x float> %ins1, float 2.0, i32 264 ret <4 x float> %ins265}66 67define <4 x float> @bazzzz(<4 x float> %x) {68; CHECK-LABEL: @bazzzz(69; CHECK-NEXT: ret <4 x float> <float poison, float poison, float 2.000000e+00, float poison>70;71 %ins1 = insertelement<4 x float> %x, float 1.0, i32 undef72 %ins2 = insertelement<4 x float> %ins1, float 2.0, i32 273 ret <4 x float> %ins274}75 76define <4 x float> @bazzzzz() {77; CHECK-LABEL: @bazzzzz(78; CHECK-NEXT: ret <4 x float> <float 1.000000e+00, float 5.000000e+00, float 1.000000e+01, float 4.000000e+00>79;80 %ins1 = insertelement <4 x float> insertelement (<4 x float> <float 1.0, float 2.0, float 3.0, float undef>, float 4.0, i32 3), float 5.0, i32 181 %ins2 = insertelement<4 x float> %ins1, float 10.0, i32 282 ret <4 x float> %ins283}84 85define <4 x float> @bazzzzzz(<4 x float> %x, i32 %a) {86; CHECK-LABEL: @bazzzzzz(87; CHECK-NEXT: ret <4 x float> <float undef, float 5.000000e+00, float undef, float 4.000000e+00>88;89 %ins1 = insertelement <4 x float> insertelement (<4 x float> shufflevector (<4 x float> undef, <4 x float> <float 1.0, float 2.0, float 3.0, float 4.0> , <4 x i32> <i32 0, i32 5, i32 undef, i32 6> ), float 4.0, i32 3), float 5.0, i32 190 ret <4 x float> %ins191}92 93; test that foldBitcastExtElt doesn't interfere with shuffle folding94 95define <4 x half> @bitcast_extract_insert_to_shuffle(i32 %a, i32 %b) {96; CHECK-LABEL: @bitcast_extract_insert_to_shuffle(97; CHECK-NEXT: [[AVEC:%.*]] = bitcast i32 [[A:%.*]] to <2 x half>98; CHECK-NEXT: [[BVEC:%.*]] = bitcast i32 [[B:%.*]] to <2 x half>99; CHECK-NEXT: [[INS3:%.*]] = shufflevector <2 x half> [[AVEC]], <2 x half> [[BVEC]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>100; CHECK-NEXT: ret <4 x half> [[INS3]]101;102 %avec = bitcast i32 %a to <2 x half>103 %a0 = extractelement <2 x half> %avec, i32 0104 %a1 = extractelement <2 x half> %avec, i32 1105 %bvec = bitcast i32 %b to <2 x half>106 %b0 = extractelement <2 x half> %bvec, i32 0107 %b1 = extractelement <2 x half> %bvec, i32 1108 %ins0 = insertelement <4 x half> undef, half %a0, i32 0109 %ins1 = insertelement <4 x half> %ins0, half %a1, i32 1110 %ins2 = insertelement <4 x half> %ins1, half %b0, i32 2111 %ins3 = insertelement <4 x half> %ins2, half %b1, i32 3112 ret <4 x half> %ins3113}114 115 116