From 33fc788374b559d449780ec0f7cf9a010d04dadc Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Mon, 8 Aug 2016 11:07:34 +0000 Subject: [PATCH] [X86][SSE] Assert if the shuffle mask indices are not -1 or within a valid input range As discussed in post-review rL277959 llvm-svn: 277993 --- llvm/lib/Target/X86/X86ISelLowering.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 1fb3983..c09d76d 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -12287,14 +12287,11 @@ static SDValue lowerVectorShuffle(SDValue Op, const X86Subtarget &Subtarget, return DAG.getVectorShuffle(VT, DL, V1, V2, NewMask); } - // Ensure that undefined mask elements only use SM_SentinelUndef. - if (llvm::any_of(Mask, [](int M) { return M < SM_SentinelUndef; })) { - SmallVector NewMask(Mask.begin(), Mask.end()); - for (int &M : NewMask) - if (M < SM_SentinelUndef) - M = SM_SentinelUndef; - return DAG.getVectorShuffle(VT, DL, V1, V2, NewMask); - } + // Check for illegal shuffle mask element index values. + int MaskUpperLimit = Mask.size() * (V2IsUndef ? 1 : 2); (void)MaskUpperLimit; + assert(llvm::all_of(Mask, + [&](int M) { return -1 <= M && M < MaskUpperLimit; }) && + "Out of bounds shuffle index"); // We actually see shuffles that are entirely re-arrangements of a set of // zero inputs. This mostly happens while decomposing complex shuffles into -- 2.7.4