[PATCH] D58626: [DAG] Fix constant store folding to handle non-byte sizes.
Nirav Dave via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 25 07:41:29 PST 2019
niravd created this revision.
niravd added reviewers: uabelho, courbet, rnk.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
Avoid crashes from zero-byte values due to sub-byte store sizes.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D58626
Files:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/X86/constant-combines.ll
Index: llvm/test/CodeGen/X86/constant-combines.ll
===================================================================
--- llvm/test/CodeGen/X86/constant-combines.ll
+++ llvm/test/CodeGen/X86/constant-combines.ll
@@ -38,3 +38,15 @@
store float %8, float* %0, align 4
ret void
}
+
+
+define void @bitstore_fold() {
+; CHECK-LABEL: bitstore_fold:
+; CHECK: # %bb.0: # %BB
+; CHECK-NEXT: movl $-2, 0
+; CHECK-NEXT: retq
+BB:
+ store i32 -1, i32* null
+ store i1 false, i1* null
+ ret void
+}
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -15427,13 +15427,13 @@
!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((STBitSize+7)/8, ChainBase, (ChainBitSize+7)/8, DAG)) {
CombineTo(ST1, ST1->getChain());
return SDValue();
}
@@ -15443,13 +15443,13 @@
// 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,
+ if (ChainBase.contains((ChainBitSize+7)/8, STBase, (STBitSize+7)/8, 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);
+ APInt InsertVal = C->getAPIntValue().zextOrTrunc(STBitSize);
// FIXME: Handle Big-endian mode.
if (!DAG.getDataLayout().isBigEndian()) {
Val.insertBits(InsertVal, Offset * 8);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58626.188177.patch
Type: text/x-patch
Size: 2660 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190225/cad4a23f/attachment-0001.bin>
More information about the llvm-commits
mailing list