From nobody Sun Jul 28 11:04:42 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WWzCZ5SsNz5RyJM; Sun, 28 Jul 2024 11:04:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WWzCZ4rQrz4Hj2; Sun, 28 Jul 2024 11:04:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722164682; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ptcWjfVFtM5G7dIgZUQvrTS1I7kcwYonvl0YKMf/5eA=; b=h89SS9JbFUbmfI6z+pqfg8T7nI8cqAFUw4l8xSvnIOlYNrN/reb1owxe1y6tt9VUXKlMFy LIptsEEQcWEm3BEmNYJrfnB6bh18VWTWqnhU/2o7Osi+OBfloVBaOQ5V0vpKDkMSviZbGb 6sD/ZPslO08IspzvZuLfgTw9UMIwAzM75gH9Cp032LipzrHPpfMKMKHiLETVW4nc/2qxu4 WWc2oIi03LaUtexZLL3Yx+zfXbX6jTM17ne/nXVtU2VPVRXTCHlRzORDLWPSz62RB8DpBd 0mmTkur3kZIKasM8BYrlNq/DyngUbLNTkjIkRmLfz40R8p2xHzqmXMsat8viPQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722164682; a=rsa-sha256; cv=none; b=NJI1Sza+jlcCgvKWK6QGPlAQ+Lk92Z6cPzgt/qCTh5zhku1KMfCnmi9Xyfk14u5wXHVypl FI0gZ+ke/ZohgyfwEuK1yxhttacXrJRrxsQWNPdAb39VxCnRC3CRsm7YKdnK2Uspn7lagA d3kNGKvUR9CMthtV30uyUdz7iqBZmTTgzIo2If/3t/0oLh+hTa7g2+aO9GYB+iCbrX3eNZ In7HhW13E6bM2jCJtiJtCKR4VTBlSZ04Ta1M6R7AV3leRQ+C0AgUpvr+Icho04lmZxItsL bOSF/cXH40DvOK0Pjg+/B2sTwAmk/U+xSej7u53rtuJyrGspK79kmh7kTbdNbQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722164682; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ptcWjfVFtM5G7dIgZUQvrTS1I7kcwYonvl0YKMf/5eA=; b=BhpRNv3cAZ4X7Ww+tLhhcE/MYQUFmOP8s/JP8HK4Vh85YRGKoFbmiQKqlUdT61oy26yzc2 SJohVMtIRka6T/+qqOoj67AmFGo5lg5Is+lfR3EsJYTTRTM+LZccZqJG8to9MSGzfcxdZf 7ejQ5S5A3+Yx0AQDPqBDMbEdMkC+c0xloU1/PhkIXwumR3UuwryjJTmovLNwl1zqIvtjUX mx8mu7+asVkyS2gIFArYDTsF5BR8Ya4nCoE130EgFaZFz4ojULAC4fgABmgT1kTR/Y8af4 SyqC71RHz99n2HV2G5OPUFDfqHSgjvDDof5P0P4qZXlivDuBI76jqirL/rf66A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4WWzCZ4LSTzpDp; Sun, 28 Jul 2024 11:04:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 46SB4gDJ002043; Sun, 28 Jul 2024 11:04:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46SB4gBd002040; Sun, 28 Jul 2024 11:04:42 GMT (envelope-from git) Date: Sun, 28 Jul 2024 11:04:42 GMT Message-Id: <202407281104.46SB4gBd002040@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dimitry Andric Subject: git: 806fbbbbe5d2 - stable/14 - Merge commit 28a2b85602a5 from llvm-project (by Kazu Hirata): List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dim X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 806fbbbbe5d2eb5decfaafba6deb94534655cc8e Auto-Submitted: auto-generated The branch stable/14 has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=806fbbbbe5d2eb5decfaafba6deb94534655cc8e commit 806fbbbbe5d2eb5decfaafba6deb94534655cc8e Author: Dimitry Andric AuthorDate: 2024-07-25 11:13:45 +0000 Commit: Dimitry Andric CommitDate: 2024-07-28 11:04:21 +0000 Merge commit 28a2b85602a5 from llvm-project (by Kazu Hirata): [DeadStoreElimination] Use SmallSetVector (NFC) (#79410) The use of SmallSetVector saves 0.58% of heap allocations during the compilation of a large preprocessed file, namely X86ISelLowering.cpp, for the X86 target. During the experiment, the final size of ToCheck was 8 or less 88% of the time. Merge commit 9e95c4947d31 from llvm-project (by Nikita Popov): [DSE] Fix non-determinism due to address reuse (#84943) The malloc->calloc fold creates a new MemoryAccess, which may end of at the same address as a previously deleted access inside SkipStores. To the most part, this is not a problem, because SkipStores is normally only used together with MemDefs. Neither the old malloc access nor the new calloc access will be part of MemDefs, so there is no problem here. However, SkipStores is also used in one more place: In the main DSE loop, ToCheck entries are checked against it. Fix this by not using SkipStores here, and instead using a separate set to track deletions inside this loop. This way it is not affected by the calloc optimization that happens outside it. This is all pretty ugly, but I haven't found another good way to fix it. Suggestions welcome. No test case as I don't have a reliable DSE-only test-case for this. Fixes https://github.com/llvm/llvm-project/issues/84458. This fixes another possible difference in output when building i386 object files with a native or cross build of clang. (Specifically, the file sbin/ipf/ipmon/ipmon.o.) PR: 276961 Reported by: cperciva MFC after: 3 days (cherry picked from commit 55a2a91c5e1bb39dd625ba56597608883fbcb318) --- .../lib/Transforms/Scalar/DeadStoreElimination.cpp | 24 ++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/contrib/llvm-project/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/contrib/llvm-project/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp index 380d65836553..f0f0f5f28025 100644 --- a/contrib/llvm-project/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/contrib/llvm-project/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -1697,7 +1697,9 @@ struct DSEState { /// Delete dead memory defs and recursively add their operands to ToRemove if /// they became dead. - void deleteDeadInstruction(Instruction *SI) { + void + deleteDeadInstruction(Instruction *SI, + SmallPtrSetImpl *Deleted = nullptr) { MemorySSAUpdater Updater(&MSSA); SmallVector NowDeadInsts; NowDeadInsts.push_back(SI); @@ -1718,6 +1720,8 @@ struct DSEState { if (IsMemDef) { auto *MD = cast(MA); SkipStores.insert(MD); + if (Deleted) + Deleted->insert(MD); if (auto *SI = dyn_cast(MD->getMemoryInst())) { if (SI->getValueOperand()->getType()->isPointerTy()) { const Value *UO = getUnderlyingObject(SI->getValueOperand()); @@ -2111,7 +2115,12 @@ static bool eliminateDeadStores(Function &F, AliasAnalysis &AA, MemorySSA &MSSA, unsigned WalkerStepLimit = MemorySSAUpwardsStepLimit; unsigned PartialLimit = MemorySSAPartialStoreLimit; // Worklist of MemoryAccesses that may be killed by KillingDef. - SetVector ToCheck; + SmallSetVector ToCheck; + // Track MemoryAccesses that have been deleted in the loop below, so we can + // skip them. Don't use SkipStores for this, which may contain reused + // MemoryAccess addresses. + SmallPtrSet Deleted; + [[maybe_unused]] unsigned OrigNumSkipStores = State.SkipStores.size(); ToCheck.insert(KillingDef->getDefiningAccess()); bool Shortend = false; @@ -2119,7 +2128,7 @@ static bool eliminateDeadStores(Function &F, AliasAnalysis &AA, MemorySSA &MSSA, // Check if MemoryAccesses in the worklist are killed by KillingDef. for (unsigned I = 0; I < ToCheck.size(); I++) { MemoryAccess *Current = ToCheck[I]; - if (State.SkipStores.count(Current)) + if (Deleted.contains(Current)) continue; std::optional MaybeDeadAccess = State.getDomMemoryDef( @@ -2166,7 +2175,7 @@ static bool eliminateDeadStores(Function &F, AliasAnalysis &AA, MemorySSA &MSSA, continue; LLVM_DEBUG(dbgs() << "DSE: Remove Dead Store:\n DEAD: " << *DeadI << "\n KILLER: " << *KillingI << '\n'); - State.deleteDeadInstruction(DeadI); + State.deleteDeadInstruction(DeadI, &Deleted); ++NumFastStores; MadeChange = true; } else { @@ -2203,7 +2212,7 @@ static bool eliminateDeadStores(Function &F, AliasAnalysis &AA, MemorySSA &MSSA, Shortend = true; // Remove killing store and remove any outstanding overlap // intervals for the updated store. - State.deleteDeadInstruction(KillingSI); + State.deleteDeadInstruction(KillingSI, &Deleted); auto I = State.IOLs.find(DeadSI->getParent()); if (I != State.IOLs.end()) I->second.erase(DeadSI); @@ -2215,13 +2224,16 @@ static bool eliminateDeadStores(Function &F, AliasAnalysis &AA, MemorySSA &MSSA, if (OR == OW_Complete) { LLVM_DEBUG(dbgs() << "DSE: Remove Dead Store:\n DEAD: " << *DeadI << "\n KILLER: " << *KillingI << '\n'); - State.deleteDeadInstruction(DeadI); + State.deleteDeadInstruction(DeadI, &Deleted); ++NumFastStores; MadeChange = true; } } } + assert(State.SkipStores.size() - OrigNumSkipStores == Deleted.size() && + "SkipStores and Deleted out of sync?"); + // Check if the store is a no-op. if (!Shortend && State.storeIsNoop(KillingDef, KillingUndObj)) { LLVM_DEBUG(dbgs() << "DSE: Remove No-Op Store:\n DEAD: " << *KillingI