diff options
author | Sanjay Patel <spatel@rotateright.com> | 2016-02-09 17:39:58 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2016-02-09 17:39:58 +0000 |
commit | 62dde825d82273eb5b7ea5716237801dbdf2e211 (patch) | |
tree | 16c79f1fd3d1d327ed25305ebad1151d18dba033 | |
parent | b625a0e1bcb62ef6cd9187ce5d64729182548b39 (diff) | |
download | bcm5719-llvm-62dde825d82273eb5b7ea5716237801dbdf2e211.tar.gz bcm5719-llvm-62dde825d82273eb5b7ea5716237801dbdf2e211.zip |
[x86] make getOneTrueElt() a helper function ; NFC
As mentioned in http://reviews.llvm.org/D16828 , the related masked load transform
will need this logic, so I'm moving it out to make that patch smaller.
llvm-svn: 260240
-rw-r--r-- | llvm/lib/Target/X86/X86ISelLowering.cpp | 69 |
1 files changed, 34 insertions, 35 deletions
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 0ff6acb0d14..1b7a866b4d1 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -26724,6 +26724,40 @@ static SDValue PerformLOADCombine(SDNode *N, SelectionDAG &DAG, return SDValue(); } +/// If V is a build vector of boolean constants and exactly one of those +/// constants is true, return the operand index of that true element. +/// Otherwise, return -1. +static int getOneTrueElt(SDValue V) { + // This needs to be a build vector of booleans. + // TODO: Checking for the i1 type matches the IR definition for the mask, + // but the mask check could be loosened to i8 or other types. That might + // also require checking more than 'allOnesValue'; eg, the x86 HW + // instructions only require that the MSB is set for each mask element. + // The ISD::MSTORE comments/definition do not specify how the mask operand + // is formatted. + auto *BV = dyn_cast<BuildVectorSDNode>(V); + if (!BV || BV->getValueType(0).getVectorElementType() != MVT::i1) + return -1; + + int TrueIndex = -1; + unsigned NumElts = BV->getValueType(0).getVectorNumElements(); + for (unsigned i = 0; i < NumElts; ++i) { + const SDValue &Op = BV->getOperand(i); + if (Op.getOpcode() == ISD::UNDEF) + continue; + auto *ConstNode = dyn_cast<ConstantSDNode>(Op); + if (!ConstNode) + return -1; + if (ConstNode->getAPIntValue().isAllOnesValue()) { + // If we already found a one, this is too many. + if (TrueIndex >= 0) + return -1; + TrueIndex = i; + } + } + return TrueIndex; +}; + static SDValue PerformMLOADCombine(SDNode *N, SelectionDAG &DAG, TargetLowering::DAGCombinerInfo &DCI, const X86Subtarget &Subtarget) { @@ -26804,7 +26838,6 @@ static SDValue PerformMLOADCombine(SDNode *N, SelectionDAG &DAG, return DCI.CombineTo(N, NewVec, WideLd.getValue(1), true); } - /// If exactly one element of the mask is set for a non-truncating masked store, /// it is a vector extract and scalar store. /// Note: It is expected that the degenerate cases of an all-zeros or all-ones @@ -26815,40 +26848,6 @@ static SDValue reduceMaskedStoreToScalarStore(MaskedStoreSDNode *MS, // However, some target hooks may need to be added to know when the transform // is profitable. Endianness would also have to be considered. - // If V is a build vector of boolean constants and exactly one of those - // constants is true, return the operand index of that true element. - // Otherwise, return -1. - auto getOneTrueElt = [](SDValue V) { - // This needs to be a build vector of booleans. - // TODO: Checking for the i1 type matches the IR definition for the mask, - // but the mask check could be loosened to i8 or other types. That might - // also require checking more than 'allOnesValue'; eg, the x86 HW - // instructions only require that the MSB is set for each mask element. - // The ISD::MSTORE comments/definition do not specify how the mask operand - // is formatted. - auto *BV = dyn_cast<BuildVectorSDNode>(V); - if (!BV || BV->getValueType(0).getVectorElementType() != MVT::i1) - return -1; - - int TrueIndex = -1; - unsigned NumElts = BV->getValueType(0).getVectorNumElements(); - for (unsigned i = 0; i < NumElts; ++i) { - const SDValue &Op = BV->getOperand(i); - if (Op.getOpcode() == ISD::UNDEF) - continue; - auto *ConstNode = dyn_cast<ConstantSDNode>(Op); - if (!ConstNode) - return -1; - if (ConstNode->getAPIntValue().isAllOnesValue()) { - // If we already found a one, this is too many. - if (TrueIndex >= 0) - return -1; - TrueIndex = i; - } - } - return TrueIndex; - }; - int TrueMaskElt = getOneTrueElt(MS->getMask()); if (TrueMaskElt < 0) return SDValue(); |