From nobody Thu Jul 25 18:03:13 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 4WVJdt0mFSz5R0YT; Thu, 25 Jul 2024 18:03:14 +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 4WVJdt0BTLz52qY; Thu, 25 Jul 2024 18:03:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1721930594; 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=Innm4UVYFJ5ZHJ/w8Zv8Zb3p3DtIiMdwFUFyW6wjjkQ=; b=LvpluAylfi3HKFqmZZvUma3oicXzu911bCzrDvneUyp1xOxu7lgqXfqa5paJRHBdPaqkxP F8sWn07pYlZVxYk8jQzJptX5lXBh84AWPh8eqtcLtM7PqRof2vmRhOdZjEKFHM4MbMcQMT 6+Ul/IWn1y8920J3nr6gNClqEpZheqGMKbDgvy3wnYFDSsWF+lwaF1DfGNK7KUfz1l17n/ Uh4J/mJBVT8gmwSne6Vco2xnnGorMaxTNnA9qHHIBluF+9X1UIusReD4BM+s0KGd8j6kQ0 p4TDF4I3AacgnMtKoIcKxwURe9mgmCCeX0rC7LtWQMrBruIZHWH+akTPz9XfMQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1721930594; a=rsa-sha256; cv=none; b=KvP7l+LsTlSFNfjj2jB4OEJ05+B93ow7/X8HsiQXzwYdPmCuSXGWF2agdsmLIMp7wRYpEC BQ9msDUyjUhUHhMJJZ7L2YQx1CCXQLqinf3MuJynnor6M+V95Z6WrNuzWsyCpehEJNgDfk IkzdhaRroB10BimTaB0iNXky4qqCwX49jFcq56DlM7NnZKNTlXC6aMMwE0oTxHt0lNxWtf szgFNYSZPiBwM8s9XTBzODpGQQOqpeR6/G9Jw30V7eS6+2UKLqsBN9rO49tQTugCWhYX+i FN1HKYtkopiafnaB3et6i8y5X7I8IjczfUD2QawtSs4SrtuV99aSOcWuh/H4WA== 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=1721930594; 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=Innm4UVYFJ5ZHJ/w8Zv8Zb3p3DtIiMdwFUFyW6wjjkQ=; b=Q5poBhtzR1Z9XE0WAx1Br9BinD/k+pntkvQZSrXFzsdLQOyLPyUBzHXZNdYkDA1kN8oFOC OAhVKbyS7zAfloidihiQ8pAgui+rw0UiYeN2atH7PGrtSXsxZaxBuKZUyGIZiMu4crUT5C OAaf/hbbgvJ6Uo4KHlOUmIjINStEHqrk68RooWxpjNFfOPydgWs4Q2/sf6PgV2s8jeXmBm P4FT8qBBUV/qxDgJO+HrMvxwGKfQemvlH86NoZ6FPExzSLbtkgdEDElGxYFLmNj/QItg/m FFc731Xg7sTFeLblx/3/RZwr0oTleiEEGVGsteWuVKrbizrtn4WGn7epWA4NlQ== 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 4WVJds6vpvz14ph; Thu, 25 Jul 2024 18:03:13 +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 46PI3DjS090082; Thu, 25 Jul 2024 18:03:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46PI3D4d090079; Thu, 25 Jul 2024 18:03:13 GMT (envelope-from git) Date: Thu, 25 Jul 2024 18:03:13 GMT Message-Id: <202407251803.46PI3D4d090079@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dimitry Andric Subject: git: 55a2a91c5e1b - main - 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/main X-Git-Reftype: branch X-Git-Commit: 55a2a91c5e1bb39dd625ba56597608883fbcb318 Auto-Submitted: auto-generated The branch main has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=55a2a91c5e1bb39dd625ba56597608883fbcb318 commit 55a2a91c5e1bb39dd625ba56597608883fbcb318 Author: Dimitry Andric AuthorDate: 2024-07-25 11:13:45 +0000 Commit: Dimitry Andric CommitDate: 2024-07-25 18:03:01 +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 --- .../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