From 386e47a61717e7613be2264dbe4c0f97b90d5ba6 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Sun, 13 Oct 2019 17:03:02 +0000 Subject: [PATCH] [X86] getTargetShuffleInputs - add KnownUndef/Zero output support Adjust SimplifyDemandedVectorEltsForTargetNode to use the known elts masks instead of recomputing it locally. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@374724 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/X86ISelLowering.cpp | 50 +++++++++++++++--------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index 58cf9bd5174..87cee5e072a 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -7248,13 +7248,13 @@ static void resolveTargetShuffleInputsAndMask(SmallVectorImpl &Inputs, static bool getTargetShuffleInputs(SDValue Op, const APInt &DemandedElts, SmallVectorImpl &Inputs, SmallVectorImpl &Mask, + APInt &KnownUndef, APInt &KnownZero, SelectionDAG &DAG, unsigned Depth, bool ResolveZero) { EVT VT = Op.getValueType(); if (!VT.isSimple() || !VT.isVector()) return false; - APInt KnownUndef, KnownZero; if (getTargetShuffleAndZeroables(Op, Mask, Inputs, KnownUndef, KnownZero)) { for (int i = 0, e = Mask.size(); i != e; ++i) { int &M = Mask[i]; @@ -7267,8 +7267,19 @@ static bool getTargetShuffleInputs(SDValue Op, const APInt &DemandedElts, } return true; } - return getFauxShuffleMask(Op, DemandedElts, Mask, Inputs, DAG, Depth, - ResolveZero); + if (getFauxShuffleMask(Op, DemandedElts, Mask, Inputs, DAG, Depth, + ResolveZero)) { + KnownUndef = KnownZero = APInt::getNullValue(Mask.size()); + for (int i = 0, e = Mask.size(); i != e; ++i) { + int M = Mask[i]; + if (SM_SentinelUndef == M) + KnownUndef.setBit(i); + if (SM_SentinelZero == M) + KnownZero.setBit(i); + } + return true; + } + return false; } static bool getTargetShuffleInputs(SDValue Op, SmallVectorImpl &Inputs, @@ -7279,10 +7290,11 @@ static bool getTargetShuffleInputs(SDValue Op, SmallVectorImpl &Inputs, if (!VT.isSimple() || !VT.isVector()) return false; + APInt KnownUndef, KnownZero; unsigned NumElts = Op.getValueType().getVectorNumElements(); APInt DemandedElts = APInt::getAllOnesValue(NumElts); - return getTargetShuffleInputs(Op, DemandedElts, Inputs, Mask, DAG, Depth, - ResolveZero); + return getTargetShuffleInputs(Op, DemandedElts, Inputs, Mask, KnownUndef, + KnownZero, DAG, Depth, ResolveZero); } /// Returns the scalar element that will make up the ith @@ -34572,10 +34584,11 @@ bool X86TargetLowering::SimplifyDemandedVectorEltsForTargetNode( } // Get target/faux shuffle mask. + APInt OpUndef, OpZero; SmallVector OpMask; SmallVector OpInputs; - if (!getTargetShuffleInputs(Op, DemandedElts, OpInputs, OpMask, TLO.DAG, - Depth, false)) + if (!getTargetShuffleInputs(Op, DemandedElts, OpInputs, OpMask, OpUndef, + OpZero, TLO.DAG, Depth, false)) return false; // Shuffle inputs must be the same size as the result. @@ -34586,19 +34599,14 @@ bool X86TargetLowering::SimplifyDemandedVectorEltsForTargetNode( })) return false; - // Clear known elts that might have been set above. - KnownZero.clearAllBits(); - KnownUndef.clearAllBits(); + KnownZero = OpZero; + KnownUndef = OpUndef; // Check if shuffle mask can be simplified to undef/zero/identity. int NumSrcs = OpInputs.size(); - for (int i = 0; i != NumElts; ++i) { - int &M = OpMask[i]; + for (int i = 0; i != NumElts; ++i) if (!DemandedElts[i]) - M = SM_SentinelUndef; - else if (0 <= M && OpInputs[M / NumElts].isUndef()) - M = SM_SentinelUndef; - } + OpMask[i] = SM_SentinelUndef; if (isUndefInRange(OpMask, 0, NumElts)) { KnownUndef.setAllBits(); @@ -34628,21 +34636,13 @@ bool X86TargetLowering::SimplifyDemandedVectorEltsForTargetNode( SrcElts.setBit(M); } + // TODO - Propagate input undef/zero elts. APInt SrcUndef, SrcZero; if (SimplifyDemandedVectorElts(OpInputs[Src], SrcElts, SrcUndef, SrcZero, TLO, Depth + 1)) return true; } - // Extract known zero/undef elements. - // TODO - Propagate input undef/zero elts. - for (int i = 0; i != NumElts; ++i) { - if (OpMask[i] == SM_SentinelUndef) - KnownUndef.setBit(i); - if (OpMask[i] == SM_SentinelZero) - KnownZero.setBit(i); - } - return false; } -- 2.40.0