From: Simon Pilgrim Date: Fri, 23 Jun 2023 15:22:01 +0000 (+0100) Subject: [DAG] mergeTruncStores - early out if we collect more than the maximum number of... X-Git-Tag: upstream/17.0.6~4073 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1f006f5fb63df4facb2c45511090b3fdd3e07de5;p=platform%2Fupstream%2Fllvm.git [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 #63306 --- diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 77b05a3..ab36d22 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -8679,9 +8679,12 @@ SDValue DAGCombiner::mergeTruncStores(StoreSDNode *N) { !N->isSimple() || N->isIndexed()) return SDValue(); - // Collect all of the stores in the chain. + // Collect all of the stores in the chain, upto the maximum store width (i64). SDValue Chain = N->getChain(); SmallVector Stores = {N}; + unsigned NarrowNumBits = MemVT.getScalarSizeInBits(); + unsigned MaxWideNumBits = 64; + unsigned MaxStores = MaxWideNumBits / NarrowNumBits; while (auto *Store = dyn_cast(Chain)) { // All stores must be the same size to ensure that we are writing all of the // bytes in the wide value. @@ -8695,6 +8698,8 @@ SDValue DAGCombiner::mergeTruncStores(StoreSDNode *N) { return SDValue(); Stores.push_back(Store); Chain = Store->getChain(); + if (MaxStores < Stores.size()) + return SDValue(); } // There is no reason to continue if we do not have at least a pair of stores. if (Stores.size() < 2) @@ -8703,7 +8708,6 @@ SDValue DAGCombiner::mergeTruncStores(StoreSDNode *N) { // Handle simple types only. LLVMContext &Context = *DAG.getContext(); unsigned NumStores = Stores.size(); - unsigned NarrowNumBits = N->getMemoryVT().getScalarSizeInBits(); unsigned WideNumBits = NumStores * NarrowNumBits; EVT WideVT = EVT::getIntegerVT(Context, WideNumBits); if (WideVT != MVT::i16 && WideVT != MVT::i32 && WideVT != MVT::i64)