diff options
author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2016-10-13 12:05:20 +0000 |
---|---|---|
committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2016-10-13 12:05:20 +0000 |
commit | 833b8a2071643d0f26876b7956af3678411458e6 (patch) | |
tree | 2f2b662dd478e51ed2d06b7ad00c216bcd0453c1 /llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | |
parent | bb51662d8d6743956f0cf24b23c4082801307f84 (diff) | |
download | bcm5719-llvm-833b8a2071643d0f26876b7956af3678411458e6.tar.gz bcm5719-llvm-833b8a2071643d0f26876b7956af3678411458e6.zip |
[DAGCombiner] Add vector support to (sub -1, x) -> (xor x, -1) canonicalization
Improves commutation potential
llvm-svn: 284113
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index fab67e779aa..d01606e07e8 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -863,6 +863,17 @@ static bool isOneConstantOrOneSplatConstant(SDValue N) { return false; } +// Determines if it is a constant integer of all ones or a splatted vector of a +// constant integer of all ones (with no undefs). +// Do not permit build vector implicit truncation. +static bool isAllOnesConstantOrAllOnesSplatConstant(SDValue N) { + unsigned BitWidth = N.getScalarValueSizeInBits(); + if (ConstantSDNode *Splat = isConstOrConstSplat(N)) + return Splat->isAllOnesValue() && + Splat->getAPIntValue().getBitWidth() == BitWidth; + return false; +} + SDValue DAGCombiner::ReassociateOps(unsigned Opc, const SDLoc &DL, SDValue N0, SDValue N1) { EVT VT = N0.getValueType(); @@ -1938,7 +1949,7 @@ SDValue DAGCombiner::visitSUB(SDNode *N) { } // Canonicalize (sub -1, x) -> ~x, i.e. (xor x, -1) - if (isAllOnesConstant(N0)) + if (isAllOnesConstantOrAllOnesSplatConstant(N0)) return DAG.getNode(ISD::XOR, DL, VT, N1, N0); // fold A-(A-B) -> B |