From nobody Sun Jul 28 11:05:11 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 4WWzD7331Wz5RyjW; Sun, 28 Jul 2024 11:05:11 +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 4WWzD7223Vz4J5G; Sun, 28 Jul 2024 11:05:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722164711; 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=U1Vt7/aAN4VAmxNxJ8kLwOWa3mxfom4Tb6yu6x1oUd8=; b=d0V29bLoBkMy0WI1RTd1Vu89xmwc6Sr/IdDoOl1Ojnmrba9cqHa87FxVdoyemBWe5yBzpm /54gkKYlNHo11WfUAwH4B+mF99ruvQ3Tedb/IN1dkMXOygiiiXbkKhqF0V1X+UsOinRLkM dvrQU+/+KHMCYB6MZghaj0bpLwg9a6TNT1TI+mMzcl9CNj1BfLf3OingFmnW+hNdzO3lk1 lmTMiCUkLki/ZdNo4kZigggineEKRX6Oshn8StkzGYQM3BOZVUO6dLJI3Xux1UYsVtdqYY msCQdOmkrp6UmaW3bFOgJJYDbnWEves2JbV3tE21MuDvHNdNp8k0fjraKK9jcg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722164711; a=rsa-sha256; cv=none; b=bHTkBivjVBK+i8IYFnqr1fWYpvFPS0FNsSnnPoAZWOg/hK1UqbxiOngUIGvU8Rr4+vWLo5 oCyh6iXXbRw9BWtB64+20Gtr1UN/2wfq5i2mCsmIFq7dhNbO/nusKcMoZYvBghKRFsKeqo vN+JyAw3TxIuQgxRZRZUkQ+RAy7gKFJouFi4SQB4RDfMdrVJTDQC7XoZNdII2X+NFBYMAX sjVSERcxyZJatjqYN6evM5WjlVgSbU1aGhL9e7NcJSGgQ/yofGgd8ugWs7RLrYOR2HctuF TXNYMistf44lIwgUBszZih2T95mgeIzBU7eaBQxlJHQu4CV4mjX+rKUNa/QZlg== 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=1722164711; 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=U1Vt7/aAN4VAmxNxJ8kLwOWa3mxfom4Tb6yu6x1oUd8=; b=Xi5PAOC8accVrvPrIixvmfRs3YP9igMFeb/mCta3+RCdfgfyS28MhotAPKN2Nrv1YxeE2M v5oZCiCg52Czqg7W+w3LLPS4eLzmRv/O+Jdohay1r7NvO3D3o0kmHiZMW/e1MsZmr2b102 N9SOS/XK0Pt0+RSj7kM1VszglkNnYS4CPqMRXkSsby96piJTopXpyiJMmYqtWawnue3ny6 rypGqKHuQKu8D2aR1jJpmv5qzptRDgGqxq6oSIpN+pHzkXSIA3lf+cSNtza5ySs3WdzcZw ESD0gApnjDpddzL80MbswXIvKrWSKgXTTX+GXsFztyitxLZTKCdbYLDgK+Jc9Q== 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 4WWzD71P8qzp5N; Sun, 28 Jul 2024 11:05:11 +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 46SB5BbA002275; Sun, 28 Jul 2024 11:05:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46SB5Bro002272; Sun, 28 Jul 2024 11:05:11 GMT (envelope-from git) Date: Sun, 28 Jul 2024 11:05:11 GMT Message-Id: <202407281105.46SB5Bro002272@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: c7e5a0d42f20 - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: c7e5a0d42f20e9a81b96fc89b3b9883cf4be9839 Auto-Submitted: auto-generated The branch stable/13 has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=c7e5a0d42f20e9a81b96fc89b3b9883cf4be9839 commit c7e5a0d42f20e9a81b96fc89b3b9883cf4be9839 Author: Dimitry Andric AuthorDate: 2024-07-25 11:13:45 +0000 Commit: Dimitry Andric CommitDate: 2024-07-28 11:04:26 +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