From: Simon Pilgrim Date: Thu, 26 Jan 2017 13:06:02 +0000 (+0000) Subject: [X86][SSE] Pull out target shuffle resolve code into helper. NFCI. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b81877488f17ab4fc52381cfa0a074483bf6a10b;p=llvm [X86][SSE] Pull out target shuffle resolve code into helper. NFCI. Pulled out code that removed unused inputs from a target shuffle mask into a helper function to allow it to be reused in a future commit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293175 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index 7dc37f432db..6857c5c7701 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -5808,6 +5808,25 @@ static bool getFauxShuffleMask(SDValue N, SmallVectorImpl &Mask, return false; } +/// Removes unused shuffle source ops and adjusts the shuffle mask accordingly. +static void resolveTargetShuffleInputsAndMask(SmallVectorImpl &Ops, + SmallVectorImpl &Mask) { + int MaskWidth = Mask.size(); + SmallVector UsedOps; + for (int i = 0, e = Ops.size(); i < e; ++i) { + int lo = UsedOps.size() * MaskWidth; + int hi = lo + MaskWidth; + if (any_of(Mask, [lo, hi](int i) { return (lo <= i) && (i < hi); })) { + UsedOps.push_back(Ops[i]); + continue; + } + for (int &M : Mask) + if (lo <= M) + M -= MaskWidth; + } + Ops = UsedOps; +} + /// Calls setTargetShuffleZeroElements to resolve a target shuffle mask's inputs /// and set the SM_SentinelUndef and SM_SentinelZero values. Then check the /// remaining input indices in case we now have a unary shuffle and adjust the @@ -27490,20 +27509,8 @@ static bool combineX86ShufflesRecursively(ArrayRef SrcOps, } // Remove unused shuffle source ops. - SmallVector UsedOps; - for (int i = 0, e = Ops.size(); i < e; ++i) { - int lo = UsedOps.size() * MaskWidth; - int hi = lo + MaskWidth; - if (any_of(Mask, [lo, hi](int i) { return (lo <= i) && (i < hi); })) { - UsedOps.push_back(Ops[i]); - continue; - } - for (int &M : Mask) - if (lo <= M) - M -= MaskWidth; - } - assert(!UsedOps.empty() && "Shuffle with no inputs detected"); - Ops = UsedOps; + resolveTargetShuffleInputsAndMask(Ops, Mask); + assert(!Ops.empty() && "Shuffle with no inputs detected"); HasVariableMask |= isTargetShuffleVariableMask(Op.getOpcode());