diff options
| author | Chandler Carruth <chandlerc@gmail.com> | 2014-07-07 19:03:32 +0000 |
|---|---|---|
| committer | Chandler Carruth <chandlerc@gmail.com> | 2014-07-07 19:03:32 +0000 |
| commit | beeacac0b32a94abd813148ff142152f74d0f78a (patch) | |
| tree | 57b7cca702e05aa63c01fd301a14ce82cb39edc1 /llvm/lib/CodeGen | |
| parent | c1856835d13e938c838bc66851db0351a6db4b66 (diff) | |
| download | bcm5719-llvm-beeacac0b32a94abd813148ff142152f74d0f78a.tar.gz bcm5719-llvm-beeacac0b32a94abd813148ff142152f74d0f78a.zip | |
[x86] Revert r212324 which was too aggressive w.r.t. allowing undef
lanes in vector splats.
The core problem here is that undef lanes can't *unilaterally* be
considered to contribute to splats. Their handling needs to be more
cautious. There is also a reported failure of the nightly testers
(thanks Tobias!) that may well stem from the same core issue. I'm going
to fix this theoretical issue, factor the APIs a bit better, and then
verify that I don't see anything bad with Tobias's reduction from the
test suite before recommitting.
Original commit message for r212324:
[x86] Generalize BuildVectorSDNode::getConstantSplatValue to work for
any constant, constant FP, or undef splat and to tolerate any undef
lanes in a splat, then replace all uses of isSplatVector in X86's
lowering with it.
This fixes issues where undef lanes in an otherwise splat vector would
prevent the splat logic from firing. It is a touch more awkward to use
this interface, but it is much more accurate. Suggestions for better
interface structuring welcome.
With this fix, the code generated with the widening legalization
strategy for widen_cast-4.ll is *dramatically* improved as the special
lowering strategies for a v16i8 SRA kick in even though the high lanes
are undef.
We also get a slightly different choice for broadcasting an aligned
memory location, and use vpshufd instead of vbroadcastss. This looks
like a minor win for pipelining and domain crossing, but a minor loss
for the number of micro-ops. I suspect its a wash, but folks can
easily tweak the lowering if they want.
llvm-svn: 212475
Diffstat (limited to 'llvm/lib/CodeGen')
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 13 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 28 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | 34 |
3 files changed, 31 insertions, 44 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 9a91dcc341b..7198203036b 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -654,12 +654,13 @@ static ConstantSDNode *isConstOrConstSplat(SDValue N) { if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N)) return CN; - if (BuildVectorSDNode *BV = dyn_cast<BuildVectorSDNode>(N)) - if (SDValue Splat = BV->getConstantSplatValue()) - if (auto *CN = dyn_cast<ConstantSDNode>(Splat)) - // BuildVectors can truncate their operands. Ignore that case here. - if (CN->getValueType(0) == N.getValueType().getScalarType()) - return CN; + if (BuildVectorSDNode *BV = dyn_cast<BuildVectorSDNode>(N)) { + ConstantSDNode *CN = BV->getConstantSplatValue(); + + // BuildVectors can truncate their operands. Ignore that case here. + if (CN && CN->getValueType(0) == N.getValueType().getScalarType()) + return CN; + } return nullptr; } diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index fb7d1b18d8b..3a8a5f9601f 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -6603,28 +6603,16 @@ bool BuildVectorSDNode::isConstantSplat(APInt &SplatValue, return true; } -SDValue BuildVectorSDNode::getConstantSplatValue() const { - SDValue Splatted; - for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { - SDValue Op = getOperand(i); - if (Op.getOpcode() == ISD::UNDEF) - continue; - if (Op.getOpcode() != ISD::Constant && Op.getOpcode() != ISD::ConstantFP) - return SDValue(); - - if (!Splatted) - Splatted = Op; - else if (Splatted != Op) - return SDValue(); - } +ConstantSDNode *BuildVectorSDNode::getConstantSplatValue() const { + SDValue Op0 = getOperand(0); + if (Op0.getOpcode() != ISD::Constant) + return nullptr; - if (!Splatted) { - assert(getOperand(0).getOpcode() == ISD::UNDEF && - "Can only have a splat without a constant for all undefs."); - return getOperand(0); - } + for (unsigned i = 1, e = getNumOperands(); i != e; ++i) + if (getOperand(i) != Op0) + return nullptr; - return Splatted; + return cast<ConstantSDNode>(Op0); } bool BuildVectorSDNode::isConstant() const { diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp index 1b3e42848bf..ad91d4a87c1 100644 --- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -1152,15 +1152,14 @@ bool TargetLowering::isConstTrueVal(const SDNode *N) const { bool IsVec = false; const ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N); - if (!CN) - if (auto *BV = dyn_cast<BuildVectorSDNode>(N)) - if (SDValue Splat = BV->getConstantSplatValue()) - if (auto *SplatCN = dyn_cast<ConstantSDNode>(Splat)) { - IsVec = true; - CN = SplatCN; - } - if (!CN) - return false; + if (!CN) { + const BuildVectorSDNode *BV = dyn_cast<BuildVectorSDNode>(N); + if (!BV) + return false; + + IsVec = true; + CN = BV->getConstantSplatValue(); + } switch (getBooleanContents(IsVec)) { case UndefinedBooleanContent: @@ -1180,15 +1179,14 @@ bool TargetLowering::isConstFalseVal(const SDNode *N) const { bool IsVec = false; const ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N); - if (!CN) - if (auto *BV = dyn_cast<BuildVectorSDNode>(N)) - if (SDValue Splat = BV->getConstantSplatValue()) - if (auto *SplatCN = dyn_cast<ConstantSDNode>(Splat)) { - IsVec = true; - CN = SplatCN; - } - if (!CN) - return false; + if (!CN) { + const BuildVectorSDNode *BV = dyn_cast<BuildVectorSDNode>(N); + if (!BV) + return false; + + IsVec = true; + CN = BV->getConstantSplatValue(); + } if (getBooleanContents(IsVec) == UndefinedBooleanContent) return !CN->getAPIntValue()[0]; |

