// TODO: Generalize this, so it can be called from visitINSERT_VECTOR_ELT().
SDValue Scalar = N->getOperand(0);
unsigned Opcode = Scalar.getOpcode();
+ EVT VecEltVT = VT.getScalarType();
if (Scalar.hasOneUse() && Scalar->getNumValues() == 1 &&
- TLI.isBinOp(Opcode) && VT.getScalarType() == Scalar.getValueType() &&
+ TLI.isBinOp(Opcode) && Scalar.getValueType() == VecEltVT &&
+ Scalar.getOperand(0).getValueType() == VecEltVT &&
+ Scalar.getOperand(1).getValueType() == VecEltVT &&
DAG.isSafeToSpeculativelyExecute(Opcode) && hasOperation(Opcode, VT)) {
// Match an extract element and get a shuffle mask equivalent.
SmallVector<int, 8> ShufMask(VT.getVectorNumElements(), -1);
return SDValue();
// If we have an implicit truncate, truncate here if it is legal.
- if (VT.getScalarType() != Scalar.getValueType() &&
- Scalar.getValueType().isScalarInteger() &&
- isTypeLegal(VT.getScalarType())) {
- SDValue Val =
- DAG.getNode(ISD::TRUNCATE, SDLoc(Scalar), VT.getScalarType(), Scalar);
+ if (VecEltVT != Scalar.getValueType() &&
+ Scalar.getValueType().isScalarInteger() && isTypeLegal(VecEltVT)) {
+ SDValue Val = DAG.getNode(ISD::TRUNCATE, SDLoc(Scalar), VecEltVT, Scalar);
return DAG.getNode(ISD::SCALAR_TO_VECTOR, SDLoc(N), VT, Val);
}
EVT SrcVT = SrcVec.getValueType();
unsigned SrcNumElts = SrcVT.getVectorNumElements();
unsigned VTNumElts = VT.getVectorNumElements();
- if (VT.getScalarType() == SrcVT.getScalarType() && VTNumElts <= SrcNumElts) {
+ if (VecEltVT == SrcVT.getScalarType() && VTNumElts <= SrcNumElts) {
// Create a shuffle equivalent for scalar-to-vector: {ExtIndex, -1, -1, ...}
SmallVector<int, 8> Mask(SrcNumElts, -1);
Mask[0] = ExtIndexC->getZExtValue();
ret <4 x i32> %r
}
+; This would crash because the scalar shift amount has a different type than the shift result.
+
+define <2 x i8> @PR58661(<2 x i8> %a0) {
+; CHECK-LABEL: PR58661:
+; CHECK: # %bb.0:
+; CHECK-NEXT: psrlw $8, %xmm0
+; CHECK-NEXT: movd %xmm0, %eax
+; CHECK-NEXT: shll $8, %eax
+; CHECK-NEXT: movd %eax, %xmm0
+; CHECK-NEXT: ret{{[l|q]}}
+ %shuffle = shufflevector <2 x i8> %a0, <2 x i8> <i8 poison, i8 0>, <2 x i32> <i32 1, i32 3>
+ %x = bitcast <2 x i8> %shuffle to i16
+ %shl = shl nuw i16 %x, 8
+ %y = bitcast i16 %shl to <2 x i8>
+ ret <2 x i8> %y
+}
+
declare <8 x i16> @llvm.x86.sse2.pslli.w(<8 x i16>, i32)
declare <8 x i16> @llvm.x86.sse2.psrli.w(<8 x i16>, i32)
declare <8 x i16> @llvm.x86.sse2.psrai.w(<8 x i16>, i32)