From nobody Sun Jul 28 11:14:06 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 4WWzQQ31wCz5S0Qw; Sun, 28 Jul 2024 11:14:06 +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 4WWzQQ2T8lz4K4R; Sun, 28 Jul 2024 11:14:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722165246; 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=FPN5IytdWA6qsOsGaQVTBlL+yRh0ktvx0wVXnzJ6Z5Y=; b=iHdH4672ItebnI1yZyWn/WNz3Xrq3EDtcH7Zynn7glVImQF+sw0NlI9R7rRRgrNlwHBZ0T zWQGUl94XUE+HcaXZORaaTgDEFY8ukyadoUFm7stY6/b85VpOXNL2jhtPg6OC0X0ppHtN1 1YqKTWqhjPl0RvHUz9UgrfbvLrIAjBWP5JmR5YcBFIxAt1B+bxuz3xgN5Rhku17U6sn6As Fmw12OD0+QZNw74qQaqSLZzpf3gtwgQVZoOiI4ZlVFRO3VxMzp46sAC7890z5sUXjZLcgb 3e4IZ9qvq48N8h71JnXDsSLfnqkHLb/G+Kj0x/cI/CRbeOU2WAspPpmVMfmQWQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722165246; a=rsa-sha256; cv=none; b=Uqs89mnL8HC0ND2hW5jB2hll8zxIlv8QE1UxgXrB6IJ/rPnt4cPKGHF5vCnn0bVs9l+R++ JYIspE2yANrxlIB3j9aZdSXzDRe9uE9SIjR2OeKwYsdKsdnz4DWJVsnP2tGwIW1KJEN2et hBfK7G9Ysd1JX+9sjoKFHZ3rfImlne03PUbRp6YwjPF8UvrFXZ/bhHwkxI7P+CUUHvyFWE S3miUpWVi5xSejmNXl96c7CjunrBTEZHumNCixgzAEHz/1mylgVL6tKOUZhql9UgpJyUB8 dt3e9x4SCpLo2UrjJUvyP0vKtZbw+Y8UySjD9d2Q8ll4wIGCoYgOLeGC0bmB8g== 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=1722165246; 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=FPN5IytdWA6qsOsGaQVTBlL+yRh0ktvx0wVXnzJ6Z5Y=; b=to2XbNESiDN8BzHCDU3rbXKFuGrLHwQPuQQYWO1usiVY9K17y8wo8Pnc9GlZFLOTMSUlr9 KnG9A6ylDz2KOYID70+NVoLUEnP0RvI2aPXlPB746QTbW1X3Znpx8MgYB9JsKBE4UWHjix lRnFhlXLvbiarYYQV7UR0gF8LjLIShXcvf4iY/zUlgaoTeHW7MkWes29WlrjyK1L1Q6/Gn FtUnNTF7TkxyLwddyC5GI+qWjIzpypfkl9Viw4/U1WE/XwSTA9TO4XBPT7d/Nq4/ELONGm KgwMH+FnfOP47qCodwhIKkjwqwBi7tj9X1+MAPmcGFDVmNXkpKaAXi8GxIo8dQ== 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 4WWzQQ24NjzpS0; Sun, 28 Jul 2024 11:14:06 +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 46SBE61C018720; Sun, 28 Jul 2024 11:14:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46SBE6DZ018717; Sun, 28 Jul 2024 11:14:06 GMT (envelope-from git) Date: Sun, 28 Jul 2024 11:14:06 GMT Message-Id: <202407281114.46SBE6DZ018717@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: 1a4b8325f6e3 - main - Merge commit c80c09f3e380 from llvm-project (by Dimitry Andric): 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: 1a4b8325f6e3a45c77188343da504fe04495cc46 Auto-Submitted: auto-generated The branch main has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=1a4b8325f6e3a45c77188343da504fe04495cc46 commit 1a4b8325f6e3a45c77188343da504fe04495cc46 Author: Dimitry Andric AuthorDate: 2024-07-28 11:13:37 +0000 Commit: Dimitry Andric CommitDate: 2024-07-28 11:13:37 +0000 Merge commit c80c09f3e380 from llvm-project (by Dimitry Andric): [CalcSpillWeights] Avoid x87 excess precision influencing weight result Fixes #99396 The result of `VirtRegAuxInfo::weightCalcHelper` can be influenced by x87 excess precision, which can result in slightly different register choices when the compiler is hosted on x86_64 or i386. This leads to different object file output when cross-compiling to i386, or native. Similar to 7af3432e22b0, we need to add a `volatile` qualifier to the local `Weight` variable to force it onto the stack, and avoid the excess precision. Define `stack_float_t` in `MathExtras.h` for this purpose, and use it. This is the version of the fix for PR276961 that landed upstream. PR: 276961 Reported by: cperciva MFC after: 3 days --- contrib/llvm-project/llvm/include/llvm/Support/MathExtras.h | 8 ++++++++ contrib/llvm-project/llvm/lib/CodeGen/CalcSpillWeights.cpp | 11 ++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/contrib/llvm-project/llvm/include/llvm/Support/MathExtras.h b/contrib/llvm-project/llvm/include/llvm/Support/MathExtras.h index aa4f4d2ed42e..afb4fa262152 100644 --- a/contrib/llvm-project/llvm/include/llvm/Support/MathExtras.h +++ b/contrib/llvm-project/llvm/include/llvm/Support/MathExtras.h @@ -644,6 +644,14 @@ std::enable_if_t, T> MulOverflow(T X, T Y, T &Result) { return UX > (static_cast(std::numeric_limits::max())) / UY; } +/// Type to force float point values onto the stack, so that x86 doesn't add +/// hidden precision, avoiding rounding differences on various platforms. +#if defined(__i386__) || defined(_M_IX86) +using stack_float_t = volatile float; +#else +using stack_float_t = float; +#endif + } // End llvm namespace #endif diff --git a/contrib/llvm-project/llvm/lib/CodeGen/CalcSpillWeights.cpp b/contrib/llvm-project/llvm/lib/CodeGen/CalcSpillWeights.cpp index f3cb7fa5af61..fa7ef669ec11 100644 --- a/contrib/llvm-project/llvm/lib/CodeGen/CalcSpillWeights.cpp +++ b/contrib/llvm-project/llvm/lib/CodeGen/CalcSpillWeights.cpp @@ -22,6 +22,7 @@ #include "llvm/CodeGen/TargetSubtargetInfo.h" #include "llvm/CodeGen/VirtRegMap.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" #include #include @@ -256,7 +257,9 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start, return -1.0f; } - float Weight = 1.0f; + // Force Weight onto the stack so that x86 doesn't add hidden precision, + // similar to HWeight below. + stack_float_t Weight = 1.0f; if (IsSpillable) { // Get loop info for mi. if (MI->getParent() != MBB) { @@ -283,11 +286,9 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start, Register HintReg = copyHint(MI, LI.reg(), TRI, MRI); if (!HintReg) continue; - // Force hweight onto the stack so that x86 doesn't add hidden precision, + // Force HWeight onto the stack so that x86 doesn't add hidden precision, // making the comparison incorrectly pass (i.e., 1 > 1 == true??). - // - // FIXME: we probably shouldn't use floats at all. - volatile float HWeight = Hint[HintReg] += Weight; + stack_float_t HWeight = Hint[HintReg] += Weight; if (HintReg.isVirtual() || MRI.isAllocatable(HintReg)) CopyHints.insert(CopyHint(HintReg, HWeight)); }