diff options
author | Nirav Dave <niravd@google.com> | 2019-02-26 15:02:32 +0000 |
---|---|---|
committer | Nirav Dave <niravd@google.com> | 2019-02-26 15:02:32 +0000 |
commit | 582d46328ce644d791f4dce31b005fc260d33611 (patch) | |
tree | 4c483fe2a5cdb8731a0234e1b78b20a296d72988 /llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | |
parent | f388d17d7cad33afee059b0fe8d6c7b2b3e6899e (diff) | |
download | bcm5719-llvm-582d46328ce644d791f4dce31b005fc260d33611.tar.gz bcm5719-llvm-582d46328ce644d791f4dce31b005fc260d33611.zip |
[DAG] Fix constant store folding to handle non-byte sizes.
Avoid crashes from zero-byte values due to sub-byte store sizes.
Reviewers: uabelho, courbet, rnk
Reviewed By: courbet
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D58626
llvm-svn: 354884
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 183a1f56888..18fe03fa468 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -15427,13 +15427,13 @@ SDValue DAGCombiner::visitSTORE(SDNode *N) { !ST1->getBasePtr().isUndef()) { const BaseIndexOffset STBase = BaseIndexOffset::match(ST, DAG); const BaseIndexOffset ChainBase = BaseIndexOffset::match(ST1, DAG); - unsigned STByteSize = ST->getMemoryVT().getSizeInBits() / 8; - unsigned ChainByteSize = ST1->getMemoryVT().getSizeInBits() / 8; + unsigned STBitSize = ST->getMemoryVT().getSizeInBits(); + unsigned ChainBitSize = ST1->getMemoryVT().getSizeInBits(); // If this is a store who's preceding store to a subset of the current // location and no one other node is chained to that store we can // effectively drop the store. Do not remove stores to undef as they may // be used as data sinks. - if (STBase.contains(STByteSize, ChainBase, ChainByteSize, DAG)) { + if (STBase.contains(DAG, STBitSize, ChainBase, ChainBitSize)) { CombineTo(ST1, ST1->getChain()); return SDValue(); } @@ -15442,17 +15442,17 @@ SDValue DAGCombiner::visitSTORE(SDNode *N) { // able to fold ST's value into the preceding 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)) { + int64_t BitOffset; + if (ChainBase.contains(DAG, ChainBitSize, STBase, STBitSize, + BitOffset)) { 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); + APInt InsertVal = C->getAPIntValue().zextOrTrunc(STBitSize); // FIXME: Handle Big-endian mode. if (!DAG.getDataLayout().isBigEndian()) { - Val.insertBits(InsertVal, Offset * 8); + Val.insertBits(InsertVal, BitOffset); SDValue NewSDVal = DAG.getConstant(Val, SDLoc(C), ChainValue.getValueType(), C1->isTargetOpcode(), C1->isOpaque()); |