Skip to content

Commit 1f006f5

Browse files
committed
[DAG] mergeTruncStores - early out if we collect more than the maximum number of stores
If we have an excessive number of stores in a single chain then the candidate WideVT may exceed the maximum width of an EVT integer type (and will assert) - but since mergeTruncStores doesn't support anything wider than a i64 store we should just early-out if we've collected more than stores than that. Fixes llvm#63306
1 parent b511537 commit 1f006f5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8679,9 +8679,12 @@ SDValue DAGCombiner::mergeTruncStores(StoreSDNode *N) {
86798679
!N->isSimple() || N->isIndexed())
86808680
return SDValue();
86818681

8682-
// Collect all of the stores in the chain.
8682+
// Collect all of the stores in the chain, upto the maximum store width (i64).
86838683
SDValue Chain = N->getChain();
86848684
SmallVector<StoreSDNode *, 8> Stores = {N};
8685+
unsigned NarrowNumBits = MemVT.getScalarSizeInBits();
8686+
unsigned MaxWideNumBits = 64;
8687+
unsigned MaxStores = MaxWideNumBits / NarrowNumBits;
86858688
while (auto *Store = dyn_cast<StoreSDNode>(Chain)) {
86868689
// All stores must be the same size to ensure that we are writing all of the
86878690
// bytes in the wide value.
@@ -8695,6 +8698,8 @@ SDValue DAGCombiner::mergeTruncStores(StoreSDNode *N) {
86958698
return SDValue();
86968699
Stores.push_back(Store);
86978700
Chain = Store->getChain();
8701+
if (MaxStores < Stores.size())
8702+
return SDValue();
86988703
}
86998704
// There is no reason to continue if we do not have at least a pair of stores.
87008705
if (Stores.size() < 2)
@@ -8703,7 +8708,6 @@ SDValue DAGCombiner::mergeTruncStores(StoreSDNode *N) {
87038708
// Handle simple types only.
87048709
LLVMContext &Context = *DAG.getContext();
87058710
unsigned NumStores = Stores.size();
8706-
unsigned NarrowNumBits = N->getMemoryVT().getScalarSizeInBits();
87078711
unsigned WideNumBits = NumStores * NarrowNumBits;
87088712
EVT WideVT = EVT::getIntegerVT(Context, WideNumBits);
87098713
if (WideVT != MVT::i16 && WideVT != MVT::i32 && WideVT != MVT::i64)

0 commit comments

Comments
 (0)