From 6da8a243f91a54096927b566d43665427a18a6cb Mon Sep 17 00:00:00 2001 From: Robert Lougher Date: Mon, 22 Sep 2014 11:54:38 +0000 Subject: Fix assert when decoding PSHUFB mask The PSHUFB mask decode routine used to assert if the mask index was out of range (<0 or greater than the size of the vector). The problem is, we can legitimately have a PSHUFB with a large index using intrinsics. The instruction only uses the least significant 4 bits. This change removes the assert and masks the index to match the instruction behaviour. llvm-svn: 218242 --- llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'llvm/lib/Target') diff --git a/llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp b/llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp index 51d251e551c..6d42a101b0e 100644 --- a/llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp +++ b/llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp @@ -247,9 +247,8 @@ void DecodePSHUFBMask(const ConstantDataSequential *C, if (Element & (1 << 7)) ShuffleMask.push_back(SM_SentinelZero); else { - int Index = Base + Element; - assert((Index >= 0 && Index < NumElements) && - "Out of bounds shuffle index for pshub instruction!"); + // Only the least significant 4 bits of the byte are used. + int Index = Base + (Element & 0xf); ShuffleMask.push_back(Index); } } @@ -266,9 +265,8 @@ void DecodePSHUFBMask(ArrayRef RawMask, if (M & (1 << 7)) ShuffleMask.push_back(SM_SentinelZero); else { - int Index = Base + M; - assert((Index >= 0 && (unsigned)Index < RawMask.size()) && - "Out of bounds shuffle index for pshub instruction!"); + // Only the least significant 4 bits of the byte are used. + int Index = Base + (M & 0xf); ShuffleMask.push_back(Index); } } -- cgit v1.2.3