; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt -S -instcombine < %s | FileCheck %s ; This test checks that bitcast is moved after insertelement when both vector and scalar are ; bitcast from the same element type. ; inselt (bitcast VecSrc), (bitcast ScalarSrc), IdxOp ; --> bitcast (inselt VecSrc, ScalarSrc, IdxOp) define @insertelement_bitcast( %vec, i32 %x) { ; CHECK-LABEL: @insertelement_bitcast( ; CHECK-NEXT: [[TMP1:%.*]] = insertelement [[VEC:%.*]], i32 [[X:%.*]], i32 0 ; CHECK-NEXT: [[R:%.*]] = bitcast [[TMP1]] to ; CHECK-NEXT: ret [[R]] ; %x_cast = bitcast i32 %x to float %vec_cast = bitcast %vec to %r = insertelement %vec_cast, float %x_cast, i32 0 ret %r } ; This test checks that code-path "Try to form a shuffle from a chain of extract-insert ops" is ; not taken when both extract and insert are scalable type. ; For scalable type, the vector length needed to create shuffle mask is not a compile-time constant. ; Meanwhile, for scalable type shuffle mask only support splat and undef in the current code base. ; Otherwise we crash at: ; "Assertion `isValidOperands(V1, V2, Mask) && "Invalid shuffle vector instruction operands!"' failed." define @insertelement_extractelement( %a, %b) { ; CHECK-LABEL: @insertelement_extractelement( ; CHECK-NEXT: [[T0:%.*]] = extractelement [[A:%.*]], i32 1 ; CHECK-NEXT: [[T1:%.*]] = insertelement [[B:%.*]], i32 [[T0]], i32 0 ; CHECK-NEXT: ret [[T1]] ; %t0 = extractelement %a, i32 1 %t1 = insertelement %b, i32 %t0, i32 0 ret %t1 } ; This test checks that we are not attempting to create a shuffle from extract/insert chain, ; when extract is from a scalable type, and the insert vector is fixed-length. define <4 x i32> @insertelement_extractelement_fixed_vec_extract_from_scalable( %a, <4 x i32> %b) { ; CHECK-LABEL: @insertelement_extractelement_fixed_vec_extract_from_scalable( ; CHECK-NEXT: [[T0:%.*]] = extractelement [[A:%.*]], i32 1 ; CHECK-NEXT: [[T1:%.*]] = insertelement <4 x i32> [[B:%.*]], i32 [[T0]], i32 0 ; CHECK-NEXT: ret <4 x i32> [[T1]] ; %t0 = extractelement %a, i32 1 %t1 = insertelement <4 x i32> %b, i32 %t0, i32 0 ret <4 x i32> %t1 } ; This test checks that the optimization "foldConstantInsEltInfoShuffle" is not taken for scalable type. ; Particularly the fold: ; insertelt (insertelt X, C1, CIndex1), C, CIndex ; --> shufflevector X, CVec', Mask' ; For scalable type, the vector length needed to create shuffle mask is not a compile-time constant. ; Meanwhile, for scalable type shuffle mask only support splat and undef in the current code base. ; Otherwise we crash at: ; "Assertion `isValidOperands(V1, V2, Mask) && "Invalid shuffle vector instruction operands!"' failed." define @insertelement_insertelement( %vec) { ; CHECK-LABEL: @insertelement_insertelement( ; CHECK-NEXT: [[T0:%.*]] = insertelement [[VEC:%.*]], i32 1, i32 1 ; CHECK-NEXT: [[T1:%.*]] = insertelement [[T0]], i32 2, i32 2 ; CHECK-NEXT: ret [[T1]] ; %t0 = insertelement %vec, i32 1, i32 1 %t1 = insertelement %t0, i32 2, i32 2 ret %t1 } ; This test checks that the following insertelement sequence is not folded into shuffle splat. ; The length of scalable vector is unknown at compile-time. Therefore the following insertelements ; may not form a valid splat. define @insertelement_sequene_may_not_be_splat(float %x) { ; CHECK-LABEL: @insertelement_sequene_may_not_be_splat( ; CHECK-NEXT: [[T0:%.*]] = insertelement undef, float [[X:%.*]], i32 0 ; CHECK-NEXT: [[T1:%.*]] = insertelement [[T0]], float [[X]], i32 1 ; CHECK-NEXT: [[T2:%.*]] = insertelement [[T1]], float [[X]], i32 2 ; CHECK-NEXT: [[T3:%.*]] = insertelement [[T2]], float [[X]], i32 3 ; CHECK-NEXT: ret [[T3]] ; %t0 = insertelement undef, float %x, i32 0 %t1 = insertelement %t0, float %x, i32 1 %t2 = insertelement %t1, float %x, i32 2 %t3 = insertelement %t2, float %x, i32 3 ret %t3 } ; OSS-Fuzz #27416 ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=27416 define void @ossfuzz_27416(i32 %v) { ; CHECK-LABEL: @ossfuzz_27416( ; CHECK-NEXT: [[IN:%.*]] = insertelement undef, i32 [[V:%.*]], i32 0 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector [[IN]], undef, zeroinitializer ; CHECK-NEXT: [[I1:%.*]] = insertelement [[SPLAT]], i32 undef, i8 -128 ; CHECK-NEXT: store [[I1]], * undef, align 16 ; CHECK-NEXT: ret void ; %in = insertelement undef, i32 %v, i32 0 %splat = shufflevector %in, undef, zeroinitializer %I1 = insertelement %splat, i32 undef, i8 -128 store %I1, * undef, align 16 ret void }