diff options
author | Nirav Dave <niravd@google.com> | 2019-02-22 16:00:19 +0000 |
---|---|---|
committer | Nirav Dave <niravd@google.com> | 2019-02-22 16:00:19 +0000 |
commit | 44037d7a6377ec8e5542cced73583283334b516b (patch) | |
tree | 93af796311371909f55eea0320a2569d851b3b8a /llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | |
parent | a9e289174a1c21698ea0c1f1a43f1f504e5e75ef (diff) | |
download | bcm5719-llvm-44037d7a6377ec8e5542cced73583283334b516b.tar.gz bcm5719-llvm-44037d7a6377ec8e5542cced73583283334b516b.zip |
[DAGCombine] Fold overlapping constant stores
Fold a smaller constant store into larger constant stores immediately
preceeding it.
Reviewers: rnk, courbet
Subscribers: javed.absar, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D58468
llvm-svn: 354676
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index dc208e10a28..cbaa13c55f5 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -15437,6 +15437,32 @@ SDValue DAGCombiner::visitSTORE(SDNode *N) { CombineTo(ST1, ST1->getChain()); return SDValue(); } + + // If ST stores to a subset of preceeding store's write set, we may be + // able to fold ST's value into the preceeding stored value. As we know + // the other uses of ST1's chain are unconcerned with ST, this folding + // will not affect those nodes. + int64_t Offset; + if (ChainBase.contains(ChainByteSize, STBase, STByteSize, DAG, + Offset)) { + SDValue ChainValue = ST1->getValue(); + if (auto *C1 = dyn_cast<ConstantSDNode>(ChainValue)) { + if (auto *C = dyn_cast<ConstantSDNode>(Value)) { + APInt Val = C1->getAPIntValue(); + APInt InsertVal = C->getAPIntValue().zextOrTrunc(STByteSize * 8); + if (DAG.getDataLayout().isBigEndian()) + Offset = ChainByteSize - 1 - Offset; + Val.insertBits(InsertVal, Offset * 8); + SDValue NewSDVal = + DAG.getConstant(Val, SDLoc(C), ChainValue.getValueType(), + C1->isTargetOpcode(), C1->isOpaque()); + SDNode *NewST1 = DAG.UpdateNodeOperands( + ST1, ST1->getChain(), NewSDVal, ST1->getOperand(2), + ST1->getOperand(3)); + return CombineTo(ST, SDValue(NewST1, 0)); + } + } + } // End ST subset of ST1 case. } } } |