Index: lib/CodeGen/SelectionDAG/SelectionDAG.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -4145,6 +4145,13 @@ break; case ISD::VECTOR_SHUFFLE: llvm_unreachable("should use getVectorShuffle constructor!"); + case ISD::INSERT_VECTOR_ELT: { + ConstantSDNode *N3C = dyn_cast(N3); + // INSERT_VECTOR_ELT into out-of-bounds element is an UNDEF + if (N3C && N3C->getZExtValue() >= N1.getValueType().getVectorNumElements()) + return getUNDEF(VT); + break; + } case ISD::INSERT_SUBVECTOR: { SDValue Index = N3; if (VT.isSimple() && N1.getValueType().isSimple() Index: test/CodeGen/PowerPC/vec_add_sub_quadword.ll =================================================================== --- test/CodeGen/PowerPC/vec_add_sub_quadword.ll +++ test/CodeGen/PowerPC/vec_add_sub_quadword.ll @@ -19,11 +19,13 @@ define <1 x i128> @increment_by_val(<1 x i128> %x, i128 %val) nounwind { %tmpvec = insertelement <1 x i128> , i128 %val, i32 0 + ; undef %tmpvec2 = insertelement <1 x i128> %tmpvec, i128 %val, i32 1 %result = add <1 x i128> %x, %tmpvec2 ret <1 x i128> %result ; CHECK-LABEL: @increment_by_val -; CHECK: vadduqm 2, 2, 3 +; CHECK: # BB#0: +; CHECK-NEXT: blr } define <1 x i128> @test_sub(<1 x i128> %x, <1 x i128> %y) nounwind { @@ -42,32 +44,34 @@ define <1 x i128> @decrement_by_val(<1 x i128> %x, i128 %val) nounwind { %tmpvec = insertelement <1 x i128> , i128 %val, i32 0 + ; undef %tmpvec2 = insertelement <1 x i128> %tmpvec, i128 %val, i32 1 %result = sub <1 x i128> %x, %tmpvec2 ret <1 x i128> %result ; CHECK-LABEL: @decrement_by_val -; CHECK: vsubuqm 2, 2, 3 +; CHECK: # BB#0: +; CHECK-NEXT: blr } -declare <1 x i128> @llvm.ppc.altivec.vaddeuqm(<1 x i128> %x, - <1 x i128> %y, +declare <1 x i128> @llvm.ppc.altivec.vaddeuqm(<1 x i128> %x, + <1 x i128> %y, <1 x i128> %z) nounwind readnone -declare <1 x i128> @llvm.ppc.altivec.vaddcuq(<1 x i128> %x, +declare <1 x i128> @llvm.ppc.altivec.vaddcuq(<1 x i128> %x, <1 x i128> %y) nounwind readnone -declare <1 x i128> @llvm.ppc.altivec.vaddecuq(<1 x i128> %x, - <1 x i128> %y, +declare <1 x i128> @llvm.ppc.altivec.vaddecuq(<1 x i128> %x, + <1 x i128> %y, <1 x i128> %z) nounwind readnone -declare <1 x i128> @llvm.ppc.altivec.vsubeuqm(<1 x i128> %x, - <1 x i128> %y, +declare <1 x i128> @llvm.ppc.altivec.vsubeuqm(<1 x i128> %x, + <1 x i128> %y, <1 x i128> %z) nounwind readnone -declare <1 x i128> @llvm.ppc.altivec.vsubcuq(<1 x i128> %x, +declare <1 x i128> @llvm.ppc.altivec.vsubcuq(<1 x i128> %x, <1 x i128> %y) nounwind readnone -declare <1 x i128> @llvm.ppc.altivec.vsubecuq(<1 x i128> %x, - <1 x i128> %y, +declare <1 x i128> @llvm.ppc.altivec.vsubecuq(<1 x i128> %x, + <1 x i128> %y, <1 x i128> %z) nounwind readnone -define <1 x i128> @test_vaddeuqm(<1 x i128> %x, - <1 x i128> %y, +define <1 x i128> @test_vaddeuqm(<1 x i128> %x, + <1 x i128> %y, <1 x i128> %z) nounwind { %tmp = tail call <1 x i128> @llvm.ppc.altivec.vaddeuqm(<1 x i128> %x, <1 x i128> %y, @@ -77,7 +81,7 @@ ; CHECK: vaddeuqm 2, 2, 3, 4 } -define <1 x i128> @test_vaddcuq(<1 x i128> %x, +define <1 x i128> @test_vaddcuq(<1 x i128> %x, <1 x i128> %y) nounwind { %tmp = tail call <1 x i128> @llvm.ppc.altivec.vaddcuq(<1 x i128> %x, <1 x i128> %y) @@ -86,8 +90,8 @@ ; CHECK: vaddcuq 2, 2, 3 } -define <1 x i128> @test_vaddecuq(<1 x i128> %x, - <1 x i128> %y, +define <1 x i128> @test_vaddecuq(<1 x i128> %x, + <1 x i128> %y, <1 x i128> %z) nounwind { %tmp = tail call <1 x i128> @llvm.ppc.altivec.vaddecuq(<1 x i128> %x, <1 x i128> %y, @@ -97,8 +101,8 @@ ; CHECK: vaddecuq 2, 2, 3, 4 } -define <1 x i128> @test_vsubeuqm(<1 x i128> %x, - <1 x i128> %y, +define <1 x i128> @test_vsubeuqm(<1 x i128> %x, + <1 x i128> %y, <1 x i128> %z) nounwind { %tmp = tail call <1 x i128> @llvm.ppc.altivec.vsubeuqm(<1 x i128> %x, <1 x i128> %y, @@ -108,7 +112,7 @@ ; CHECK: vsubeuqm 2, 2, 3, 4 } -define <1 x i128> @test_vsubcuq(<1 x i128> %x, +define <1 x i128> @test_vsubcuq(<1 x i128> %x, <1 x i128> %y) nounwind { %tmp = tail call <1 x i128> @llvm.ppc.altivec.vsubcuq(<1 x i128> %x, <1 x i128> %y) @@ -117,8 +121,8 @@ ; CHECK: vsubcuq 2, 2, 3 } -define <1 x i128> @test_vsubecuq(<1 x i128> %x, - <1 x i128> %y, +define <1 x i128> @test_vsubecuq(<1 x i128> %x, + <1 x i128> %y, <1 x i128> %z) nounwind { %tmp = tail call <1 x i128> @llvm.ppc.altivec.vsubecuq(<1 x i128> %x, <1 x i128> %y, Index: test/CodeGen/X86/avx512-insert-extract.ll =================================================================== --- test/CodeGen/X86/avx512-insert-extract.ll +++ test/CodeGen/X86/avx512-insert-extract.ll @@ -727,18 +727,18 @@ define <2 x i64> @insert_v2i64(<2 x i64> %x, i64 %y , i64* %ptr) { ; KNL-LABEL: insert_v2i64: ; KNL: ## BB#0: +; KNL-NEXT: vpinsrq $0, %rdi, %xmm0, %xmm0 ; KNL-NEXT: vpinsrq $1, (%rsi), %xmm0, %xmm0 -; KNL-NEXT: vpinsrq $3, %rdi, %xmm0, %xmm0 ; KNL-NEXT: retq ; ; SKX-LABEL: insert_v2i64: ; SKX: ## BB#0: +; SKX-NEXT: vpinsrq $0, %rdi, %xmm0, %xmm0 ; SKX-NEXT: vpinsrq $1, (%rsi), %xmm0, %xmm0 -; SKX-NEXT: vpinsrq $3, %rdi, %xmm0, %xmm0 ; SKX-NEXT: retq %val = load i64, i64* %ptr %r1 = insertelement <2 x i64> %x, i64 %val, i32 1 - %r2 = insertelement <2 x i64> %r1, i64 %y, i32 3 + %r2 = insertelement <2 x i64> %r1, i64 %y, i32 0 ret <2 x i64> %r2 }