Index: lib/Target/X86/X86ISelLowering.cpp =================================================================== --- lib/Target/X86/X86ISelLowering.cpp +++ lib/Target/X86/X86ISelLowering.cpp @@ -4961,6 +4961,19 @@ return true; } +static bool canWidenShuffleElements(ArrayRef Mask, + const APInt &Zeroable, + SmallVectorImpl &WidenedMask) { + SmallVector TargetMask(Mask.begin(), Mask.end()); + for (int i = 0, Size = TargetMask.size(); i < Size; ++i) { + if (TargetMask[i] == SM_SentinelUndef) + continue; + if (Zeroable[i]) + TargetMask[i] = SM_SentinelZero; + } + return canWidenShuffleElements(TargetMask, WidenedMask); +} + /// Returns true if Elt is a constant zero or a floating point constant +0.0. bool X86::isZeroNode(SDValue Elt) { return isNullConstant(Elt) || isNullFPConstant(Elt); @@ -13126,7 +13139,7 @@ return SDValue(); SmallVector WidenedMask; - if (!canWidenShuffleElements(Mask, WidenedMask)) + if (!canWidenShuffleElements(Mask, Zeroable, WidenedMask)) return SDValue(); bool IsLowZero = (Zeroable & 0x3) == 0x3; @@ -13195,7 +13208,8 @@ // [6] - ignore // [7] - zero high half of destination - assert(WidenedMask[0] >= 0 && WidenedMask[1] >= 0 && "Undef half?"); + assert((WidenedMask[0] >= 0 || IsLowZero) && + (WidenedMask[1] >= 0 || IsHighZero) && "Undef half?"); unsigned PermMask = 0; PermMask |= IsLowZero ? 0x08 : (WidenedMask[0] << 0); Index: test/CodeGen/X86/avx-cast.ll =================================================================== --- test/CodeGen/X86/avx-cast.ll +++ test/CodeGen/X86/avx-cast.ll @@ -20,9 +20,7 @@ define <4 x double> @castB(<2 x double> %m) nounwind uwtable readnone ssp { ; AVX-LABEL: castB: ; AVX: ## %bb.0: -; AVX-NEXT: ## kill: def $xmm0 killed $xmm0 def $ymm0 -; AVX-NEXT: vxorps %xmm1, %xmm1, %xmm1 -; AVX-NEXT: vblendps {{.*#+}} ymm0 = ymm0[0,1,2,3],ymm1[4,5,6,7] +; AVX-NEXT: vmovaps %xmm0, %xmm0 ; AVX-NEXT: retq %shuffle.i = shufflevector <2 x double> %m, <2 x double> zeroinitializer, <4 x i32> ret <4 x double> %shuffle.i @@ -33,9 +31,7 @@ define <4 x i64> @castC(<2 x i64> %m) nounwind uwtable readnone ssp { ; AVX-LABEL: castC: ; AVX: ## %bb.0: -; AVX-NEXT: ## kill: def $xmm0 killed $xmm0 def $ymm0 -; AVX-NEXT: vxorps %xmm1, %xmm1, %xmm1 -; AVX-NEXT: vblendps {{.*#+}} ymm0 = ymm0[0,1,2,3],ymm1[4,5,6,7] +; AVX-NEXT: vmovaps %xmm0, %xmm0 ; AVX-NEXT: retq %shuffle.i = shufflevector <2 x i64> %m, <2 x i64> zeroinitializer, <4 x i32> ret <4 x i64> %shuffle.i