From nobody Wed Jul 31 07:37:00 2024
X-Original-To: dev-commits-src-branches@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 4WYkSX6z18z5RP2w;
	Wed, 31 Jul 2024 07:37:00 +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 4WYkSX5K30z4pL5;
	Wed, 31 Jul 2024 07:37:00 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1722411420;
	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=Q3iv6M7PbSPY98s4/JIuw7wMtI2nGJf8h5zJB/CbmKw=;
	b=S8FjzOFTreGRUsZE5JSgs43pPD3Ubv9VVdV8BeZrMtoJyFf2Uf5Ky//3rY9jXoYkeStwHk
	UtwhxOeBIfTJAUc1mpFTk6+LM6F9GUYaMKFm84XBqGLvDuL5bj2P4tV1XbsSoW7ZvEsLUW
	OpRgm6LcysYqBBcX0XVB0wzHpKWRQpVcsNzsMD/nQzEMwpsWKMDvVrk9zxQcMok/d0naWD
	RKDEIeWnvYiZIY9kFyK9ChZCwu0klJ4wzWEbqVUZuG0DeMCn16rHEBW4+8PdEQnTx7JxDj
	g8sk2Dz9ynrAa45YR9cOh/zMyTl8ckyT5jwiJIKaMGPLYOzwf8UMMJgLuJJ7Eg==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722411420; a=rsa-sha256; cv=none;
	b=XbtM0FdWYS9g/OTa6iIjG6+07VSr+AK1HdT9P8ahl9+sHfpYu1yDRRnAdwUHi969XsM4f1
	Cou5quVYPmZC/4fD3rHO2UhGvVd/MDuFobp7qvfBSufXjA+2PfZxjusbBWyRXvxF4ASexx
	GNk0Q7Z10Y60w1qCSgebZKOVdbMWBpXBZkG43ZYEXl/GlCJ9x1mLdZ2W4wo9+sqdz1dDvY
	F/gy5pDucITI6CXPQBagq2Xyf+2UJA6SuP+PbAFfBoVwonBTGJY5vmEbTpg0VcwhFWRok8
	etuhQBGQ38YyTUQOrReW+3zUQSprXTFbNXRog/9SnSx4wWfp74oylToO88nU7g==
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=1722411420;
	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=Q3iv6M7PbSPY98s4/JIuw7wMtI2nGJf8h5zJB/CbmKw=;
	b=rtHQvS15Y3F3d+zhiH4GkgJui/1O+vMQIWbYEVgBDlzqdqvxuldBZTIxWHA48f4a5ny5yl
	xlL/3Egtg/g7Qz5yIgi4pE9wERnwxdK9jET8ct4iDflBMcf64al19gCMVsh7DnJlx8Ipx9
	zQ0FO2hchOkId4Jk07yi5aKVNAgw8PBgOgbIFwHE9mEFkfdFXK/DNTcdYd8ujgb49KfmZc
	DwkUjn41d02Bv1v5bCxa5uQi1a0BZrJ6QYIlYAUrmvNNZPZl5i7M2ufy24ywg1YTdbtrGz
	SpcSZA8/Daia/rYeSTxEgk7mdyEW86fouv8YDQ1ZalZjRw1XMstvUv7fajhepA==
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 4WYkSX4xLNzsVh;
	Wed, 31 Jul 2024 07:37:00 +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 46V7b0ga073326;
	Wed, 31 Jul 2024 07:37:00 GMT
	(envelope-from git@gitrepo.freebsd.org)
Received: (from git@localhost)
	by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46V7b0lk073323;
	Wed, 31 Jul 2024 07:37:00 GMT
	(envelope-from git)
Date: Wed, 31 Jul 2024 07:37:00 GMT
Message-Id: <202407310737.46V7b0lk073323@gitrepo.freebsd.org>
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org,
        dev-commits-src-branches@FreeBSD.org
From: Dimitry Andric <dim@FreeBSD.org>
Subject: git: 814641415fbe - stable/13 - Merge commit c80c09f3e380
  from llvm-project (by Dimitry Andric):
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@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: 814641415fbee707b312c334e00a1ebb5157e37b
Auto-Submitted: auto-generated

The branch stable/13 has been updated by dim:

URL: https://cgit.FreeBSD.org/src/commit/?id=814641415fbee707b312c334e00a1ebb5157e37b

commit 814641415fbee707b312c334e00a1ebb5157e37b
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2024-07-28 11:13:37 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2024-07-31 07:29:59 +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
    
    (cherry picked from commit 1a4b8325f6e3a45c77188343da504fe04495cc46)
---
 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<std::is_signed_v<T>, T> MulOverflow(T X, T Y, T &Result) {
     return UX > (static_cast<U>(std::numeric_limits<T>::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 <cassert>
 #include <tuple>
@@ -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));
   }