[llvm-branch-commits] [lld] release/21.x: [LLD][COFF] Allow symbols with empty chunks to have no associated output section in the PDB writer (#149523) (PR #150969)

2025-07-28 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/150969

Backport 1ab04fc94c5f68ad0dc6755e3914f2895b85e720

Requested by: @cjacek

>From b7590f6647be22bc7f84eee9dcc776eb4755b37d Mon Sep 17 00:00:00 2001
From: Jacek Caban 
Date: Mon, 28 Jul 2025 08:01:26 -0700
Subject: [PATCH] [LLD][COFF] Allow symbols with empty chunks to have no
 associated output section in the PDB writer (#149523)

If a chunk is empty and there are no other non-empty chunks in the same
section, `removeEmptySections()` will remove the entire section. In this
case, use a section index of 0, as the MSVC linker does, instead of
asserting.

(cherry picked from commit 1ab04fc94c5f68ad0dc6755e3914f2895b85e720)
---
 lld/COFF/PDB.cpp  |  9 ++---
 lld/test/COFF/pdb-empty-sec.s | 19 +++
 2 files changed, 25 insertions(+), 3 deletions(-)
 create mode 100644 lld/test/COFF/pdb-empty-sec.s

diff --git a/lld/COFF/PDB.cpp b/lld/COFF/PDB.cpp
index a54ea403ba2ec..94eeae2797971 100644
--- a/lld/COFF/PDB.cpp
+++ b/lld/COFF/PDB.cpp
@@ -1135,9 +1135,12 @@ static pdb::BulkPublic createPublic(COFFLinkerContext 
&ctx, Defined *def) {
   pub.setFlags(flags);
 
   OutputSection *os = ctx.getOutputSection(def->getChunk());
-  assert(os && "all publics should be in final image");
-  pub.Offset = def->getRVA() - os->getRVA();
-  pub.Segment = os->sectionIndex;
+  assert((os || !def->getChunk()->getSize()) &&
+ "all publics should be in final image");
+  if (os) {
+pub.Offset = def->getRVA() - os->getRVA();
+pub.Segment = os->sectionIndex;
+  }
   return pub;
 }
 
diff --git a/lld/test/COFF/pdb-empty-sec.s b/lld/test/COFF/pdb-empty-sec.s
new file mode 100644
index 0..0d61447b76651
--- /dev/null
+++ b/lld/test/COFF/pdb-empty-sec.s
@@ -0,0 +1,19 @@
+// REQUIRES: x86
+
+// RUN: llvm-mc -filetype=obj -triple=x86_64-windows %s -o %t.obj
+// RUN: lld-link -dll -noentry -debug %t.obj -out:%t.dll
+// RUN: llvm-pdbutil dump -publics %t.pdb | FileCheck %s
+
+// CHECK:   Records
+// CHECK-NEXT:   0 | S_PUB32 [size = 20] `func`
+// CHECK-NEXT:   flags = none, addr = 0001:
+// CHECK-NEXT:  20 | S_PUB32 [size = 20] `sym`
+// CHECK-NEXT:   flags = none, addr = :
+
+.globl sym
+.data
+sym:
+.text
+.globl func
+func:
+ret

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/21.x: [LLD][COFF] Allow symbols with empty chunks to have no associated output section in the PDB writer (#149523) (PR #150969)

2025-07-28 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-lld

Author: None (llvmbot)


Changes

Backport 1ab04fc94c5f68ad0dc6755e3914f2895b85e720

Requested by: @cjacek

---
Full diff: https://github.com/llvm/llvm-project/pull/150969.diff


2 Files Affected:

- (modified) lld/COFF/PDB.cpp (+6-3) 
- (added) lld/test/COFF/pdb-empty-sec.s (+19) 


``diff
diff --git a/lld/COFF/PDB.cpp b/lld/COFF/PDB.cpp
index a54ea403ba2ec..94eeae2797971 100644
--- a/lld/COFF/PDB.cpp
+++ b/lld/COFF/PDB.cpp
@@ -1135,9 +1135,12 @@ static pdb::BulkPublic createPublic(COFFLinkerContext 
&ctx, Defined *def) {
   pub.setFlags(flags);
 
   OutputSection *os = ctx.getOutputSection(def->getChunk());
-  assert(os && "all publics should be in final image");
-  pub.Offset = def->getRVA() - os->getRVA();
-  pub.Segment = os->sectionIndex;
+  assert((os || !def->getChunk()->getSize()) &&
+ "all publics should be in final image");
+  if (os) {
+pub.Offset = def->getRVA() - os->getRVA();
+pub.Segment = os->sectionIndex;
+  }
   return pub;
 }
 
diff --git a/lld/test/COFF/pdb-empty-sec.s b/lld/test/COFF/pdb-empty-sec.s
new file mode 100644
index 0..0d61447b76651
--- /dev/null
+++ b/lld/test/COFF/pdb-empty-sec.s
@@ -0,0 +1,19 @@
+// REQUIRES: x86
+
+// RUN: llvm-mc -filetype=obj -triple=x86_64-windows %s -o %t.obj
+// RUN: lld-link -dll -noentry -debug %t.obj -out:%t.dll
+// RUN: llvm-pdbutil dump -publics %t.pdb | FileCheck %s
+
+// CHECK:   Records
+// CHECK-NEXT:   0 | S_PUB32 [size = 20] `func`
+// CHECK-NEXT:   flags = none, addr = 0001:
+// CHECK-NEXT:  20 | S_PUB32 [size = 20] `sym`
+// CHECK-NEXT:   flags = none, addr = :
+
+.globl sym
+.data
+sym:
+.text
+.globl func
+func:
+ret

``




https://github.com/llvm/llvm-project/pull/150969
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/21.x: [LLD][COFF] Allow symbols with empty chunks to have no associated output section in the PDB writer (#149523) (PR #150969)

2025-07-28 Thread via llvm-branch-commits

llvmbot wrote:

@mstorsjo What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/150969
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/21.x: [LLD][COFF] Allow symbols with empty chunks to have no associated output section in the PDB writer (#149523) (PR #150969)

2025-07-28 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/150969
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atan implementation to header-only in src/__support/math folder. (PR #150852)

2025-07-28 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix updated 
https://github.com/llvm/llvm-project/pull/150852

>From 41e35b0624ca02d1295272382e8e44ba8119ff53 Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Sun, 27 Jul 2025 23:44:37 +0300
Subject: [PATCH] [libc][math] Refactor atan implementation to header-only in
 src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/atan.h   |  23 +++
 libc/src/__support/math/CMakeLists.txt|  27 +++
 libc/src/__support/math/atan.h| 189 ++
 .../generic => __support/math}/atan_utils.h   |  16 +-
 libc/src/math/generic/CMakeLists.txt  |  25 +--
 libc/src/math/generic/atan.cpp| 167 +---
 libc/src/math/generic/atan2.cpp   |   3 +-
 libc/src/math/generic/atan2f128.cpp   |   3 +-
 libc/test/shared/CMakeLists.txt   |   1 +
 libc/test/shared/shared_math_test.cpp |   1 +
 .../llvm-project-overlay/libc/BUILD.bazel |  44 ++--
 12 files changed, 286 insertions(+), 214 deletions(-)
 create mode 100644 libc/shared/math/atan.h
 create mode 100644 libc/src/__support/math/atan.h
 rename libc/src/{math/generic => __support/math}/atan_utils.h (96%)

diff --git a/libc/shared/math.h b/libc/shared/math.h
index 26e33ecd45d73..70b1b7b0bef09 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -22,6 +22,7 @@
 #include "math/asinf16.h"
 #include "math/asinhf.h"
 #include "math/asinhf16.h"
+#include "math/atan.h"
 #include "math/erff.h"
 #include "math/exp.h"
 #include "math/exp10.h"
diff --git a/libc/shared/math/atan.h b/libc/shared/math/atan.h
new file mode 100644
index 0..b9ba89b7e6225
--- /dev/null
+++ b/libc/shared/math/atan.h
@@ -0,0 +1,23 @@
+//===-- Shared atan function *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_ATAN_H
+#define LLVM_LIBC_SHARED_MATH_ATAN_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/atan.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::atan;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ATAN_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index be208f946024a..cc02920c2a1ef 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -172,6 +172,33 @@ DEPENDS
 libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  atan_utils
+  HDRS
+atan_utils.h
+DEPENDS
+libc.src.__support.integer_literals
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.macros.optimization
+)
+
+add_header_library(
+  atan
+  HDRS
+atan.h
+DEPENDS
+.atan_utils
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.macros.optimization
+)
+
 add_header_library(
   asinf
   HDRS
diff --git a/libc/src/__support/math/atan.h b/libc/src/__support/math/atan.h
new file mode 100644
index 0..62190b092429a
--- /dev/null
+++ b/libc/src/__support/math/atan.h
@@ -0,0 +1,189 @@
+//===-- Implementation header for atan --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ATAN_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ATAN_H
+
+#include "atan_utils.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/double_double.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/nearest_integer.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+// To compute atan(x), we divided it into the following cases:
+// * |x| < 2^-26:
+//  Since |x| > atan(|x|) > |x| - |x|^3/3, and |x|^3/3 < ulp(x)/2, we 
simply
+//  return atan(x) = x - sign(x) * epsilon.
+// * 2^-26 <= |x| < 1:
+//  We perform range reduction mod 2^-6 = 1/64 as follow:
+//  Let k = 2^(-6) * round(|x| * 2^6), then
+//atan(x) = sign(x) * atan(|x|)
+//

[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atanf implementation to header-only in src/__support/math folder. (PR #150854)

2025-07-28 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix updated 
https://github.com/llvm/llvm-project/pull/150854

>From ca83f9dfa292c0aca3b61f9033a36df18350ed73 Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Mon, 28 Jul 2025 00:37:42 +0300
Subject: [PATCH] [libc][math] Refactor atanf implementation to header-only in
 src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/atanf.h  |  23 
 libc/src/__support/math/CMakeLists.txt|  15 ++
 libc/src/__support/math/atanf.h   | 129 ++
 libc/src/math/generic/CMakeLists.txt  |   9 +-
 libc/src/math/generic/atanf.cpp   | 110 +--
 libc/test/shared/CMakeLists.txt   |   1 +
 libc/test/shared/shared_math_test.cpp |   1 +
 .../llvm-project-overlay/libc/BUILD.bazel |  22 ++-
 9 files changed, 188 insertions(+), 123 deletions(-)
 create mode 100644 libc/shared/math/atanf.h
 create mode 100644 libc/src/__support/math/atanf.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index 70b1b7b0bef09..21536647948f4 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -23,6 +23,7 @@
 #include "math/asinhf.h"
 #include "math/asinhf16.h"
 #include "math/atan.h"
+#include "math/atanf.h"
 #include "math/erff.h"
 #include "math/exp.h"
 #include "math/exp10.h"
diff --git a/libc/shared/math/atanf.h b/libc/shared/math/atanf.h
new file mode 100644
index 0..858d727bd6698
--- /dev/null
+++ b/libc/shared/math/atanf.h
@@ -0,0 +1,23 @@
+//===-- Shared atanf function ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_ATANF_H
+#define LLVM_LIBC_SHARED_MATH_ATANF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/atanf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::atanf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ATANF_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index cc02920c2a1ef..95acc962cc885 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -199,6 +199,21 @@ DEPENDS
 libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  atanf
+  HDRS
+atanf.h
+  DEPENDS
+.inv_trigf_utils
+libc.src.__support.FPUtil.except_value_utils
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.FPUtil.rounding_mode
+libc.src.__support.macros.optimization
+)
+
 add_header_library(
   asinf
   HDRS
diff --git a/libc/src/__support/math/atanf.h b/libc/src/__support/math/atanf.h
new file mode 100644
index 0..92799dc8db3cc
--- /dev/null
+++ b/libc/src/__support/math/atanf.h
@@ -0,0 +1,129 @@
+//===-- Implementation header for atanf -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ATANF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ATANF_H
+
+#include "inv_trigf_utils.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.h"
+#include "src/__support/FPUtil/except_value_utils.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/nearest_integer.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE static constexpr float atanf(float x) {
+  using namespace inv_trigf_utils_internal;
+  using FPBits = typename fputil::FPBits;
+
+  constexpr double FINAL_SIGN[2] = {1.0, -1.0};
+  constexpr double SIGNED_PI_OVER_2[2] = {0x1.921fb54442d18p0,
+  -0x1.921fb54442d18p0};
+
+  FPBits x_bits(x);
+  Sign sign = x_bits.sign();
+  x_bits.set_sign(Sign::POS);
+  uint32_t x_abs = x_bits.uintval();
+
+  // x is inf or nan, |x| < 2^-4 or |x|= > 16.
+  if (LIBC_UNLIKELY(x_abs <= 0x3d80'U || x_abs >= 0x4180'U)) {
+double x_d = static_cast(x);
+double const_term = 0.0;
+if (LIBC_UNLIKELY(x_abs >= 0x4180')) {
+  // atan(+-Inf) = +-pi/2.
+  if (x_bits.is_inf()) {
+volatile double sign_pi_over_2 = SIGNED_PI_OVER_2[sign.is_neg()];
+return static_cast(sign_pi_over_2);
+  }
+  if (x_bits.is_nan())
+ 

[llvm-branch-commits] [llvm] [CI] Backport recent changes to release branch (PR #150949)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru approved this pull request.


https://github.com/llvm/llvm-project/pull/150949
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atanf16 implementation to header-only in src/__support/math folder. (PR #150868)

2025-07-28 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix updated 
https://github.com/llvm/llvm-project/pull/150868

>From e361d72613ded94fa78a5c1a4baa366c799a6d7b Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Mon, 28 Jul 2025 05:26:38 +0300
Subject: [PATCH] [libc][math] Refactor atanf16 implementation to header-only
 in src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/atanf16.h|  28 +
 libc/src/__support/math/CMakeLists.txt|  15 +++
 libc/src/__support/math/atanf16.h | 119 ++
 libc/src/math/generic/CMakeLists.txt  |  12 +-
 libc/src/math/generic/atanf16.cpp |  95 +-
 libc/test/shared/CMakeLists.txt   |   1 +
 libc/test/shared/shared_math_test.cpp |   1 +
 .../llvm-project-overlay/libc/BUILD.bazel |  22 
 9 files changed, 190 insertions(+), 104 deletions(-)
 create mode 100644 libc/shared/math/atanf16.h
 create mode 100644 libc/src/__support/math/atanf16.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index 21536647948f4..bcbe0de56170a 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -24,6 +24,7 @@
 #include "math/asinhf16.h"
 #include "math/atan.h"
 #include "math/atanf.h"
+#include "math/atanf16.h"
 #include "math/erff.h"
 #include "math/exp.h"
 #include "math/exp10.h"
diff --git a/libc/shared/math/atanf16.h b/libc/shared/math/atanf16.h
new file mode 100644
index 0..f196907059e01
--- /dev/null
+++ b/libc/shared/math/atanf16.h
@@ -0,0 +1,28 @@
+//===-- Shared atanf16 function -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_ATANF16_H
+#define LLVM_LIBC_SHARED_MATH_ATANF16_H
+
+#include "shared/libc_common.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/atanf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::atanf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_ATANF16_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index 95acc962cc885..04cbd3fd1cc01 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -214,6 +214,21 @@ add_header_library(
 libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  atanf16
+  HDRS
+atanf16.h
+  DEPENDS
+libc.src.__support.FPUtil.cast
+libc.src.__support.FPUtil.except_value_utils
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.FPUtil.sqrt
+libc.src.__support.macros.optimization
+)
+
 add_header_library(
   asinf
   HDRS
diff --git a/libc/src/__support/math/atanf16.h 
b/libc/src/__support/math/atanf16.h
new file mode 100644
index 0..f75d145f36852
--- /dev/null
+++ b/libc/src/__support/math/atanf16.h
@@ -0,0 +1,119 @@
+//===-- Implementation header for atanf16 ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ATANF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ATANF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.h"
+#include "src/__support/FPUtil/cast.h"
+#include "src/__support/FPUtil/except_value_utils.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/sqrt.h"
+#include "src/__support/macros/optimization.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE static constexpr float16 atanf16(float16 x) {
+  // Generated by Solly using the following command:
+  // > round(pi/2, SG, RN);
+  constexpr float PI_2 = 0x1.921fb6p0;
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+  constexpr size_t N_EXCEPTS = 6;
+
+  constexpr fputil::ExceptValues ATANF16_EXCEPTS{{
+  // (input, RZ output, RU offset, RD offset, RN offset)
+  {0x2745, 0x2744, 1, 0, 1},
+  {0x3099, 0x3090, 1, 0, 1},
+  {0x3c6c, 0x3aae, 1, 0, 1},
+  {0x466e, 0x3daa, 1, 0, 1},
+  {0x48ae, 0x3ddb, 1, 0, 0},
+  {0x5619, 0x3e3d, 1, 0, 1},
+  }};
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+  using FPBits = fputil::FPBits;
+  FPBits xbits(x);
+
+  uint16_t x

[llvm-branch-commits] [llvm] [CI] Backport recent changes to release branch (PR #150949)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru closed https://github.com/llvm/llvm-project/pull/150949
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [AMDGPU] Improve StructurizeCFG pass performance by using SSAUpdaterBulk. (PR #150937)

2025-07-28 Thread Shilei Tian via llvm-branch-commits

shiltian wrote:

Can you request an internal psdb full cycle to test this PR? StructurizeCFG 
seems very sensitive to changes.

https://github.com/llvm/llvm-project/pull/150937
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [flang][OpenMP] Make all block constructs share the same structure (PR #150956)

2025-07-28 Thread Krzysztof Parzyszek via llvm-branch-commits

kparzysz wrote:

Part of the reason to do this is that it will make dealing with the hundreds of 
new compound directives easier.  The next step would be to make the parser 
parse constructs based on properties (such as association), not names or 
directive id's.

https://github.com/llvm/llvm-project/pull/150956
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] Reland "RegisterCoalescer: Add implicit-def of super register when coalescing SUBREG_TO_REG" (PR #134408)

2025-07-28 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm approved this pull request.


https://github.com/llvm/llvm-project/pull/134408
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] AMDGPU: Add a few missing mfma rewrite tests (PR #149026)

2025-07-28 Thread Sirish Pande via llvm-branch-commits

https://github.com/srpande approved this pull request.


https://github.com/llvm/llvm-project/pull/149026
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] AlwaysInliner: A new inlining algorithm to interleave alloca promotion with inlines. (PR #145613)

2025-07-28 Thread Amara Emerson via llvm-branch-commits

aemerson wrote:

pong

https://github.com/llvm/llvm-project/pull/145613
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][DebugInfo] Disable VTable debug info (#130255) on COFF platforms (PR #150938)

2025-07-28 Thread Tomohiro Kashiwada via llvm-branch-commits

kikairoya wrote:

> Thanks! I took the liberty to further reword it a bit more, to clarify the 
> scope - let me know if you disagree with the wording.

Thank you for your follow-up. I really appreciate it.


https://github.com/llvm/llvm-project/pull/150938
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: opencl: Ensure printf symbol is not mangled. (#150210) (PR #150960)

2025-07-28 Thread via llvm-branch-commits

github-actions[bot] wrote:

⚠️ We detected that you are using a GitHub private e-mail address to contribute 
to the repo. Please turn off [Keep my email addresses 
private](https://github.com/settings/emails) setting in your account. See 
[LLVM Developer 
Policy](https://llvm.org/docs/DeveloperPolicy.html#email-addresses) and [LLVM 
Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it)
 for more information.

https://github.com/llvm/llvm-project/pull/150960
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atan2 implementation to header-only in src/__support/math folder. (PR #150968)

2025-07-28 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix updated 
https://github.com/llvm/llvm-project/pull/150968

>From d0488b8711b10233a6bb91b5d67b104837fd3eb7 Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Mon, 28 Jul 2025 18:07:19 +0300
Subject: [PATCH] [libc][math] Refactor atan2 implementation to header-only in
 src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/atan2.h  |  23 ++
 libc/src/__support/math/CMakeLists.txt|  20 +-
 libc/src/__support/math/atan2.h   | 209 ++
 libc/src/math/generic/CMakeLists.txt  |   8 +-
 libc/src/math/generic/atan2.cpp   | 187 +---
 libc/test/shared/CMakeLists.txt   |   1 +
 libc/test/shared/shared_math_test.cpp |   1 +
 .../llvm-project-overlay/libc/BUILD.bazel |  14 +-
 9 files changed, 266 insertions(+), 198 deletions(-)
 create mode 100644 libc/shared/math/atan2.h
 create mode 100644 libc/src/__support/math/atan2.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index bcbe0de56170a..0605d918eb2af 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -23,6 +23,7 @@
 #include "math/asinhf.h"
 #include "math/asinhf16.h"
 #include "math/atan.h"
+#include "math/atan2.h"
 #include "math/atanf.h"
 #include "math/atanf16.h"
 #include "math/erff.h"
diff --git a/libc/shared/math/atan2.h b/libc/shared/math/atan2.h
new file mode 100644
index 0..894110838817c
--- /dev/null
+++ b/libc/shared/math/atan2.h
@@ -0,0 +1,23 @@
+//===-- Shared atan2 function ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_ATAN2_H
+#define LLVM_LIBC_SHARED_MATH_ATAN2_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/atan2.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::atan2;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ATAN2_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index 04cbd3fd1cc01..bbb07b62552f6 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -158,7 +158,7 @@ add_header_library(
   asinhf16
   HDRS
 asinhf16.h
-DEPENDS
+  DEPENDS
 .acoshf_utils
 libc.src.__support.FPUtil.fenv_impl
 libc.src.__support.FPUtil.fp_bits
@@ -176,7 +176,7 @@ add_header_library(
   atan_utils
   HDRS
 atan_utils.h
-DEPENDS
+  DEPENDS
 libc.src.__support.integer_literals
 libc.src.__support.FPUtil.double_double
 libc.src.__support.FPUtil.dyadic_float
@@ -189,7 +189,21 @@ add_header_library(
   atan
   HDRS
 atan.h
-DEPENDS
+  DEPENDS
+.atan_utils
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.macros.optimization
+)
+
+add_header_library(
+  atan2
+  HDRS
+atan2.h
+  DEPENDS
 .atan_utils
 libc.src.__support.FPUtil.double_double
 libc.src.__support.FPUtil.fenv_impl
diff --git a/libc/src/__support/math/atan2.h b/libc/src/__support/math/atan2.h
new file mode 100644
index 0..90ed926c8d75f
--- /dev/null
+++ b/libc/src/__support/math/atan2.h
@@ -0,0 +1,209 @@
+//===-- Implementation header for atan2 -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ATAN2_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ATAN2_H
+
+#include "atan_utils.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/double_double.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/nearest_integer.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+// There are several range reduction steps we can take for atan2(y, x) as
+// follow:
+
+// * Range reduction 1: signness
+// atan2(y, x) will return a number between -PI and PI representing the angle
+// forming by the 0x axis and the vector (x, y) on the 0xy-plane.
+// In particular, we have that:
+//   atan2(y, x) = atan( y/x ) if x >= 0 and y >= 0 (I-quadrant)
+//   = pi + atan( y/x )if x < 0 and y >= 0  (II-quadrant)
+//  

[llvm-branch-commits] [llvm] release/21.x: [flang-rt] Remove hard-coded dependency on compiler-rt path on Windows (#150244) (PR #150764)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru updated https://github.com/llvm/llvm-project/pull/150764

>From 9257a0500f4f3a052113b9b5018d8528a1fc7762 Mon Sep 17 00:00:00 2001
From: David Truby 
Date: Sat, 26 Jul 2025 14:42:42 +0100
Subject: [PATCH] [flang-rt] Remove hard-coded dependency on compiler-rt path
 on Windows (#150244)

This fixes an issue where if the build folder is no longer present flang
cannot link anything on Windows because the path to compiler-rt in the
binary is hard-coded. Flang already links compiler-rt on Windows so it
isn't necessary for flang-rt to specify that it depends on compiler-rt
at all, other than for the unit tests, so instead we can move that logic
into the unit test compile lines.

(cherry picked from commit c20a95a7ddd8219f3e587e335a0a8e3f4613fc47)
---
 flang-rt/cmake/modules/AddFlangRT.cmake | 21 -
 flang-rt/unittests/CMakeLists.txt   | 23 +++
 2 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/flang-rt/cmake/modules/AddFlangRT.cmake 
b/flang-rt/cmake/modules/AddFlangRT.cmake
index e51590fdae3d3..58541609829c4 100644
--- a/flang-rt/cmake/modules/AddFlangRT.cmake
+++ b/flang-rt/cmake/modules/AddFlangRT.cmake
@@ -286,27 +286,6 @@ function (add_flangrt_library name)
   target_compile_options(${tgtname} PUBLIC -U_LIBCPP_ENABLE_ASSERTIONS)
 endif ()
 
-# Flang/Clang (including clang-cl) -compiled programs targeting the MSVC 
ABI
-# should only depend on msvcrt/ucrt. LLVM still emits libgcc/compiler-rt
-# functions in some cases like 128-bit integer math (__udivti3, __modti3,
-# __fixsfti, __floattidf, ...) that msvc does not support. We are 
injecting a
-# dependency to Compiler-RT's builtin library where these are implemented.
-if (MSVC AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
-  if (FLANG_RT_BUILTINS_LIBRARY)
-target_compile_options(${tgtname} PRIVATE 
"$<$:-Xclang>" 
"$<$:--dependent-lib=${FLANG_RT_BUILTINS_LIBRARY}>")
-  endif ()
-endif ()
-if (MSVC AND CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang")
-  if (FLANG_RT_BUILTINS_LIBRARY)
-target_compile_options(${tgtname} PRIVATE 
"$<$:-Xflang>" 
"$<$:--dependent-lib=${FLANG_RT_BUILTINS_LIBRARY}>")
-  else ()
-message(WARNING "Did not find libclang_rt.builtins.lib.
-  LLVM may emit builtins that are not implemented in msvcrt/ucrt and
-  instead falls back to builtins from Compiler-RT. Linking with 
${tgtname}
-  may result in a linker error.")
-  endif ()
-endif ()
-
 # Non-GTest unittests depend on LLVMSupport
 if (ARG_LINK_TO_LLVM)
   if (LLVM_LINK_LLVM_DYLIB)
diff --git a/flang-rt/unittests/CMakeLists.txt 
b/flang-rt/unittests/CMakeLists.txt
index 5282196174134..831bc8a4c2906 100644
--- a/flang-rt/unittests/CMakeLists.txt
+++ b/flang-rt/unittests/CMakeLists.txt
@@ -60,6 +60,27 @@ function(add_flangrt_unittest_offload_properties target)
   endif()
 endfunction()
 
+# flang-rt on Windows requires compiler-rt for some symbols. For binaries built
+# with flang this dependency is added by the flang driver, but since the unit
+# tests are built with clang we need to add the dependency manually.
+function(add_flangrt_dependent_libs target)
+  if (MSVC AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+if (FLANG_RT_BUILTINS_LIBRARY)
+  target_compile_options(${target} PRIVATE 
"$<$:-Xclang>" 
"$<$:--dependent-lib=${FLANG_RT_BUILTINS_LIBRARY}>")
+endif ()
+  endif ()
+  if (MSVC AND CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang")
+if (FLANG_RT_BUILTINS_LIBRARY)
+  target_compile_options(${target} PRIVATE 
"$<$:-Xflang>" 
"$<$:--dependent-lib=${FLANG_RT_BUILTINS_LIBRARY}>")
+else ()
+  message(WARNING "Did not find libclang_rt.builtins.lib.
+LLVM may emit builtins that are not implemented in msvcrt/ucrt and
+instead falls back to builtins from Compiler-RT. Linking with 
${tgtname}
+may result in a linker error.")
+endif ()
+  endif ()
+endfunction()
+
 
 function(add_flangrt_unittest test_dirname)
   cmake_parse_arguments(ARG
@@ -72,6 +93,7 @@ function(add_flangrt_unittest test_dirname)
 
   target_link_libraries(${test_dirname} PRIVATE ${ARG_LINK_LIBS})
   add_flangrt_unittest_offload_properties(${test_dirname})
+  add_flangrt_dependent_libs(${test_dirname})
 
   # Required because LLVMSupport is compiled with this option.
   # FIXME: According to CMake documentation, this is the default. Why is it
@@ -99,6 +121,7 @@ function(add_flangrt_nongtest_unittest test_name)
   set_target_properties(${test_name}${suffix} PROPERTIES FOLDER 
"Flang-RT/Tests/Unit")
 
   target_link_libraries(${test_name}${suffix} PRIVATE NonGTestTesting 
${ARG_LINK_LIBS})
+  add_flangrt_dependent_libs(${test_name}${suffix})
 
   if(NOT ARG_SLOW_TEST)
 add_dependencies(FlangRTUnitTests ${test_name}${suffix})

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cg

[llvm-branch-commits] [llvm] release/21.x: [CodeGenPrepare] Make sure that `AddOffset` is also a loop invariant (#150625) (PR #150646)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru updated https://github.com/llvm/llvm-project/pull/150646

>From 56ff1bbdde730433f292e130eb7f5759fd8929ba Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Sat, 26 Jul 2025 00:23:56 +0800
Subject: [PATCH] [CodeGenPrepare] Make sure that `AddOffset` is also a loop
 invariant (#150625)

Closes https://github.com/llvm/llvm-project/issues/150611.

(cherry picked from commit 2d0ca09305fcece75e2c501f1ec74aa6eada69a0)
---
 llvm/lib/CodeGen/CodeGenPrepare.cpp   |  4 +++
 .../CodeGenPrepare/X86/fold-loop-of-urem.ll   | 34 +++
 2 files changed, 38 insertions(+)

diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp 
b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 9bbb89e37865d..3d1408256df8e 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -2096,6 +2096,10 @@ static bool isRemOfLoopIncrementWithLoopInvariant(
   if (!L->isLoopInvariant(RemAmt))
 return false;
 
+  // Only works if the AddOffset is a loop invaraint
+  if (AddOffset && !L->isLoopInvariant(AddOffset))
+return false;
+
   // Is the PHI a loop increment?
   auto LoopIncrInfo = getIVIncrement(PN, LI);
   if (!LoopIncrInfo)
diff --git a/llvm/test/Transforms/CodeGenPrepare/X86/fold-loop-of-urem.ll 
b/llvm/test/Transforms/CodeGenPrepare/X86/fold-loop-of-urem.ll
index 7abc32e4f1cd8..f53127f015391 100644
--- a/llvm/test/Transforms/CodeGenPrepare/X86/fold-loop-of-urem.ll
+++ b/llvm/test/Transforms/CodeGenPrepare/X86/fold-loop-of-urem.ll
@@ -1065,3 +1065,37 @@ for.body:
   %exitcond.not = icmp eq i32 %inc, %N
   br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
 }
+
+define i64 @pr150611_add_offset_is_not_loop_invariant(i1 %cond) {
+; CHECK-LABEL: define i64 @pr150611_add_offset_is_not_loop_invariant(
+; CHECK-SAME: i1 [[COND:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*]]:
+; CHECK-NEXT:[[REMAMT:%.*]] = select i1 [[COND]], i64 2, i64 0
+; CHECK-NEXT:br label %[[FOR_BODY:.*]]
+; CHECK:   [[FOR_BODY]]:
+; CHECK-NEXT:[[INDVARS:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ 
[[INDVARS_NEXT:%.*]], %[[FOR_BODY]] ]
+; CHECK-NEXT:[[ADD_OFFSET:%.*]] = zext i1 [[COND]] to i64
+; CHECK-NEXT:[[ADD:%.*]] = add nuw i64 [[INDVARS]], [[ADD_OFFSET]]
+; CHECK-NEXT:[[REM:%.*]] = urem i64 [[ADD]], [[REMAMT]]
+; CHECK-NEXT:[[INDVARS_NEXT]] = add nuw i64 [[INDVARS]], 1
+; CHECK-NEXT:[[EXITCOND:%.*]] = icmp eq i64 [[INDVARS_NEXT]], 3
+; CHECK-NEXT:br i1 [[EXITCOND]], label %[[FOR_EXIT:.*]], label 
%[[FOR_BODY]]
+; CHECK:   [[FOR_EXIT]]:
+; CHECK-NEXT:ret i64 [[REM]]
+;
+entry:
+  %remamt = select i1 %cond, i64 2, i64 0
+  br label %for.body
+
+for.body:
+  %indvars = phi i64 [ 0, %entry ], [ %indvars.next, %for.body ]
+  %add.offset = zext i1 %cond to i64
+  %add = add nuw i64 %indvars, %add.offset
+  %rem = urem i64 %add, %remamt
+  %indvars.next = add nuw i64 %indvars, 1
+  %exitcond = icmp eq i64 %indvars.next, 3
+  br i1 %exitcond, label %for.exit, label %for.body
+
+for.exit:
+  ret i64 %rem
+}

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/21.x: [lld][LoongArch] Support relaxation during TLSDESC GD/LD to IE/LE conversion (#123730) (PR #150895)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru updated https://github.com/llvm/llvm-project/pull/150895

>From 434e8e2a5c1fdb6bae91f7a2588d5796ebaf8145 Mon Sep 17 00:00:00 2001
From: Zhaoxin Yang 
Date: Wed, 23 Jul 2025 17:12:13 +0800
Subject: [PATCH] [lld][LoongArch] Support relaxation during TLSDESC GD/LD to
 IE/LE conversion (#123730)

Complement https://github.com/llvm/llvm-project/pull/123715. When
relaxation enable, remove redundant NOPs.

(cherry picked from commit 2a5cd50c469891a0bc918b42785cbf6fd6132a50)
---
 lld/ELF/Arch/LoongArch.cpp | 32 --
 lld/test/ELF/loongarch-relax-tlsdesc.s | 45 +-
 2 files changed, 45 insertions(+), 32 deletions(-)

diff --git a/lld/ELF/Arch/LoongArch.cpp b/lld/ELF/Arch/LoongArch.cpp
index fe804cbb0e690..15dcddb13baf7 100644
--- a/lld/ELF/Arch/LoongArch.cpp
+++ b/lld/ELF/Arch/LoongArch.cpp
@@ -966,10 +966,16 @@ static bool relax(Ctx &ctx, InputSection &sec) {
 case R_LARCH_GOT_PC_HI20:
 case R_LARCH_TLS_GD_PC_HI20:
 case R_LARCH_TLS_LD_PC_HI20:
-case R_LARCH_TLS_DESC_PC_HI20:
   // The overflow check for i+2 will be carried out in isPairRelaxable.
-  if (r.expr != RE_LOONGARCH_RELAX_TLS_GD_TO_IE_PAGE_PC &&
-  r.expr != R_RELAX_TLS_GD_TO_LE && isPairRelaxable(relocs, i))
+  if (isPairRelaxable(relocs, i))
+relaxPCHi20Lo12(ctx, sec, i, loc, r, relocs[i + 2], remove);
+  break;
+case R_LARCH_TLS_DESC_PC_HI20:
+  if (r.expr == RE_LOONGARCH_RELAX_TLS_GD_TO_IE_PAGE_PC ||
+  r.expr == R_RELAX_TLS_GD_TO_LE) {
+if (relaxable(relocs, i))
+  remove = 4;
+  } else if (isPairRelaxable(relocs, i))
 relaxPCHi20Lo12(ctx, sec, i, loc, r, relocs[i + 2], remove);
   break;
 case R_LARCH_CALL36:
@@ -987,6 +993,17 @@ static bool relax(Ctx &ctx, InputSection &sec) {
   isUInt<12>(r.sym->getVA(ctx, r.addend)))
 remove = 4;
   break;
+case R_LARCH_TLS_DESC_PC_LO12:
+  if (relaxable(relocs, i) &&
+  (r.expr == RE_LOONGARCH_RELAX_TLS_GD_TO_IE_PAGE_PC ||
+   r.expr == R_RELAX_TLS_GD_TO_LE))
+remove = 4;
+  break;
+case R_LARCH_TLS_DESC_LD:
+  if (relaxable(relocs, i) && r.expr == R_RELAX_TLS_GD_TO_LE &&
+  isUInt<12>(r.sym->getVA(ctx, r.addend)))
+remove = 4;
+  break;
 }
 
 // For all anchors whose offsets are <= r.offset, they are preceded by
@@ -1216,6 +1233,10 @@ void LoongArch::relocateAlloc(InputSectionBase &sec, 
uint8_t *buf) const {
bits);
 relocateNoSym(loc, rel.type, val);
   } else {
+isRelax = relaxable(relocs, i);
+if (isRelax && (rel.type == R_LARCH_TLS_DESC_PC_HI20 ||
+rel.type == R_LARCH_TLS_DESC_PC_LO12))
+  continue;
 tlsdescToIe(loc, rel, val);
   }
   continue;
@@ -1232,6 +1253,11 @@ void LoongArch::relocateAlloc(InputSectionBase &sec, 
uint8_t *buf) const {
bits);
 relocateNoSym(loc, rel.type, val);
   } else {
+isRelax = relaxable(relocs, i);
+if (isRelax && (rel.type == R_LARCH_TLS_DESC_PC_HI20 ||
+rel.type == R_LARCH_TLS_DESC_PC_LO12 ||
+(rel.type == R_LARCH_TLS_DESC_LD && isUInt<12>(val
+  continue;
 tlsdescToLe(loc, rel, val);
   }
   continue;
diff --git a/lld/test/ELF/loongarch-relax-tlsdesc.s 
b/lld/test/ELF/loongarch-relax-tlsdesc.s
index 5f4368343471c..025cbc09fbdd8 100644
--- a/lld/test/ELF/loongarch-relax-tlsdesc.s
+++ b/lld/test/ELF/loongarch-relax-tlsdesc.s
@@ -9,7 +9,6 @@
 # RUN: llvm-readobj -r -x .got a.64.so | FileCheck --check-prefix=GD64-RELA %s
 # RUN: llvm-objdump --no-show-raw-insn -dr -h a.64.so | FileCheck %s 
--check-prefix=GD64
 
-## FIXME: IE/LE relaxation have not yet been implemented, --relax/--no-relax 
obtain the same results.
 ## Transition from TLSDESC to IE/LE. Also check --emit-relocs.
 # RUN: ld.lld -e 0 -z now --emit-relocs a.64.o c.64.o -o a.64.le
 # RUN: llvm-readobj -r -x .got a.64.le 2>&1 | FileCheck 
--check-prefix=LE64-RELA %s
@@ -73,25 +72,21 @@
 # LE64-RELA: could not find section '.got'
 
 ## a@tprel = 0x8
-# LE64:20158: nop
+# LE64:20158: ori $a0, $zero, 8
 # LE64-NEXT:R_LARCH_TLS_DESC_PC_HI20 a
 # LE64-NEXT:R_LARCH_RELAX *ABS*
-# LE64-NEXT:  nop
 # LE64-NEXT:R_LARCH_TLS_DESC_PC_LO12 a
 # LE64-NEXT:R_LARCH_RELAX *ABS*
-# LE64-NEXT:  nop
 # LE64-NEXT:R_LARCH_TLS_DESC_LD a
 # LE64-NEXT:R_LARCH_RELAX *ABS*
-# LE64-NEXT:  ori $a0, $zero, 8
 # LE64-NEXT:R_LARCH_TLS_DESC_CALL a
 # LE64-NEXT:R_LARCH_RELAX *ABS*
 # LE64-NEXT:  add.d   $a1, $a0, $tp
 
 ## b@tprel = 0x7ff
-# LE64:2016c: nop
+# LE64:20160: nop
 # LE64-NEXT:R_LARCH_TLS_DESC_PC_HI20 b
 # LE64-NEXT:R_LARCH_RELAX *ABS*
-# LE64-NEXT:

[llvm-branch-commits] [llvm] release/21.x: [Mips] Fix wrong ELF FP ABI info when inline asm was empty (#146457) (PR #150866)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru updated https://github.com/llvm/llvm-project/pull/150866

>From cd72b5039c42321abd70eeb650d3e50f6e691f39 Mon Sep 17 00:00:00 2001
From: yingopq <115543042+ying...@users.noreply.github.com>
Date: Mon, 28 Jul 2025 09:07:51 +0800
Subject: [PATCH] [Mips] Fix wrong ELF FP ABI info when inline asm was empty
 (#146457)

When Mips process emitStartOfAsmFile and updateABIInfo, it did not know
the real value of IsSoftFloat and STI.useSoftFloat(). And when inline
asm instruction was empty, Mips did not process asm parser, so it would
not do TS.updateABIInfo(STI) again and at this time the value of
IsSoftFloat is correct.

Fix #135283.

(cherry picked from commit 778fb76e6308534a63239a91b98f5dad055f6fdb)
---
 llvm/lib/Target/Mips/MipsAsmPrinter.cpp   |  8 ++--
 llvm/test/CodeGen/Mips/abiflags-soft-float.ll | 12 
 2 files changed, 18 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/CodeGen/Mips/abiflags-soft-float.ll

diff --git a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp 
b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
index 87e06a6d3c08a..2903ff75475cf 100644
--- a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
+++ b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -747,14 +747,18 @@ void MipsAsmPrinter::emitStartOfAsmFile(Module &M) {
 if (FS.empty() && M.size() && F->hasFnAttribute("target-features"))
   FS = F->getFnAttribute("target-features").getValueAsString();
 
+std::string strFS = FS.str();
+if (M.size() && F->getFnAttribute("use-soft-float").getValueAsBool())
+  strFS += strFS.empty() ? "+soft-float" : ",+soft-float";
+
 // Compute MIPS architecture attributes based on the default subtarget
 // that we'd have constructed.
 // FIXME: For ifunc related functions we could iterate over and look
 // for a feature string that doesn't match the default one.
 StringRef CPU = MIPS_MC::selectMipsCPU(TT, TM.getTargetCPU());
 const MipsTargetMachine &MTM = static_cast(TM);
-const MipsSubtarget STI(TT, CPU, FS, MTM.isLittleEndian(), MTM,
-std::nullopt);
+const MipsSubtarget STI(TT, CPU, StringRef(strFS), MTM.isLittleEndian(),
+MTM, std::nullopt);
 
 bool IsABICalls = STI.isABICalls();
 const MipsABIInfo &ABI = MTM.getABI();
diff --git a/llvm/test/CodeGen/Mips/abiflags-soft-float.ll 
b/llvm/test/CodeGen/Mips/abiflags-soft-float.ll
new file mode 100644
index 0..01821f2d9b6c6
--- /dev/null
+++ b/llvm/test/CodeGen/Mips/abiflags-soft-float.ll
@@ -0,0 +1,12 @@
+; RUN: llc -filetype=obj -mtriple mipsel-unknown-linux -mcpu=mips32 %s -o tmp.o
+; RUN: llvm-readobj -A tmp.o | FileCheck %s -check-prefix=OBJ
+; RUN: llc -filetype=asm -mtriple mipsel-unknown-linux -mcpu=mips32 %s -o - | \
+; RUN: FileCheck %s -check-prefix=ASM
+
+; OBJ: FP ABI: Soft float
+; ASM: .module softfloat 
+
+define dso_local void @asm_is_null() "use-soft-float"="true" {
+  call void asm sideeffect "", ""()
+  ret void
+}

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/21.x: [CodeGen] More consistently expand float ops by default (#150597) (PR #150970)

2025-07-28 Thread via llvm-branch-commits

llvmbot wrote:

@arsenm What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/150970
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/21.x: Revert "[MIPS]Fix QNaNs in the MIPS legacy NaN encodings" (#150773) (PR #150902)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru updated https://github.com/llvm/llvm-project/pull/150902

>From 6260262ad1c160106ce4c8be713e6a6be633181f Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Mon, 28 Jul 2025 10:36:40 +0200
Subject: [PATCH] Revert "[MIPS]Fix QNaNs in the MIPS legacy NaN encodings"
 (#150773)

Reverts llvm/llvm-project#139829.

We can't just randomly change the value of constants during lowering.

Fixes https://github.com/llvm/llvm-project/issues/149295.

(cherry picked from commit 525090e83ca392753d371602b5e64f06e7debd9a)
---
 llvm/lib/Target/Mips/MipsISelLowering.cpp | 29 ---
 llvm/lib/Target/Mips/MipsISelLowering.h   |  1 -
 llvm/test/CodeGen/Mips/nan_lowering.ll| 25 +++
 llvm/test/CodeGen/Mips/qnan.ll| 14 ---
 4 files changed, 25 insertions(+), 44 deletions(-)
 create mode 100644 llvm/test/CodeGen/Mips/nan_lowering.ll
 delete mode 100644 llvm/test/CodeGen/Mips/qnan.ll

diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp 
b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index 0e581a7a16503..ec6b382151660 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -522,9 +522,6 @@ MipsTargetLowering::MipsTargetLowering(const 
MipsTargetMachine &TM,
 
   setOperationAction(ISD::TRAP, MVT::Other, Legal);
 
-  setOperationAction(ISD::ConstantFP, MVT::f32, Custom);
-  setOperationAction(ISD::ConstantFP, MVT::f64, Custom);
-
   setTargetDAGCombine({ISD::SDIVREM, ISD::UDIVREM, ISD::SELECT, ISD::AND,
ISD::OR, ISD::ADD, ISD::SUB, ISD::AssertZext, ISD::SHL,
ISD::SIGN_EXTEND});
@@ -1360,8 +1357,6 @@ LowerOperation(SDValue Op, SelectionDAG &DAG) const
   case ISD::FP_TO_SINT: return lowerFP_TO_SINT(Op, DAG);
   case ISD::READCYCLECOUNTER:
 return lowerREADCYCLECOUNTER(Op, DAG);
-  case ISD::ConstantFP:
-return lowerConstantFP(Op, DAG);
   }
   return SDValue();
 }
@@ -3019,30 +3014,6 @@ SDValue MipsTargetLowering::lowerFP_TO_SINT(SDValue Op,
   return DAG.getNode(ISD::BITCAST, SDLoc(Op), Op.getValueType(), Trunc);
 }
 
-SDValue MipsTargetLowering::lowerConstantFP(SDValue Op,
-SelectionDAG &DAG) const {
-  SDLoc DL(Op);
-  EVT VT = Op.getSimpleValueType();
-  SDNode *N = Op.getNode();
-  ConstantFPSDNode *CFP = cast(N);
-
-  if (!CFP->isNaN() || Subtarget.isNaN2008()) {
-return SDValue();
-  }
-
-  APFloat NaNValue = CFP->getValueAPF();
-  auto &Sem = NaNValue.getSemantics();
-
-  // The MSB of the mantissa should be zero for QNaNs in the MIPS legacy NaN
-  // encodings, and one for sNaNs. Check every NaN constants and make sure
-  // they are correctly encoded for legacy encodings.
-  if (!NaNValue.isSignaling()) {
-APFloat RealQNaN = NaNValue.getSNaN(Sem);
-return DAG.getConstantFP(RealQNaN, DL, VT);
-  }
-  return SDValue();
-}
-
 
//===--===//
 //  Calling Convention Implementation
 
//===--===//
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.h 
b/llvm/lib/Target/Mips/MipsISelLowering.h
index 31ac5d4c185bc..c65c76ccffc75 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.h
+++ b/llvm/lib/Target/Mips/MipsISelLowering.h
@@ -592,7 +592,6 @@ class TargetRegisterClass;
 SDValue lowerEH_DWARF_CFA(SDValue Op, SelectionDAG &DAG) const;
 SDValue lowerFP_TO_SINT(SDValue Op, SelectionDAG &DAG) const;
 SDValue lowerREADCYCLECOUNTER(SDValue Op, SelectionDAG &DAG) const;
-SDValue lowerConstantFP(SDValue Op, SelectionDAG &DAG) const;
 
 /// isEligibleForTailCallOptimization - Check whether the call is eligible
 /// for tail call optimization.
diff --git a/llvm/test/CodeGen/Mips/nan_lowering.ll 
b/llvm/test/CodeGen/Mips/nan_lowering.ll
new file mode 100644
index 0..2a11278e14b6c
--- /dev/null
+++ b/llvm/test/CodeGen/Mips/nan_lowering.ll
@@ -0,0 +1,25 @@
+; RUN: llc -mtriple=mips-linux-gnu -mattr=-nan2008 < %s | FileCheck %s
+; RUN: llc -mtriple=mips-linux-gnu -mattr=+nan2008 < %s | FileCheck %s
+
+; Make sure that lowering does not corrupt the value of NaN values,
+; regardless of what the NaN mode is.
+
+define float @test1() {
+; CHECK: .4byte 0x7fc0
+  ret float bitcast (i32 u0x7fc0 to float)
+}
+
+define float @test2() {
+; CHECK: .4byte 0x7fc1
+  ret float bitcast (i32 u0x7fc1 to float)
+}
+
+define float @test3() {
+; CHECK: .4byte 0x7f80
+  ret float bitcast (i32 u0x7f80 to float)
+}
+
+define float @test4() {
+; CHECK: .4byte 0x7f81
+  ret float bitcast (i32 u0x7f81 to float)
+}
diff --git a/llvm/test/CodeGen/Mips/qnan.ll b/llvm/test/CodeGen/Mips/qnan.ll
deleted file mode 100644
index e5b4aa1b42ee7..0
--- a/llvm/test/CodeGen/Mips/qnan.ll
+++ /dev/null
@@ -1,14 +0,0 @@
-; RUN: llc -O3 -mcpu=mips32r2 -mtriple=mips-linux-gnu < %s -o - | FileCheck %s 
-check-prefix

[llvm-branch-commits] [llvm] release/21.x: [CodeGen] More consistently expand float ops by default (#150597) (PR #150970)

2025-07-28 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/150970

Backport fe0dbe0f2950d95071be7140c7b4680f17a7ac4e

Requested by: @nikic

>From 65b12eadb8130932798c5c3cb0b372945bafba96 Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Mon, 28 Jul 2025 09:46:00 +0200
Subject: [PATCH] [CodeGen] More consistently expand float ops by default
 (#150597)

These float operations were expanded for scalar f32/f64/f128, but not
for f16 and more problematically, not for vectors. A small subset of
them was separately set to expand for vectors.

Change these to always expand by default, and adjust targets to mark
these as legal where necessary instead.

This is a much safer default, and avoids unnecessary legalization
failures because a target failed to manually mark them as expand.

Fixes https://github.com/llvm/llvm-project/issues/110753.
Fixes https://github.com/llvm/llvm-project/issues/121390.

(cherry picked from commit fe0dbe0f2950d95071be7140c7b4680f17a7ac4e)
---
 llvm/lib/CodeGen/TargetLoweringBase.cpp   |  34 +++---
 llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp |  10 +-
 llvm/lib/Target/ARM/ARMISelLowering.cpp   |  11 ++
 .../PowerPC/froundeven-legalization.ll| 111 ++
 4 files changed, 145 insertions(+), 21 deletions(-)
 create mode 100644 llvm/test/CodeGen/PowerPC/froundeven-legalization.ll

diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp 
b/llvm/lib/CodeGen/TargetLoweringBase.cpp
index 6feeb19bb8589..db2065f878727 100644
--- a/llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -806,7 +806,17 @@ void TargetLoweringBase::initActions() {
 ISD::SDIVFIX,ISD::SDIVFIXSAT,
 ISD::UDIVFIX,ISD::UDIVFIXSAT,
 ISD::FP_TO_SINT_SAT, ISD::FP_TO_UINT_SAT,
-ISD::IS_FPCLASS},
+ISD::IS_FPCLASS, ISD::FCBRT,
+ISD::FLOG,   ISD::FLOG2,
+ISD::FLOG10, ISD::FEXP,
+ISD::FEXP2,  ISD::FEXP10,
+ISD::FFLOOR, ISD::FNEARBYINT,
+ISD::FCEIL,  ISD::FRINT,
+ISD::FTRUNC, ISD::FROUNDEVEN,
+ISD::FTAN,   ISD::FACOS,
+ISD::FASIN,  ISD::FATAN,
+ISD::FCOSH,  ISD::FSINH,
+ISD::FTANH,  ISD::FATAN2},
VT, Expand);
 
 // Overflow operations default to expand
@@ -852,13 +862,12 @@ void TargetLoweringBase::initActions() {
 
 // These operations default to expand for vector types.
 if (VT.isVector())
-  setOperationAction(
-  {ISD::FCOPYSIGN, ISD::SIGN_EXTEND_INREG, 
ISD::ANY_EXTEND_VECTOR_INREG,
-   ISD::SIGN_EXTEND_VECTOR_INREG, ISD::ZERO_EXTEND_VECTOR_INREG,
-   ISD::SPLAT_VECTOR, ISD::LRINT, ISD::LLRINT, ISD::LROUND,
-   ISD::LLROUND, ISD::FTAN, ISD::FACOS, ISD::FASIN, ISD::FATAN,
-   ISD::FCOSH, ISD::FSINH, ISD::FTANH, ISD::FATAN2},
-  VT, Expand);
+  setOperationAction({ISD::FCOPYSIGN, ISD::SIGN_EXTEND_INREG,
+  ISD::ANY_EXTEND_VECTOR_INREG,
+  ISD::SIGN_EXTEND_VECTOR_INREG,
+  ISD::ZERO_EXTEND_VECTOR_INREG, ISD::SPLAT_VECTOR,
+  ISD::LRINT, ISD::LLRINT, ISD::LROUND, ISD::LLROUND},
+ VT, Expand);
 
   // Constrained floating-point operations default to expand.
 #define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN)   
\
@@ -914,15 +923,6 @@ void TargetLoweringBase::initActions() {
  {MVT::bf16, MVT::f16, MVT::f32, MVT::f64, MVT::f80, 
MVT::f128},
  Expand);
 
-  // These library functions default to expand.
-  setOperationAction({ISD::FCBRT,  ISD::FLOG,  ISD::FLOG2,  ISD::FLOG10,
-  ISD::FEXP,   ISD::FEXP2, ISD::FEXP10, ISD::FFLOOR,
-  ISD::FNEARBYINT, ISD::FCEIL, ISD::FRINT,  ISD::FTRUNC,
-  ISD::FROUNDEVEN, ISD::FTAN,  ISD::FACOS,  ISD::FASIN,
-  ISD::FATAN,  ISD::FCOSH, ISD::FSINH,  ISD::FTANH,
-  ISD::FATAN2},
- {MVT::f32, MVT::f64, MVT::f128}, Expand);
-
   // Insert custom handling default for llvm.canonicalize.*.
   setOperationAction(ISD::FCANONICALIZE,
  {MVT::f16, MVT::f32, MVT::f64, MVT::f128}, Expand);
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
index 3414fe758eff8..7b93382d1281f 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
@@ -392,8 +392,9 @@ AMDGPUTargetLowering::AMDGPUTargetLowering(const 
TargetMachine &TM,
   // Library functions.  These def

[llvm-branch-commits] [lldb] release/21.x: [lldb] [Windows] Silence format string warnings (#150886) (PR #150919)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru updated https://github.com/llvm/llvm-project/pull/150919

>From 9ffbd30fb68d2b77038c2d0a6a5674340a5492cc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= 
Date: Mon, 28 Jul 2025 12:10:46 +0200
Subject: [PATCH] [lldb] [Windows] Silence format string warnings (#150886)

This fixes the following build warnings in a mingw environment:

../../lldb/source/Host/windows/MainLoopWindows.cpp:226:50: warning:
format specifies type 'int' but the argument has type
'IOObject::WaitableHandle' (aka 'void *') [-Wformat]
226 | "File descriptor %d already monitored.", waitable_handle);
| ~~ ^~~
../../lldb/source/Host/windows/MainLoopWindows.cpp:239:49: warning:
format specifies type 'int' but the argument has type 'DWORD' (aka
'unsigned long') [-Wformat]
238 | error = Status::FromErrorStringWithFormat("Unsupported file type
%d",
| ~~
| %lu
  239 | file_type);
  | ^
2 warnings generated.

(cherry picked from commit 98ec927fcb8697a6f6df64298835917aa1d0d3c1)
---
 lldb/source/Host/windows/MainLoopWindows.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lldb/source/Host/windows/MainLoopWindows.cpp 
b/lldb/source/Host/windows/MainLoopWindows.cpp
index a1de895c0ba98..2de5d3d3e9b63 100644
--- a/lldb/source/Host/windows/MainLoopWindows.cpp
+++ b/lldb/source/Host/windows/MainLoopWindows.cpp
@@ -222,7 +222,7 @@ MainLoopWindows::RegisterReadObject(const IOObjectSP 
&object_sp,
 
   if (m_read_fds.find(waitable_handle) != m_read_fds.end()) {
 error = Status::FromErrorStringWithFormat(
-"File descriptor %d already monitored.", waitable_handle);
+"File descriptor %p already monitored.", waitable_handle);
 return nullptr;
   }
 
@@ -234,7 +234,7 @@ MainLoopWindows::RegisterReadObject(const IOObjectSP 
&object_sp,
   } else {
 DWORD file_type = GetFileType(waitable_handle);
 if (file_type != FILE_TYPE_PIPE) {
-  error = Status::FromErrorStringWithFormat("Unsupported file type %d",
+  error = Status::FromErrorStringWithFormat("Unsupported file type %ld",
 file_type);
   return nullptr;
 }

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [Driver] Default to -mv8plus on 32-bit Solaris/SPARC (#150176) (PR #150898)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru updated https://github.com/llvm/llvm-project/pull/150898

>From 043589c16e39d03279e57f30d764052b76252857 Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Wed, 23 Jul 2025 17:03:34 +0200
Subject: [PATCH] [Driver] Default to -mv8plus on 32-bit Solaris/SPARC
 (#150176)

While investigating PR #149990, I noticed that while both the Oracle
Studio compilers and GCC default to `-mv8plus` on 32-bit Solaris/SPARC,
Clang does not.

This patch fixes this by enabling the `v8plus` feature.

Tested on `sparcv9-sun-solaris2.11` and `sparc64-unknown-linux-gnu`.

(cherry picked from commit 06233892e84f96a3b4e05338cd4f6c12b8f5a185)
---
 clang/lib/Driver/ToolChains/Arch/Sparc.cpp | 13 -
 clang/test/Driver/sparc-target-features.c  |  4 
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp 
b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
index 1351244e1..94a94f1e9c487 100644
--- a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
@@ -37,6 +37,13 @@ const char *sparc::getSparcAsmModeForCPU(StringRef Name,
 .Case("niagara4", "-Av9d")
 .Default(DefV9CPU);
   } else {
+const char *DefV8CPU;
+
+if (Triple.isOSSolaris())
+  DefV8CPU = "-Av8plus";
+else
+  DefV8CPU = "-Av8";
+
 return llvm::StringSwitch(Name)
 .Case("v8", "-Av8")
 .Case("supersparc", "-Av8")
@@ -72,7 +79,7 @@ const char *sparc::getSparcAsmModeForCPU(StringRef Name,
 .Case("gr712rc", "-Aleon")
 .Case("leon4", "-Aleon")
 .Case("gr740", "-Aleon")
-.Default("-Av8");
+.Default(DefV8CPU);
   }
 }
 
@@ -160,6 +167,8 @@ void sparc::getSparcTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
   (Triple.getArch() == llvm::Triple::sparcv9) &&
   (Triple.isOSLinux() || Triple.isOSFreeBSD() || Triple.isOSOpenBSD());
   bool IsSparcV9BTarget = Triple.isOSSolaris();
+  bool IsSparcV8PlusTarget =
+  Triple.getArch() == llvm::Triple::sparc && Triple.isOSSolaris();
   if (Arg *A = Args.getLastArg(options::OPT_mvis, options::OPT_mno_vis)) {
 if (A->getOption().matches(options::OPT_mvis))
   Features.push_back("+vis");
@@ -196,6 +205,8 @@ void sparc::getSparcTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
   if (Arg *A = Args.getLastArg(options::OPT_mv8plus, options::OPT_mno_v8plus)) 
{
 if (A->getOption().matches(options::OPT_mv8plus))
   Features.push_back("+v8plus");
+  } else if (IsSparcV8PlusTarget) {
+Features.push_back("+v8plus");
   }
 
   if (Args.hasArg(options::OPT_ffixed_g1))
diff --git a/clang/test/Driver/sparc-target-features.c 
b/clang/test/Driver/sparc-target-features.c
index 48a180caf259b..bd17da112bbd2 100644
--- a/clang/test/Driver/sparc-target-features.c
+++ b/clang/test/Driver/sparc-target-features.c
@@ -39,4 +39,8 @@
 // SOFT-QUAD-FLOAT: "-target-feature" "-hard-quad-float"
 
 // RUN: %clang --target=sparc -mv8plus %s -### 2>&1 | FileCheck 
-check-prefix=V8PLUS %s
+/// 32-bit Solaris/SPARC defaults to -mv8plus
+// RUN: %clang --target=sparc-sun-solaris2.11 %s -### 2>&1 | FileCheck 
-check-prefix=V8PLUS %s
+// RUN: %clang --target=sparc-sun-solaris2.11 -mno-v8plus %s -### 2>&1 | 
FileCheck -check-prefix=NO-V8PLUS %s
 // V8PLUS: "-target-feature" "+v8plus"
+// NO-V8PLUS-NOT: "-target-feature" "+v8plus"

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/21.x: [CodeGen] More consistently expand float ops by default (#150597) (PR #150970)

2025-07-28 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/150970
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: opencl: Ensure printf symbol is not mangled. (#150210) (PR #150960)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru updated https://github.com/llvm/llvm-project/pull/150960

>From f40dea1d635f757d4791c649e94cb18d748837b9 Mon Sep 17 00:00:00 2001
From: Felix Weiglhofer <9267733+fw...@users.noreply.github.com>
Date: Mon, 28 Jul 2025 16:24:54 +0200
Subject: [PATCH] opencl: Ensure printf symbol is not mangled. (#150210)

Fixes #122453.

(cherry picked from commit a22d010002baf761f84d0a8fa5fcaaf6f3b1455f)
---
 clang/lib/Headers/opencl-c-base.h | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index 2b7f5043e09e4..6206a347852be 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -697,7 +697,16 @@ template  struct 
__remove_address_space<__constant _Tp> {
 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
 // OpenCL v1.2 s6.12.13, v2.0 s6.13.13 - printf
 
-int printf(__constant const char* st, ...) __attribute__((format(printf, 1, 
2)));
+#ifdef __OPENCL_CPP_VERSION__
+#define CLINKAGE extern "C"
+#else
+#define CLINKAGE
+#endif
+
+CLINKAGE int printf(__constant const char *st, ...)
+__attribute__((format(printf, 1, 2)));
+
+#undef CLINKAGE
 #endif
 
 #ifdef cl_intel_device_side_avc_motion_estimation

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/21.x: [CodeGen] More consistently expand float ops by default (#150597) (PR #150970)

2025-07-28 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-arm

Author: None (llvmbot)


Changes

Backport fe0dbe0f2950d95071be7140c7b4680f17a7ac4e

Requested by: @nikic

---
Full diff: https://github.com/llvm/llvm-project/pull/150970.diff


4 Files Affected:

- (modified) llvm/lib/CodeGen/TargetLoweringBase.cpp (+17-17) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp (+6-4) 
- (modified) llvm/lib/Target/ARM/ARMISelLowering.cpp (+11) 
- (added) llvm/test/CodeGen/PowerPC/froundeven-legalization.ll (+111) 


``diff
diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp 
b/llvm/lib/CodeGen/TargetLoweringBase.cpp
index 6feeb19bb8589..db2065f878727 100644
--- a/llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -806,7 +806,17 @@ void TargetLoweringBase::initActions() {
 ISD::SDIVFIX,ISD::SDIVFIXSAT,
 ISD::UDIVFIX,ISD::UDIVFIXSAT,
 ISD::FP_TO_SINT_SAT, ISD::FP_TO_UINT_SAT,
-ISD::IS_FPCLASS},
+ISD::IS_FPCLASS, ISD::FCBRT,
+ISD::FLOG,   ISD::FLOG2,
+ISD::FLOG10, ISD::FEXP,
+ISD::FEXP2,  ISD::FEXP10,
+ISD::FFLOOR, ISD::FNEARBYINT,
+ISD::FCEIL,  ISD::FRINT,
+ISD::FTRUNC, ISD::FROUNDEVEN,
+ISD::FTAN,   ISD::FACOS,
+ISD::FASIN,  ISD::FATAN,
+ISD::FCOSH,  ISD::FSINH,
+ISD::FTANH,  ISD::FATAN2},
VT, Expand);
 
 // Overflow operations default to expand
@@ -852,13 +862,12 @@ void TargetLoweringBase::initActions() {
 
 // These operations default to expand for vector types.
 if (VT.isVector())
-  setOperationAction(
-  {ISD::FCOPYSIGN, ISD::SIGN_EXTEND_INREG, 
ISD::ANY_EXTEND_VECTOR_INREG,
-   ISD::SIGN_EXTEND_VECTOR_INREG, ISD::ZERO_EXTEND_VECTOR_INREG,
-   ISD::SPLAT_VECTOR, ISD::LRINT, ISD::LLRINT, ISD::LROUND,
-   ISD::LLROUND, ISD::FTAN, ISD::FACOS, ISD::FASIN, ISD::FATAN,
-   ISD::FCOSH, ISD::FSINH, ISD::FTANH, ISD::FATAN2},
-  VT, Expand);
+  setOperationAction({ISD::FCOPYSIGN, ISD::SIGN_EXTEND_INREG,
+  ISD::ANY_EXTEND_VECTOR_INREG,
+  ISD::SIGN_EXTEND_VECTOR_INREG,
+  ISD::ZERO_EXTEND_VECTOR_INREG, ISD::SPLAT_VECTOR,
+  ISD::LRINT, ISD::LLRINT, ISD::LROUND, ISD::LLROUND},
+ VT, Expand);
 
   // Constrained floating-point operations default to expand.
 #define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN)   
\
@@ -914,15 +923,6 @@ void TargetLoweringBase::initActions() {
  {MVT::bf16, MVT::f16, MVT::f32, MVT::f64, MVT::f80, 
MVT::f128},
  Expand);
 
-  // These library functions default to expand.
-  setOperationAction({ISD::FCBRT,  ISD::FLOG,  ISD::FLOG2,  ISD::FLOG10,
-  ISD::FEXP,   ISD::FEXP2, ISD::FEXP10, ISD::FFLOOR,
-  ISD::FNEARBYINT, ISD::FCEIL, ISD::FRINT,  ISD::FTRUNC,
-  ISD::FROUNDEVEN, ISD::FTAN,  ISD::FACOS,  ISD::FASIN,
-  ISD::FATAN,  ISD::FCOSH, ISD::FSINH,  ISD::FTANH,
-  ISD::FATAN2},
- {MVT::f32, MVT::f64, MVT::f128}, Expand);
-
   // Insert custom handling default for llvm.canonicalize.*.
   setOperationAction(ISD::FCANONICALIZE,
  {MVT::f16, MVT::f32, MVT::f64, MVT::f128}, Expand);
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
index 3414fe758eff8..7b93382d1281f 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
@@ -392,8 +392,9 @@ AMDGPUTargetLowering::AMDGPUTargetLowering(const 
TargetMachine &TM,
   // Library functions.  These default to Expand, but we have instructions
   // for them.
   setOperationAction({ISD::FCEIL, ISD::FPOW, ISD::FABS, ISD::FFLOOR,
-  ISD::FROUNDEVEN, ISD::FTRUNC, ISD::FMINNUM, 
ISD::FMAXNUM},
- MVT::f32, Legal);
+  ISD::FROUNDEVEN, ISD::FTRUNC},
+ {MVT::f16, MVT::f32}, Legal);
+  setOperationAction({ISD::FMINNUM, ISD::FMAXNUM}, MVT::f32, Legal);
 
   setOperationAction(ISD::FLOG2, MVT::f32, Custom);
   setOperationAction(ISD::FROUND, {MVT::f32, MVT::f64}, Custom);
@@ -413,9 +414,10 @@ AMDGPUTargetLowering::AMDGPUTargetLowering(const 
TargetMachine &TM,
 
   setOperationAction(ISD::FREM, {MVT::f16, MVT::f32, MVT::f64}, Custom);
 
-  if (Subtarget->has16BitInsts())
+  if (Subtarget->has16BitInsts()) {
 setOperationAction(ISD::IS_FPCLASS, {MVT::f16

[llvm-branch-commits] [clang] release/21.x: [[gnu::nonstring]] should work on pointers too (#150974) (PR #150980)

2025-07-28 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/150980

Backport 837b2d464ff16fe0d892dcf2827747c97dd5465e

Requested by: @AaronBallman

>From 197fbd01a89825c9bf80a2e174406fcb8e0cba71 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Mon, 28 Jul 2025 11:53:33 -0400
Subject: [PATCH] [[gnu::nonstring]] should work on pointers too (#150974)

Clang's current implementation only works on array types, but GCC (which
is where we got this attribute) supports it on pointers as well as
arrays.

Fixes #150951

(cherry picked from commit 837b2d464ff16fe0d892dcf2827747c97dd5465e)
---
 clang/include/clang/Basic/AttrDocs.td | 6 +++---
 clang/lib/Sema/SemaDeclAttr.cpp   | 6 +++---
 clang/test/Sema/attr-nonstring.c  | 8 
 3 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index fefdaba7f8bf5..76747d2b11811 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -9417,9 +9417,9 @@ def NonStringDocs : Documentation {
   let Category = DocCatDecl;
   let Content = [{
 The ``nonstring`` attribute can be applied to the declaration of a variable or
-a field whose type is a character array to specify that the character array is
-not intended to behave like a null-terminated string. This will silence
-diagnostics with code like:
+a field whose type is a character pointer or character array to specify that
+the buffer is not intended to behave like a null-terminated string. This will
+silence diagnostics with code like:
 
 .. code-block:: c
 
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 5f481ed1f7139..eff5f9568236a 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5011,10 +5011,10 @@ void Sema::AddModeAttr(Decl *D, const 
AttributeCommonInfo &CI,
 
 static void handleNonStringAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   // This only applies to fields and variable declarations which have an array
-  // type.
+  // type or pointer type, with character elements.
   QualType QT = cast(D)->getType();
-  if (!QT->isArrayType() ||
-  !QT->getBaseElementTypeUnsafe()->isAnyCharacterType()) {
+  if ((!QT->isArrayType() && !QT->isPointerType()) ||
+  !QT->getPointeeOrArrayElementType()->isAnyCharacterType()) {
 S.Diag(D->getBeginLoc(), diag::warn_attribute_non_character_array)
 << AL << AL.isRegularKeywordAttribute() << QT << AL.getRange();
 return;
diff --git a/clang/test/Sema/attr-nonstring.c b/clang/test/Sema/attr-nonstring.c
index 3838aa3bbee15..fe7b6d259dd79 100644
--- a/clang/test/Sema/attr-nonstring.c
+++ b/clang/test/Sema/attr-nonstring.c
@@ -229,3 +229,11 @@ struct Outer o2[] = {
 }
   }
 };
+
+// The attribute also works with a pointer type, not just an array type.
+__attribute__((nonstring)) char *ptr1;
+__attribute__((nonstring)) const unsigned char *ptr2;
+struct GH150951 {
+  __attribute__((nonstring)) char *ptr1;
+  __attribute__((nonstring)) const unsigned char *ptr2;
+};

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [[gnu::nonstring]] should work on pointers too (#150974) (PR #150980)

2025-07-28 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/150980
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [[gnu::nonstring]] should work on pointers too (#150974) (PR #150980)

2025-07-28 Thread via llvm-branch-commits

llvmbot wrote:

@erichkeane What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/150980
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [[gnu::nonstring]] should work on pointers too (#150974) (PR #150980)

2025-07-28 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (llvmbot)


Changes

Backport 837b2d464ff16fe0d892dcf2827747c97dd5465e

Requested by: @AaronBallman

---
Full diff: https://github.com/llvm/llvm-project/pull/150980.diff


3 Files Affected:

- (modified) clang/include/clang/Basic/AttrDocs.td (+3-3) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+3-3) 
- (modified) clang/test/Sema/attr-nonstring.c (+8) 


``diff
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index fefdaba7f8bf5..76747d2b11811 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -9417,9 +9417,9 @@ def NonStringDocs : Documentation {
   let Category = DocCatDecl;
   let Content = [{
 The ``nonstring`` attribute can be applied to the declaration of a variable or
-a field whose type is a character array to specify that the character array is
-not intended to behave like a null-terminated string. This will silence
-diagnostics with code like:
+a field whose type is a character pointer or character array to specify that
+the buffer is not intended to behave like a null-terminated string. This will
+silence diagnostics with code like:
 
 .. code-block:: c
 
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 5f481ed1f7139..eff5f9568236a 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5011,10 +5011,10 @@ void Sema::AddModeAttr(Decl *D, const 
AttributeCommonInfo &CI,
 
 static void handleNonStringAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   // This only applies to fields and variable declarations which have an array
-  // type.
+  // type or pointer type, with character elements.
   QualType QT = cast(D)->getType();
-  if (!QT->isArrayType() ||
-  !QT->getBaseElementTypeUnsafe()->isAnyCharacterType()) {
+  if ((!QT->isArrayType() && !QT->isPointerType()) ||
+  !QT->getPointeeOrArrayElementType()->isAnyCharacterType()) {
 S.Diag(D->getBeginLoc(), diag::warn_attribute_non_character_array)
 << AL << AL.isRegularKeywordAttribute() << QT << AL.getRange();
 return;
diff --git a/clang/test/Sema/attr-nonstring.c b/clang/test/Sema/attr-nonstring.c
index 3838aa3bbee15..fe7b6d259dd79 100644
--- a/clang/test/Sema/attr-nonstring.c
+++ b/clang/test/Sema/attr-nonstring.c
@@ -229,3 +229,11 @@ struct Outer o2[] = {
 }
   }
 };
+
+// The attribute also works with a pointer type, not just an array type.
+__attribute__((nonstring)) char *ptr1;
+__attribute__((nonstring)) const unsigned char *ptr2;
+struct GH150951 {
+  __attribute__((nonstring)) char *ptr1;
+  __attribute__((nonstring)) const unsigned char *ptr2;
+};

``




https://github.com/llvm/llvm-project/pull/150980
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [clang] Fix const eval of constexpr-unknown relational comparisons. (#150088) (PR #150981)

2025-07-28 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (llvmbot)


Changes

Backport bba846773c7dfce0f95b8846672d8dd5fa8912be

Requested by: @efriedma-quic

---
Full diff: https://github.com/llvm/llvm-project/pull/150981.diff


2 Files Affected:

- (modified) clang/lib/AST/ExprConstant.cpp (+4-2) 
- (modified) clang/test/SemaCXX/constant-expression-p2280r4.cpp (+14) 


``diff
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index d7b1173283c57..0733f8e8a33b0 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -14566,7 +14566,9 @@ EvaluateComparisonBinaryOperator(EvalInfo &Info, const 
BinaryOperator *E,
 if (!LHSDesignator.Invalid && !RHSDesignator.Invalid && IsRelational) {
   bool WasArrayIndex;
   unsigned Mismatch = FindDesignatorMismatch(
-  getType(LHSValue.Base), LHSDesignator, RHSDesignator, WasArrayIndex);
+  LHSValue.Base.isNull() ? QualType()
+ : 
getType(LHSValue.Base).getNonReferenceType(),
+  LHSDesignator, RHSDesignator, WasArrayIndex);
   // At the point where the designators diverge, the comparison has a
   // specified value if:
   //  - we are comparing array indices
@@ -14610,7 +14612,7 @@ EvaluateComparisonBinaryOperator(EvalInfo &Info, const 
BinaryOperator *E,
 // compare pointers within the object in question; otherwise, the result
 // depends on where the object is located in memory.
 if (!LHSValue.Base.isNull() && IsRelational) {
-  QualType BaseTy = getType(LHSValue.Base);
+  QualType BaseTy = getType(LHSValue.Base).getNonReferenceType();
   if (BaseTy->isIncompleteType())
 return Error(E);
   CharUnits Size = Info.Ctx.getTypeSizeInChars(BaseTy);
diff --git a/clang/test/SemaCXX/constant-expression-p2280r4.cpp 
b/clang/test/SemaCXX/constant-expression-p2280r4.cpp
index 16f5f823d26c1..312a77830420b 100644
--- a/clang/test/SemaCXX/constant-expression-p2280r4.cpp
+++ b/clang/test/SemaCXX/constant-expression-p2280r4.cpp
@@ -383,3 +383,17 @@ namespace enable_if_2 {
   }
 }
 }
+
+namespace GH150015 {
+  extern int (& c)[8]; // interpreter-note {{declared here}}
+  constexpr int x = c <= c+8; // interpreter-error {{constexpr variable 'x' 
must be initialized by a constant expression}} \
+  // interpreter-note {{initializer of 'c' is 
unknown}}
+
+  struct X {};
+  struct Y {};
+  struct Z : X, Y {};
+  extern Z &z; // interpreter-note{{declared here}}
+  constexpr int bases = (void*)(X*)&z <= (Y*)&z; // expected-error {{constexpr 
variable 'bases' must be initialized by a constant expression}} \
+ // nointerpreter-note 
{{comparison of addresses of subobjects of different base classes has 
unspecified value}} \
+ // interpreter-note 
{{initializer of 'z' is unknown}}
+}

``




https://github.com/llvm/llvm-project/pull/150981
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [clang] Fix const eval of constexpr-unknown relational comparisons. (#150088) (PR #150981)

2025-07-28 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/150981

Backport bba846773c7dfce0f95b8846672d8dd5fa8912be

Requested by: @efriedma-quic

>From c9d5e3b903d7eac067490a5455cb74afb6066b3f Mon Sep 17 00:00:00 2001
From: Eli Friedman 
Date: Thu, 24 Jul 2025 13:36:54 -0700
Subject: [PATCH] [clang] Fix const eval of constexpr-unknown relational
 comparisons. (#150088)

Like in other places, ignore the reference type of the base. (It might
make sense to refactor this at some point.)

Fixes #150015.

(cherry picked from commit bba846773c7dfce0f95b8846672d8dd5fa8912be)
---
 clang/lib/AST/ExprConstant.cpp |  6 --
 clang/test/SemaCXX/constant-expression-p2280r4.cpp | 14 ++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index d7b1173283c57..0733f8e8a33b0 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -14566,7 +14566,9 @@ EvaluateComparisonBinaryOperator(EvalInfo &Info, const 
BinaryOperator *E,
 if (!LHSDesignator.Invalid && !RHSDesignator.Invalid && IsRelational) {
   bool WasArrayIndex;
   unsigned Mismatch = FindDesignatorMismatch(
-  getType(LHSValue.Base), LHSDesignator, RHSDesignator, WasArrayIndex);
+  LHSValue.Base.isNull() ? QualType()
+ : 
getType(LHSValue.Base).getNonReferenceType(),
+  LHSDesignator, RHSDesignator, WasArrayIndex);
   // At the point where the designators diverge, the comparison has a
   // specified value if:
   //  - we are comparing array indices
@@ -14610,7 +14612,7 @@ EvaluateComparisonBinaryOperator(EvalInfo &Info, const 
BinaryOperator *E,
 // compare pointers within the object in question; otherwise, the result
 // depends on where the object is located in memory.
 if (!LHSValue.Base.isNull() && IsRelational) {
-  QualType BaseTy = getType(LHSValue.Base);
+  QualType BaseTy = getType(LHSValue.Base).getNonReferenceType();
   if (BaseTy->isIncompleteType())
 return Error(E);
   CharUnits Size = Info.Ctx.getTypeSizeInChars(BaseTy);
diff --git a/clang/test/SemaCXX/constant-expression-p2280r4.cpp 
b/clang/test/SemaCXX/constant-expression-p2280r4.cpp
index 16f5f823d26c1..312a77830420b 100644
--- a/clang/test/SemaCXX/constant-expression-p2280r4.cpp
+++ b/clang/test/SemaCXX/constant-expression-p2280r4.cpp
@@ -383,3 +383,17 @@ namespace enable_if_2 {
   }
 }
 }
+
+namespace GH150015 {
+  extern int (& c)[8]; // interpreter-note {{declared here}}
+  constexpr int x = c <= c+8; // interpreter-error {{constexpr variable 'x' 
must be initialized by a constant expression}} \
+  // interpreter-note {{initializer of 'c' is 
unknown}}
+
+  struct X {};
+  struct Y {};
+  struct Z : X, Y {};
+  extern Z &z; // interpreter-note{{declared here}}
+  constexpr int bases = (void*)(X*)&z <= (Y*)&z; // expected-error {{constexpr 
variable 'bases' must be initialized by a constant expression}} \
+ // nointerpreter-note 
{{comparison of addresses of subobjects of different base classes has 
unspecified value}} \
+ // interpreter-note 
{{initializer of 'z' is unknown}}
+}

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [clang] Fix const eval of constexpr-unknown relational comparisons. (#150088) (PR #150981)

2025-07-28 Thread via llvm-branch-commits

llvmbot wrote:

@efriedma-quic What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/150981
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [clang] Fix const eval of constexpr-unknown relational comparisons. (#150088) (PR #150981)

2025-07-28 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/150981
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [clang] Fix const eval of constexpr-unknown relational comparisons. (#150088) (PR #150981)

2025-07-28 Thread Corentin Jabot via llvm-branch-commits

https://github.com/cor3ntin approved this pull request.


https://github.com/llvm/llvm-project/pull/150981
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atan2 implementation to header-only in src/__support/math folder. (PR #150968)

2025-07-28 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-libc

Author: Muhammad Bassiouni (bassiounix)


Changes

Part of #147386

in preparation for: 
https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450

---

Patch is 22.56 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/150968.diff


9 Files Affected:

- (modified) libc/shared/math.h (+1) 
- (added) libc/shared/math/atan2.h (+23) 
- (modified) libc/src/__support/math/CMakeLists.txt (+17-3) 
- (added) libc/src/__support/math/atan2.h (+209) 
- (modified) libc/src/math/generic/CMakeLists.txt (+1-7) 
- (modified) libc/src/math/generic/atan2.cpp (+2-185) 
- (modified) libc/test/shared/CMakeLists.txt (+1) 
- (modified) libc/test/shared/shared_math_test.cpp (+1) 
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+11-3) 


``diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index bcbe0de56170a..0605d918eb2af 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -23,6 +23,7 @@
 #include "math/asinhf.h"
 #include "math/asinhf16.h"
 #include "math/atan.h"
+#include "math/atan2.h"
 #include "math/atanf.h"
 #include "math/atanf16.h"
 #include "math/erff.h"
diff --git a/libc/shared/math/atan2.h b/libc/shared/math/atan2.h
new file mode 100644
index 0..894110838817c
--- /dev/null
+++ b/libc/shared/math/atan2.h
@@ -0,0 +1,23 @@
+//===-- Shared atan2 function ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_ATAN2_H
+#define LLVM_LIBC_SHARED_MATH_ATAN2_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/atan2.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::atan2;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ATAN2_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index 04cbd3fd1cc01..bbb07b62552f6 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -158,7 +158,7 @@ add_header_library(
   asinhf16
   HDRS
 asinhf16.h
-DEPENDS
+  DEPENDS
 .acoshf_utils
 libc.src.__support.FPUtil.fenv_impl
 libc.src.__support.FPUtil.fp_bits
@@ -176,7 +176,7 @@ add_header_library(
   atan_utils
   HDRS
 atan_utils.h
-DEPENDS
+  DEPENDS
 libc.src.__support.integer_literals
 libc.src.__support.FPUtil.double_double
 libc.src.__support.FPUtil.dyadic_float
@@ -189,7 +189,21 @@ add_header_library(
   atan
   HDRS
 atan.h
-DEPENDS
+  DEPENDS
+.atan_utils
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.macros.optimization
+)
+
+add_header_library(
+  atan2
+  HDRS
+atan2.h
+  DEPENDS
 .atan_utils
 libc.src.__support.FPUtil.double_double
 libc.src.__support.FPUtil.fenv_impl
diff --git a/libc/src/__support/math/atan2.h b/libc/src/__support/math/atan2.h
new file mode 100644
index 0..90ed926c8d75f
--- /dev/null
+++ b/libc/src/__support/math/atan2.h
@@ -0,0 +1,209 @@
+//===-- Implementation header for atan2 -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ATAN2_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ATAN2_H
+
+#include "atan_utils.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/double_double.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/nearest_integer.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+// There are several range reduction steps we can take for atan2(y, x) as
+// follow:
+
+// * Range reduction 1: signness
+// atan2(y, x) will return a number between -PI and PI representing the angle
+// forming by the 0x axis and the vector (x, y) on the 0xy-plane.
+// In particular, we have that:
+//   atan2(y, x) = atan( y/x ) if x >= 0 and y >= 0 (I-quadrant)
+//   = pi + atan( y/x )if x < 0 and y >= 0  (II-quadrant)
+//   = -pi + atan( y/x )   if x < 0 and y < 0   (III-quadrant)
+//   = ata

[llvm-branch-commits] [clang] release/21.x: opencl: Ensure printf symbol is not mangled. (#150210) (PR #150960)

2025-07-28 Thread Sven van Haastregt via llvm-branch-commits

https://github.com/svenvh approved this pull request.


https://github.com/llvm/llvm-project/pull/150960
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: opencl: Ensure printf symbol is not mangled. (#150210) (PR #150960)

2025-07-28 Thread via llvm-branch-commits

llvmbot wrote:

@svenvh What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/150960
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: opencl: Ensure printf symbol is not mangled. (#150210) (PR #150960)

2025-07-28 Thread via llvm-branch-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-x86

@llvm/pr-subscribers-clang

Author: None (llvmbot)


Changes

Backport a22d010002baf761f84d0a8fa5fcaaf6f3b1455f

Requested by: @svenvh

---
Full diff: https://github.com/llvm/llvm-project/pull/150960.diff


1 Files Affected:

- (modified) clang/lib/Headers/opencl-c-base.h (+10-1) 


``diff
diff --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index 2b7f5043e09e4..6206a347852be 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -697,7 +697,16 @@ template  struct 
__remove_address_space<__constant _Tp> {
 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
 // OpenCL v1.2 s6.12.13, v2.0 s6.13.13 - printf
 
-int printf(__constant const char* st, ...) __attribute__((format(printf, 1, 
2)));
+#ifdef __OPENCL_CPP_VERSION__
+#define CLINKAGE extern "C"
+#else
+#define CLINKAGE
+#endif
+
+CLINKAGE int printf(__constant const char *st, ...)
+__attribute__((format(printf, 1, 2)));
+
+#undef CLINKAGE
 #endif
 
 #ifdef cl_intel_device_side_avc_motion_estimation

``




https://github.com/llvm/llvm-project/pull/150960
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: opencl: Ensure printf symbol is not mangled. (#150210) (PR #150960)

2025-07-28 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/150960

Backport a22d010002baf761f84d0a8fa5fcaaf6f3b1455f

Requested by: @svenvh

>From fc660972ea35ed452ab53001bd08b96ea8680494 Mon Sep 17 00:00:00 2001
From: Felix Weiglhofer <9267733+fw...@users.noreply.github.com>
Date: Mon, 28 Jul 2025 16:24:54 +0200
Subject: [PATCH] opencl: Ensure printf symbol is not mangled. (#150210)

Fixes #122453.

(cherry picked from commit a22d010002baf761f84d0a8fa5fcaaf6f3b1455f)
---
 clang/lib/Headers/opencl-c-base.h | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index 2b7f5043e09e4..6206a347852be 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -697,7 +697,16 @@ template  struct 
__remove_address_space<__constant _Tp> {
 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
 // OpenCL v1.2 s6.12.13, v2.0 s6.13.13 - printf
 
-int printf(__constant const char* st, ...) __attribute__((format(printf, 1, 
2)));
+#ifdef __OPENCL_CPP_VERSION__
+#define CLINKAGE extern "C"
+#else
+#define CLINKAGE
+#endif
+
+CLINKAGE int printf(__constant const char *st, ...)
+__attribute__((format(printf, 1, 2)));
+
+#undef CLINKAGE
 #endif
 
 #ifdef cl_intel_device_side_avc_motion_estimation

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: opencl: Ensure printf symbol is not mangled. (#150210) (PR #150960)

2025-07-28 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/150960
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atan2 implementation to header-only in src/__support/math folder. (PR #150968)

2025-07-28 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix created 
https://github.com/llvm/llvm-project/pull/150968

Part of #147386

in preparation for: 
https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450

>From e6225547a4677563cd334a186fe01db4a5c4c9bc Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Mon, 28 Jul 2025 18:07:19 +0300
Subject: [PATCH] [libc][math] Refactor atan2 implementation to header-only in
 src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/atan2.h  |  23 ++
 libc/src/__support/math/CMakeLists.txt|  20 +-
 libc/src/__support/math/atan2.h   | 209 ++
 libc/src/math/generic/CMakeLists.txt  |   8 +-
 libc/src/math/generic/atan2.cpp   | 187 +---
 libc/test/shared/CMakeLists.txt   |   1 +
 libc/test/shared/shared_math_test.cpp |   1 +
 .../llvm-project-overlay/libc/BUILD.bazel |  14 +-
 9 files changed, 266 insertions(+), 198 deletions(-)
 create mode 100644 libc/shared/math/atan2.h
 create mode 100644 libc/src/__support/math/atan2.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index bcbe0de56170a..0605d918eb2af 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -23,6 +23,7 @@
 #include "math/asinhf.h"
 #include "math/asinhf16.h"
 #include "math/atan.h"
+#include "math/atan2.h"
 #include "math/atanf.h"
 #include "math/atanf16.h"
 #include "math/erff.h"
diff --git a/libc/shared/math/atan2.h b/libc/shared/math/atan2.h
new file mode 100644
index 0..894110838817c
--- /dev/null
+++ b/libc/shared/math/atan2.h
@@ -0,0 +1,23 @@
+//===-- Shared atan2 function ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_ATAN2_H
+#define LLVM_LIBC_SHARED_MATH_ATAN2_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/atan2.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::atan2;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ATAN2_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index 04cbd3fd1cc01..bbb07b62552f6 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -158,7 +158,7 @@ add_header_library(
   asinhf16
   HDRS
 asinhf16.h
-DEPENDS
+  DEPENDS
 .acoshf_utils
 libc.src.__support.FPUtil.fenv_impl
 libc.src.__support.FPUtil.fp_bits
@@ -176,7 +176,7 @@ add_header_library(
   atan_utils
   HDRS
 atan_utils.h
-DEPENDS
+  DEPENDS
 libc.src.__support.integer_literals
 libc.src.__support.FPUtil.double_double
 libc.src.__support.FPUtil.dyadic_float
@@ -189,7 +189,21 @@ add_header_library(
   atan
   HDRS
 atan.h
-DEPENDS
+  DEPENDS
+.atan_utils
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.macros.optimization
+)
+
+add_header_library(
+  atan2
+  HDRS
+atan2.h
+  DEPENDS
 .atan_utils
 libc.src.__support.FPUtil.double_double
 libc.src.__support.FPUtil.fenv_impl
diff --git a/libc/src/__support/math/atan2.h b/libc/src/__support/math/atan2.h
new file mode 100644
index 0..90ed926c8d75f
--- /dev/null
+++ b/libc/src/__support/math/atan2.h
@@ -0,0 +1,209 @@
+//===-- Implementation header for atan2 -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ATAN2_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ATAN2_H
+
+#include "atan_utils.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/double_double.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/nearest_integer.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+// There are several range reduction steps we can take for atan2(y, x) as
+// follow:
+
+// * Range reduction 1: signness
+// atan2(y, x) will return a number between -PI and PI representing the angle
+// forming by the 0x axis and the vector (x, y) on the 0xy-plane.
+// In partic

[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atan2 implementation to header-only in src/__support/math folder. (PR #150968)

2025-07-28 Thread Muhammad Bassiouni via llvm-branch-commits

bassiounix wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/150968?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#150968** https://app.graphite.dev/github/pr/llvm/llvm-project/150968?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/150968?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#150868** https://app.graphite.dev/github/pr/llvm/llvm-project/150868?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#150854** https://app.graphite.dev/github/pr/llvm/llvm-project/150854?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#150852** https://app.graphite.dev/github/pr/llvm/llvm-project/150852?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#150849** https://app.graphite.dev/github/pr/llvm/llvm-project/150849?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#150843** https://app.graphite.dev/github/pr/llvm/llvm-project/150843?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


https://github.com/llvm/llvm-project/pull/150968
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/21.x: [CodeGen] More consistently expand float ops by default (#150597) (PR #150970)

2025-07-28 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm approved this pull request.


https://github.com/llvm/llvm-project/pull/150970
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atanf implementation to header-only in src/__support/math folder. (PR #150854)

2025-07-28 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix updated 
https://github.com/llvm/llvm-project/pull/150854

>From 9cac4fc9c88100b253c67ada7767a5dba9c4c917 Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Mon, 28 Jul 2025 00:37:42 +0300
Subject: [PATCH] [libc][math] Refactor atanf implementation to header-only in
 src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/atanf.h  |  23 
 libc/src/__support/math/CMakeLists.txt|  15 ++
 libc/src/__support/math/atanf.h   | 129 ++
 libc/src/math/generic/CMakeLists.txt  |   9 +-
 libc/src/math/generic/atanf.cpp   | 110 +--
 libc/test/shared/CMakeLists.txt   |   1 +
 libc/test/shared/shared_math_test.cpp |   1 +
 .../llvm-project-overlay/libc/BUILD.bazel |  22 ++-
 9 files changed, 188 insertions(+), 123 deletions(-)
 create mode 100644 libc/shared/math/atanf.h
 create mode 100644 libc/src/__support/math/atanf.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index 70b1b7b0bef09..21536647948f4 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -23,6 +23,7 @@
 #include "math/asinhf.h"
 #include "math/asinhf16.h"
 #include "math/atan.h"
+#include "math/atanf.h"
 #include "math/erff.h"
 #include "math/exp.h"
 #include "math/exp10.h"
diff --git a/libc/shared/math/atanf.h b/libc/shared/math/atanf.h
new file mode 100644
index 0..858d727bd6698
--- /dev/null
+++ b/libc/shared/math/atanf.h
@@ -0,0 +1,23 @@
+//===-- Shared atanf function ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_ATANF_H
+#define LLVM_LIBC_SHARED_MATH_ATANF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/atanf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::atanf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ATANF_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index cc02920c2a1ef..95acc962cc885 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -199,6 +199,21 @@ DEPENDS
 libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  atanf
+  HDRS
+atanf.h
+  DEPENDS
+.inv_trigf_utils
+libc.src.__support.FPUtil.except_value_utils
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.FPUtil.rounding_mode
+libc.src.__support.macros.optimization
+)
+
 add_header_library(
   asinf
   HDRS
diff --git a/libc/src/__support/math/atanf.h b/libc/src/__support/math/atanf.h
new file mode 100644
index 0..92799dc8db3cc
--- /dev/null
+++ b/libc/src/__support/math/atanf.h
@@ -0,0 +1,129 @@
+//===-- Implementation header for atanf -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ATANF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ATANF_H
+
+#include "inv_trigf_utils.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.h"
+#include "src/__support/FPUtil/except_value_utils.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/nearest_integer.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE static constexpr float atanf(float x) {
+  using namespace inv_trigf_utils_internal;
+  using FPBits = typename fputil::FPBits;
+
+  constexpr double FINAL_SIGN[2] = {1.0, -1.0};
+  constexpr double SIGNED_PI_OVER_2[2] = {0x1.921fb54442d18p0,
+  -0x1.921fb54442d18p0};
+
+  FPBits x_bits(x);
+  Sign sign = x_bits.sign();
+  x_bits.set_sign(Sign::POS);
+  uint32_t x_abs = x_bits.uintval();
+
+  // x is inf or nan, |x| < 2^-4 or |x|= > 16.
+  if (LIBC_UNLIKELY(x_abs <= 0x3d80'U || x_abs >= 0x4180'U)) {
+double x_d = static_cast(x);
+double const_term = 0.0;
+if (LIBC_UNLIKELY(x_abs >= 0x4180')) {
+  // atan(+-Inf) = +-pi/2.
+  if (x_bits.is_inf()) {
+volatile double sign_pi_over_2 = SIGNED_PI_OVER_2[sign.is_neg()];
+return static_cast(sign_pi_over_2);
+  }
+  if (x_bits.is_nan())
+ 

[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atanf16 implementation to header-only in src/__support/math folder. (PR #150868)

2025-07-28 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix updated 
https://github.com/llvm/llvm-project/pull/150868

>From 5077f3f8f1c4d3db505f9aa74862607c2e6a32cf Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Mon, 28 Jul 2025 05:26:38 +0300
Subject: [PATCH] [libc][math] Refactor atanf16 implementation to header-only
 in src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/atanf16.h|  28 +
 libc/src/__support/math/CMakeLists.txt|  15 +++
 libc/src/__support/math/atanf16.h | 119 ++
 libc/src/math/generic/CMakeLists.txt  |  12 +-
 libc/src/math/generic/atanf16.cpp |  95 +-
 libc/test/shared/CMakeLists.txt   |   1 +
 libc/test/shared/shared_math_test.cpp |   1 +
 .../llvm-project-overlay/libc/BUILD.bazel |  22 
 9 files changed, 190 insertions(+), 104 deletions(-)
 create mode 100644 libc/shared/math/atanf16.h
 create mode 100644 libc/src/__support/math/atanf16.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index 21536647948f4..bcbe0de56170a 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -24,6 +24,7 @@
 #include "math/asinhf16.h"
 #include "math/atan.h"
 #include "math/atanf.h"
+#include "math/atanf16.h"
 #include "math/erff.h"
 #include "math/exp.h"
 #include "math/exp10.h"
diff --git a/libc/shared/math/atanf16.h b/libc/shared/math/atanf16.h
new file mode 100644
index 0..f196907059e01
--- /dev/null
+++ b/libc/shared/math/atanf16.h
@@ -0,0 +1,28 @@
+//===-- Shared atanf16 function -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_ATANF16_H
+#define LLVM_LIBC_SHARED_MATH_ATANF16_H
+
+#include "shared/libc_common.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/atanf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::atanf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_ATANF16_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index 95acc962cc885..04cbd3fd1cc01 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -214,6 +214,21 @@ add_header_library(
 libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  atanf16
+  HDRS
+atanf16.h
+  DEPENDS
+libc.src.__support.FPUtil.cast
+libc.src.__support.FPUtil.except_value_utils
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.FPUtil.sqrt
+libc.src.__support.macros.optimization
+)
+
 add_header_library(
   asinf
   HDRS
diff --git a/libc/src/__support/math/atanf16.h 
b/libc/src/__support/math/atanf16.h
new file mode 100644
index 0..f75d145f36852
--- /dev/null
+++ b/libc/src/__support/math/atanf16.h
@@ -0,0 +1,119 @@
+//===-- Implementation header for atanf16 ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ATANF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ATANF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.h"
+#include "src/__support/FPUtil/cast.h"
+#include "src/__support/FPUtil/except_value_utils.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/sqrt.h"
+#include "src/__support/macros/optimization.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE static constexpr float16 atanf16(float16 x) {
+  // Generated by Solly using the following command:
+  // > round(pi/2, SG, RN);
+  constexpr float PI_2 = 0x1.921fb6p0;
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+  constexpr size_t N_EXCEPTS = 6;
+
+  constexpr fputil::ExceptValues ATANF16_EXCEPTS{{
+  // (input, RZ output, RU offset, RD offset, RN offset)
+  {0x2745, 0x2744, 1, 0, 1},
+  {0x3099, 0x3090, 1, 0, 1},
+  {0x3c6c, 0x3aae, 1, 0, 1},
+  {0x466e, 0x3daa, 1, 0, 1},
+  {0x48ae, 0x3ddb, 1, 0, 0},
+  {0x5619, 0x3e3d, 1, 0, 1},
+  }};
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+  using FPBits = fputil::FPBits;
+  FPBits xbits(x);
+
+  uint16_t x

[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atan2 implementation to header-only in src/__support/math folder. (PR #150968)

2025-07-28 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix updated 
https://github.com/llvm/llvm-project/pull/150968

>From 079c38ecdd5a66b752a772213f76c2f514ea7fce Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Mon, 28 Jul 2025 18:07:19 +0300
Subject: [PATCH] [libc][math] Refactor atan2 implementation to header-only in
 src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/atan2.h  |  23 ++
 libc/src/__support/math/CMakeLists.txt|  20 +-
 libc/src/__support/math/atan2.h   | 209 ++
 libc/src/math/generic/CMakeLists.txt  |   8 +-
 libc/src/math/generic/atan2.cpp   | 187 +---
 libc/test/shared/CMakeLists.txt   |   1 +
 libc/test/shared/shared_math_test.cpp |   1 +
 .../llvm-project-overlay/libc/BUILD.bazel |  14 +-
 9 files changed, 266 insertions(+), 198 deletions(-)
 create mode 100644 libc/shared/math/atan2.h
 create mode 100644 libc/src/__support/math/atan2.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index bcbe0de56170a..0605d918eb2af 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -23,6 +23,7 @@
 #include "math/asinhf.h"
 #include "math/asinhf16.h"
 #include "math/atan.h"
+#include "math/atan2.h"
 #include "math/atanf.h"
 #include "math/atanf16.h"
 #include "math/erff.h"
diff --git a/libc/shared/math/atan2.h b/libc/shared/math/atan2.h
new file mode 100644
index 0..894110838817c
--- /dev/null
+++ b/libc/shared/math/atan2.h
@@ -0,0 +1,23 @@
+//===-- Shared atan2 function ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_ATAN2_H
+#define LLVM_LIBC_SHARED_MATH_ATAN2_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/atan2.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::atan2;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ATAN2_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index 04cbd3fd1cc01..bbb07b62552f6 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -158,7 +158,7 @@ add_header_library(
   asinhf16
   HDRS
 asinhf16.h
-DEPENDS
+  DEPENDS
 .acoshf_utils
 libc.src.__support.FPUtil.fenv_impl
 libc.src.__support.FPUtil.fp_bits
@@ -176,7 +176,7 @@ add_header_library(
   atan_utils
   HDRS
 atan_utils.h
-DEPENDS
+  DEPENDS
 libc.src.__support.integer_literals
 libc.src.__support.FPUtil.double_double
 libc.src.__support.FPUtil.dyadic_float
@@ -189,7 +189,21 @@ add_header_library(
   atan
   HDRS
 atan.h
-DEPENDS
+  DEPENDS
+.atan_utils
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.macros.optimization
+)
+
+add_header_library(
+  atan2
+  HDRS
+atan2.h
+  DEPENDS
 .atan_utils
 libc.src.__support.FPUtil.double_double
 libc.src.__support.FPUtil.fenv_impl
diff --git a/libc/src/__support/math/atan2.h b/libc/src/__support/math/atan2.h
new file mode 100644
index 0..90ed926c8d75f
--- /dev/null
+++ b/libc/src/__support/math/atan2.h
@@ -0,0 +1,209 @@
+//===-- Implementation header for atan2 -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ATAN2_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ATAN2_H
+
+#include "atan_utils.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/double_double.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/nearest_integer.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+// There are several range reduction steps we can take for atan2(y, x) as
+// follow:
+
+// * Range reduction 1: signness
+// atan2(y, x) will return a number between -PI and PI representing the angle
+// forming by the 0x axis and the vector (x, y) on the 0xy-plane.
+// In particular, we have that:
+//   atan2(y, x) = atan( y/x ) if x >= 0 and y >= 0 (I-quadrant)
+//   = pi + atan( y/x )if x < 0 and y >= 0  (II-quadrant)
+//  

[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atanf implementation to header-only in src/__support/math folder. (PR #150854)

2025-07-28 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix updated 
https://github.com/llvm/llvm-project/pull/150854

>From 9cac4fc9c88100b253c67ada7767a5dba9c4c917 Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Mon, 28 Jul 2025 00:37:42 +0300
Subject: [PATCH] [libc][math] Refactor atanf implementation to header-only in
 src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/atanf.h  |  23 
 libc/src/__support/math/CMakeLists.txt|  15 ++
 libc/src/__support/math/atanf.h   | 129 ++
 libc/src/math/generic/CMakeLists.txt  |   9 +-
 libc/src/math/generic/atanf.cpp   | 110 +--
 libc/test/shared/CMakeLists.txt   |   1 +
 libc/test/shared/shared_math_test.cpp |   1 +
 .../llvm-project-overlay/libc/BUILD.bazel |  22 ++-
 9 files changed, 188 insertions(+), 123 deletions(-)
 create mode 100644 libc/shared/math/atanf.h
 create mode 100644 libc/src/__support/math/atanf.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index 70b1b7b0bef09..21536647948f4 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -23,6 +23,7 @@
 #include "math/asinhf.h"
 #include "math/asinhf16.h"
 #include "math/atan.h"
+#include "math/atanf.h"
 #include "math/erff.h"
 #include "math/exp.h"
 #include "math/exp10.h"
diff --git a/libc/shared/math/atanf.h b/libc/shared/math/atanf.h
new file mode 100644
index 0..858d727bd6698
--- /dev/null
+++ b/libc/shared/math/atanf.h
@@ -0,0 +1,23 @@
+//===-- Shared atanf function ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_ATANF_H
+#define LLVM_LIBC_SHARED_MATH_ATANF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/atanf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::atanf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ATANF_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index cc02920c2a1ef..95acc962cc885 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -199,6 +199,21 @@ DEPENDS
 libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  atanf
+  HDRS
+atanf.h
+  DEPENDS
+.inv_trigf_utils
+libc.src.__support.FPUtil.except_value_utils
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.FPUtil.rounding_mode
+libc.src.__support.macros.optimization
+)
+
 add_header_library(
   asinf
   HDRS
diff --git a/libc/src/__support/math/atanf.h b/libc/src/__support/math/atanf.h
new file mode 100644
index 0..92799dc8db3cc
--- /dev/null
+++ b/libc/src/__support/math/atanf.h
@@ -0,0 +1,129 @@
+//===-- Implementation header for atanf -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ATANF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ATANF_H
+
+#include "inv_trigf_utils.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.h"
+#include "src/__support/FPUtil/except_value_utils.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/nearest_integer.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE static constexpr float atanf(float x) {
+  using namespace inv_trigf_utils_internal;
+  using FPBits = typename fputil::FPBits;
+
+  constexpr double FINAL_SIGN[2] = {1.0, -1.0};
+  constexpr double SIGNED_PI_OVER_2[2] = {0x1.921fb54442d18p0,
+  -0x1.921fb54442d18p0};
+
+  FPBits x_bits(x);
+  Sign sign = x_bits.sign();
+  x_bits.set_sign(Sign::POS);
+  uint32_t x_abs = x_bits.uintval();
+
+  // x is inf or nan, |x| < 2^-4 or |x|= > 16.
+  if (LIBC_UNLIKELY(x_abs <= 0x3d80'U || x_abs >= 0x4180'U)) {
+double x_d = static_cast(x);
+double const_term = 0.0;
+if (LIBC_UNLIKELY(x_abs >= 0x4180')) {
+  // atan(+-Inf) = +-pi/2.
+  if (x_bits.is_inf()) {
+volatile double sign_pi_over_2 = SIGNED_PI_OVER_2[sign.is_neg()];
+return static_cast(sign_pi_over_2);
+  }
+  if (x_bits.is_nan())
+ 

[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atan implementation to header-only in src/__support/math folder. (PR #150852)

2025-07-28 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix updated 
https://github.com/llvm/llvm-project/pull/150852

>From 8c60f834b0fd914b7d35b38ef89b0cd0f46c39e5 Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Sun, 27 Jul 2025 23:44:37 +0300
Subject: [PATCH] [libc][math] Refactor atan implementation to header-only in
 src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/atan.h   |  23 +++
 libc/src/__support/math/CMakeLists.txt|  27 +++
 libc/src/__support/math/atan.h| 189 ++
 .../generic => __support/math}/atan_utils.h   |  16 +-
 libc/src/math/generic/CMakeLists.txt  |  25 +--
 libc/src/math/generic/atan.cpp| 167 +---
 libc/src/math/generic/atan2.cpp   |   3 +-
 libc/src/math/generic/atan2f128.cpp   |   3 +-
 libc/test/shared/CMakeLists.txt   |   1 +
 libc/test/shared/shared_math_test.cpp |   1 +
 .../llvm-project-overlay/libc/BUILD.bazel |  44 ++--
 12 files changed, 286 insertions(+), 214 deletions(-)
 create mode 100644 libc/shared/math/atan.h
 create mode 100644 libc/src/__support/math/atan.h
 rename libc/src/{math/generic => __support/math}/atan_utils.h (96%)

diff --git a/libc/shared/math.h b/libc/shared/math.h
index 26e33ecd45d73..70b1b7b0bef09 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -22,6 +22,7 @@
 #include "math/asinf16.h"
 #include "math/asinhf.h"
 #include "math/asinhf16.h"
+#include "math/atan.h"
 #include "math/erff.h"
 #include "math/exp.h"
 #include "math/exp10.h"
diff --git a/libc/shared/math/atan.h b/libc/shared/math/atan.h
new file mode 100644
index 0..b9ba89b7e6225
--- /dev/null
+++ b/libc/shared/math/atan.h
@@ -0,0 +1,23 @@
+//===-- Shared atan function *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_ATAN_H
+#define LLVM_LIBC_SHARED_MATH_ATAN_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/atan.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::atan;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ATAN_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index be208f946024a..cc02920c2a1ef 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -172,6 +172,33 @@ DEPENDS
 libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  atan_utils
+  HDRS
+atan_utils.h
+DEPENDS
+libc.src.__support.integer_literals
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.macros.optimization
+)
+
+add_header_library(
+  atan
+  HDRS
+atan.h
+DEPENDS
+.atan_utils
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.macros.optimization
+)
+
 add_header_library(
   asinf
   HDRS
diff --git a/libc/src/__support/math/atan.h b/libc/src/__support/math/atan.h
new file mode 100644
index 0..62190b092429a
--- /dev/null
+++ b/libc/src/__support/math/atan.h
@@ -0,0 +1,189 @@
+//===-- Implementation header for atan --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ATAN_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ATAN_H
+
+#include "atan_utils.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/double_double.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/nearest_integer.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+// To compute atan(x), we divided it into the following cases:
+// * |x| < 2^-26:
+//  Since |x| > atan(|x|) > |x| - |x|^3/3, and |x|^3/3 < ulp(x)/2, we 
simply
+//  return atan(x) = x - sign(x) * epsilon.
+// * 2^-26 <= |x| < 1:
+//  We perform range reduction mod 2^-6 = 1/64 as follow:
+//  Let k = 2^(-6) * round(|x| * 2^6), then
+//atan(x) = sign(x) * atan(|x|)
+//

[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atan2f implementation to header-only in src/__support/math folder. (PR #150993)

2025-07-28 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix created 
https://github.com/llvm/llvm-project/pull/150993

Part of #147386

in preparation for: 
https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450

>From 938716d9098a91943153be870a7717e8a358988c Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Mon, 28 Jul 2025 19:35:03 +0300
Subject: [PATCH] [libc][math] Refactor atan2f implementation to header-only in
 src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/atan2f.h |  23 ++
 libc/src/__support/math/CMakeLists.txt|  17 +
 libc/src/__support/math/atan2f.h  | 351 ++
 .../generic => __support/math}/atan2f_float.h |  21 +-
 libc/src/math/generic/CMakeLists.txt  |  12 +-
 libc/src/math/generic/atan2f.cpp  | 328 +---
 libc/test/shared/CMakeLists.txt   |   1 +
 libc/test/shared/shared_math_test.cpp |   1 +
 .../llvm-project-overlay/libc/BUILD.bazel |  20 +-
 10 files changed, 427 insertions(+), 348 deletions(-)
 create mode 100644 libc/shared/math/atan2f.h
 create mode 100644 libc/src/__support/math/atan2f.h
 rename libc/src/{math/generic => __support/math}/atan2f_float.h (95%)

diff --git a/libc/shared/math.h b/libc/shared/math.h
index 0605d918eb2af..527bb8d6214ae 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -24,6 +24,7 @@
 #include "math/asinhf16.h"
 #include "math/atan.h"
 #include "math/atan2.h"
+#include "math/atan2f.h"
 #include "math/atanf.h"
 #include "math/atanf16.h"
 #include "math/erff.h"
diff --git a/libc/shared/math/atan2f.h b/libc/shared/math/atan2f.h
new file mode 100644
index 0..2de09d25e19f8
--- /dev/null
+++ b/libc/shared/math/atan2f.h
@@ -0,0 +1,23 @@
+//===-- Shared atan2f function --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_ATAN2F_H
+#define LLVM_LIBC_SHARED_MATH_ATAN2F_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/atan2f.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::atan2f;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ATAN2F_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index bbb07b62552f6..c197b19ed29de 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -213,6 +213,23 @@ add_header_library(
 libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  atan2f
+  HDRS
+atan2f_float.h
+atan2f.h
+  DEPENDS
+.inv_trigf_utils
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.macros.config
+libc.src.__support.macros.optimization
+)
+
 add_header_library(
   atanf
   HDRS
diff --git a/libc/src/__support/math/atan2f.h b/libc/src/__support/math/atan2f.h
new file mode 100644
index 0..e3b19329126f4
--- /dev/null
+++ b/libc/src/__support/math/atan2f.h
@@ -0,0 +1,351 @@
+//===-- Implementation header for atan2f *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ATAN2F_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ATAN2F_H
+
+#include "inv_trigf_utils.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.h"
+#include "src/__support/FPUtil/double_double.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/nearest_integer.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
+
+#if defined(LIBC_MATH_HAS_SKIP_ACCURATE_PASS) &&   
\
+defined(LIBC_MATH_HAS_INTERMEDIATE_COMP_IN_FLOAT)
+
+// We use float-float implementation to reduce size.
+#include "atan2f_float.h"
+
+#else
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+namespace atan2f_internal {
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+// Look up tables for accurate pass:
+
+// atan(i/16) with i = 0..16, generated by Sollya with:
+// > for i from 0 to 16 do {
+// a = round(atan(i/16), D, RN);
+/

[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atan implementation to header-only in src/__support/math folder. (PR #150852)

2025-07-28 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix updated 
https://github.com/llvm/llvm-project/pull/150852

>From 8c60f834b0fd914b7d35b38ef89b0cd0f46c39e5 Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Sun, 27 Jul 2025 23:44:37 +0300
Subject: [PATCH] [libc][math] Refactor atan implementation to header-only in
 src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/atan.h   |  23 +++
 libc/src/__support/math/CMakeLists.txt|  27 +++
 libc/src/__support/math/atan.h| 189 ++
 .../generic => __support/math}/atan_utils.h   |  16 +-
 libc/src/math/generic/CMakeLists.txt  |  25 +--
 libc/src/math/generic/atan.cpp| 167 +---
 libc/src/math/generic/atan2.cpp   |   3 +-
 libc/src/math/generic/atan2f128.cpp   |   3 +-
 libc/test/shared/CMakeLists.txt   |   1 +
 libc/test/shared/shared_math_test.cpp |   1 +
 .../llvm-project-overlay/libc/BUILD.bazel |  44 ++--
 12 files changed, 286 insertions(+), 214 deletions(-)
 create mode 100644 libc/shared/math/atan.h
 create mode 100644 libc/src/__support/math/atan.h
 rename libc/src/{math/generic => __support/math}/atan_utils.h (96%)

diff --git a/libc/shared/math.h b/libc/shared/math.h
index 26e33ecd45d73..70b1b7b0bef09 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -22,6 +22,7 @@
 #include "math/asinf16.h"
 #include "math/asinhf.h"
 #include "math/asinhf16.h"
+#include "math/atan.h"
 #include "math/erff.h"
 #include "math/exp.h"
 #include "math/exp10.h"
diff --git a/libc/shared/math/atan.h b/libc/shared/math/atan.h
new file mode 100644
index 0..b9ba89b7e6225
--- /dev/null
+++ b/libc/shared/math/atan.h
@@ -0,0 +1,23 @@
+//===-- Shared atan function *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_ATAN_H
+#define LLVM_LIBC_SHARED_MATH_ATAN_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/atan.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::atan;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ATAN_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index be208f946024a..cc02920c2a1ef 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -172,6 +172,33 @@ DEPENDS
 libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  atan_utils
+  HDRS
+atan_utils.h
+DEPENDS
+libc.src.__support.integer_literals
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.dyadic_float
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.macros.optimization
+)
+
+add_header_library(
+  atan
+  HDRS
+atan.h
+DEPENDS
+.atan_utils
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.macros.optimization
+)
+
 add_header_library(
   asinf
   HDRS
diff --git a/libc/src/__support/math/atan.h b/libc/src/__support/math/atan.h
new file mode 100644
index 0..62190b092429a
--- /dev/null
+++ b/libc/src/__support/math/atan.h
@@ -0,0 +1,189 @@
+//===-- Implementation header for atan --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ATAN_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ATAN_H
+
+#include "atan_utils.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/double_double.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/nearest_integer.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+// To compute atan(x), we divided it into the following cases:
+// * |x| < 2^-26:
+//  Since |x| > atan(|x|) > |x| - |x|^3/3, and |x|^3/3 < ulp(x)/2, we 
simply
+//  return atan(x) = x - sign(x) * epsilon.
+// * 2^-26 <= |x| < 1:
+//  We perform range reduction mod 2^-6 = 1/64 as follow:
+//  Let k = 2^(-6) * round(|x| * 2^6), then
+//atan(x) = sign(x) * atan(|x|)
+//

[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atan2f implementation to header-only in src/__support/math folder. (PR #150993)

2025-07-28 Thread Muhammad Bassiouni via llvm-branch-commits

bassiounix wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/150993?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#150993** https://app.graphite.dev/github/pr/llvm/llvm-project/150993?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/150993?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#150968** https://app.graphite.dev/github/pr/llvm/llvm-project/150968?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#150868** https://app.graphite.dev/github/pr/llvm/llvm-project/150868?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#150854** https://app.graphite.dev/github/pr/llvm/llvm-project/150854?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#150852** https://app.graphite.dev/github/pr/llvm/llvm-project/150852?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#150849** https://app.graphite.dev/github/pr/llvm/llvm-project/150849?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#150843** https://app.graphite.dev/github/pr/llvm/llvm-project/150843?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


https://github.com/llvm/llvm-project/pull/150993
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atanf16 implementation to header-only in src/__support/math folder. (PR #150868)

2025-07-28 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix updated 
https://github.com/llvm/llvm-project/pull/150868

>From 5077f3f8f1c4d3db505f9aa74862607c2e6a32cf Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Mon, 28 Jul 2025 05:26:38 +0300
Subject: [PATCH] [libc][math] Refactor atanf16 implementation to header-only
 in src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/atanf16.h|  28 +
 libc/src/__support/math/CMakeLists.txt|  15 +++
 libc/src/__support/math/atanf16.h | 119 ++
 libc/src/math/generic/CMakeLists.txt  |  12 +-
 libc/src/math/generic/atanf16.cpp |  95 +-
 libc/test/shared/CMakeLists.txt   |   1 +
 libc/test/shared/shared_math_test.cpp |   1 +
 .../llvm-project-overlay/libc/BUILD.bazel |  22 
 9 files changed, 190 insertions(+), 104 deletions(-)
 create mode 100644 libc/shared/math/atanf16.h
 create mode 100644 libc/src/__support/math/atanf16.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index 21536647948f4..bcbe0de56170a 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -24,6 +24,7 @@
 #include "math/asinhf16.h"
 #include "math/atan.h"
 #include "math/atanf.h"
+#include "math/atanf16.h"
 #include "math/erff.h"
 #include "math/exp.h"
 #include "math/exp10.h"
diff --git a/libc/shared/math/atanf16.h b/libc/shared/math/atanf16.h
new file mode 100644
index 0..f196907059e01
--- /dev/null
+++ b/libc/shared/math/atanf16.h
@@ -0,0 +1,28 @@
+//===-- Shared atanf16 function -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_ATANF16_H
+#define LLVM_LIBC_SHARED_MATH_ATANF16_H
+
+#include "shared/libc_common.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/atanf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::atanf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_ATANF16_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index 95acc962cc885..04cbd3fd1cc01 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -214,6 +214,21 @@ add_header_library(
 libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  atanf16
+  HDRS
+atanf16.h
+  DEPENDS
+libc.src.__support.FPUtil.cast
+libc.src.__support.FPUtil.except_value_utils
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.FPUtil.sqrt
+libc.src.__support.macros.optimization
+)
+
 add_header_library(
   asinf
   HDRS
diff --git a/libc/src/__support/math/atanf16.h 
b/libc/src/__support/math/atanf16.h
new file mode 100644
index 0..f75d145f36852
--- /dev/null
+++ b/libc/src/__support/math/atanf16.h
@@ -0,0 +1,119 @@
+//===-- Implementation header for atanf16 ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ATANF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ATANF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.h"
+#include "src/__support/FPUtil/cast.h"
+#include "src/__support/FPUtil/except_value_utils.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/sqrt.h"
+#include "src/__support/macros/optimization.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE static constexpr float16 atanf16(float16 x) {
+  // Generated by Solly using the following command:
+  // > round(pi/2, SG, RN);
+  constexpr float PI_2 = 0x1.921fb6p0;
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+  constexpr size_t N_EXCEPTS = 6;
+
+  constexpr fputil::ExceptValues ATANF16_EXCEPTS{{
+  // (input, RZ output, RU offset, RD offset, RN offset)
+  {0x2745, 0x2744, 1, 0, 1},
+  {0x3099, 0x3090, 1, 0, 1},
+  {0x3c6c, 0x3aae, 1, 0, 1},
+  {0x466e, 0x3daa, 1, 0, 1},
+  {0x48ae, 0x3ddb, 1, 0, 0},
+  {0x5619, 0x3e3d, 1, 0, 1},
+  }};
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+  using FPBits = fputil::FPBits;
+  FPBits xbits(x);
+
+  uint16_t x

[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atan2 implementation to header-only in src/__support/math folder. (PR #150968)

2025-07-28 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix updated 
https://github.com/llvm/llvm-project/pull/150968

>From 079c38ecdd5a66b752a772213f76c2f514ea7fce Mon Sep 17 00:00:00 2001
From: bassiounix 
Date: Mon, 28 Jul 2025 18:07:19 +0300
Subject: [PATCH] [libc][math] Refactor atan2 implementation to header-only in
 src/__support/math folder.

---
 libc/shared/math.h|   1 +
 libc/shared/math/atan2.h  |  23 ++
 libc/src/__support/math/CMakeLists.txt|  20 +-
 libc/src/__support/math/atan2.h   | 209 ++
 libc/src/math/generic/CMakeLists.txt  |   8 +-
 libc/src/math/generic/atan2.cpp   | 187 +---
 libc/test/shared/CMakeLists.txt   |   1 +
 libc/test/shared/shared_math_test.cpp |   1 +
 .../llvm-project-overlay/libc/BUILD.bazel |  14 +-
 9 files changed, 266 insertions(+), 198 deletions(-)
 create mode 100644 libc/shared/math/atan2.h
 create mode 100644 libc/src/__support/math/atan2.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index bcbe0de56170a..0605d918eb2af 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -23,6 +23,7 @@
 #include "math/asinhf.h"
 #include "math/asinhf16.h"
 #include "math/atan.h"
+#include "math/atan2.h"
 #include "math/atanf.h"
 #include "math/atanf16.h"
 #include "math/erff.h"
diff --git a/libc/shared/math/atan2.h b/libc/shared/math/atan2.h
new file mode 100644
index 0..894110838817c
--- /dev/null
+++ b/libc/shared/math/atan2.h
@@ -0,0 +1,23 @@
+//===-- Shared atan2 function ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_ATAN2_H
+#define LLVM_LIBC_SHARED_MATH_ATAN2_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/atan2.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::atan2;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ATAN2_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index 04cbd3fd1cc01..bbb07b62552f6 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -158,7 +158,7 @@ add_header_library(
   asinhf16
   HDRS
 asinhf16.h
-DEPENDS
+  DEPENDS
 .acoshf_utils
 libc.src.__support.FPUtil.fenv_impl
 libc.src.__support.FPUtil.fp_bits
@@ -176,7 +176,7 @@ add_header_library(
   atan_utils
   HDRS
 atan_utils.h
-DEPENDS
+  DEPENDS
 libc.src.__support.integer_literals
 libc.src.__support.FPUtil.double_double
 libc.src.__support.FPUtil.dyadic_float
@@ -189,7 +189,21 @@ add_header_library(
   atan
   HDRS
 atan.h
-DEPENDS
+  DEPENDS
+.atan_utils
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.macros.optimization
+)
+
+add_header_library(
+  atan2
+  HDRS
+atan2.h
+  DEPENDS
 .atan_utils
 libc.src.__support.FPUtil.double_double
 libc.src.__support.FPUtil.fenv_impl
diff --git a/libc/src/__support/math/atan2.h b/libc/src/__support/math/atan2.h
new file mode 100644
index 0..90ed926c8d75f
--- /dev/null
+++ b/libc/src/__support/math/atan2.h
@@ -0,0 +1,209 @@
+//===-- Implementation header for atan2 -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ATAN2_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ATAN2_H
+
+#include "atan_utils.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/double_double.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/nearest_integer.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+// There are several range reduction steps we can take for atan2(y, x) as
+// follow:
+
+// * Range reduction 1: signness
+// atan2(y, x) will return a number between -PI and PI representing the angle
+// forming by the 0x axis and the vector (x, y) on the 0xy-plane.
+// In particular, we have that:
+//   atan2(y, x) = atan( y/x ) if x >= 0 and y >= 0 (I-quadrant)
+//   = pi + atan( y/x )if x < 0 and y >= 0  (II-quadrant)
+//  

[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atan2f implementation to header-only in src/__support/math folder. (PR #150993)

2025-07-28 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-libc

Author: Muhammad Bassiouni (bassiounix)


Changes

Part of #147386

in preparation for: 
https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450

---

Patch is 36.23 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/150993.diff


10 Files Affected:

- (modified) libc/shared/math.h (+1) 
- (added) libc/shared/math/atan2f.h (+23) 
- (modified) libc/src/__support/math/CMakeLists.txt (+17) 
- (added) libc/src/__support/math/atan2f.h (+351) 
- (renamed) libc/src/__support/math/atan2f_float.h (+13-8) 
- (modified) libc/src/math/generic/CMakeLists.txt (+1-11) 
- (modified) libc/src/math/generic/atan2f.cpp (+2-326) 
- (modified) libc/test/shared/CMakeLists.txt (+1) 
- (modified) libc/test/shared/shared_math_test.cpp (+1) 
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+17-3) 


``diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 0605d918eb2af..527bb8d6214ae 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -24,6 +24,7 @@
 #include "math/asinhf16.h"
 #include "math/atan.h"
 #include "math/atan2.h"
+#include "math/atan2f.h"
 #include "math/atanf.h"
 #include "math/atanf16.h"
 #include "math/erff.h"
diff --git a/libc/shared/math/atan2f.h b/libc/shared/math/atan2f.h
new file mode 100644
index 0..2de09d25e19f8
--- /dev/null
+++ b/libc/shared/math/atan2f.h
@@ -0,0 +1,23 @@
+//===-- Shared atan2f function --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_ATAN2F_H
+#define LLVM_LIBC_SHARED_MATH_ATAN2F_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/atan2f.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::atan2f;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ATAN2F_H
diff --git a/libc/src/__support/math/CMakeLists.txt 
b/libc/src/__support/math/CMakeLists.txt
index bbb07b62552f6..c197b19ed29de 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -213,6 +213,23 @@ add_header_library(
 libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  atan2f
+  HDRS
+atan2f_float.h
+atan2f.h
+  DEPENDS
+.inv_trigf_utils
+libc.src.__support.FPUtil.double_double
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.multiply_add
+libc.src.__support.FPUtil.nearest_integer
+libc.src.__support.FPUtil.polyeval
+libc.src.__support.macros.config
+libc.src.__support.macros.optimization
+)
+
 add_header_library(
   atanf
   HDRS
diff --git a/libc/src/__support/math/atan2f.h b/libc/src/__support/math/atan2f.h
new file mode 100644
index 0..e3b19329126f4
--- /dev/null
+++ b/libc/src/__support/math/atan2f.h
@@ -0,0 +1,351 @@
+//===-- Implementation header for atan2f *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ATAN2F_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ATAN2F_H
+
+#include "inv_trigf_utils.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.h"
+#include "src/__support/FPUtil/double_double.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/nearest_integer.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
+
+#if defined(LIBC_MATH_HAS_SKIP_ACCURATE_PASS) &&   
\
+defined(LIBC_MATH_HAS_INTERMEDIATE_COMP_IN_FLOAT)
+
+// We use float-float implementation to reduce size.
+#include "atan2f_float.h"
+
+#else
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+namespace atan2f_internal {
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+// Look up tables for accurate pass:
+
+// atan(i/16) with i = 0..16, generated by Sollya with:
+// > for i from 0 to 16 do {
+// a = round(atan(i/16), D, RN);
+// b = round(atan(i/16) - a, D, RN);
+// print("{", b, ",", a, "},");
+//   };
+static constexpr fputil::DoubleDouble ATAN_I[17] = {
+{0.0, 0.0},
+{-0x1.c934d86d23f1dp-60, 0x1.ff55bb72cfdeap-5},
+{-0x1.cd37686760c17p-59, 0x1.fd5ba9aac2f6ep-4},
+{0x1.347b0b4f881cap-58, 0x1.7b97b4bce5b02p-3},
+{0x1.8ab6e3cf7a

[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atan2f implementation to header-only in src/__support/math folder. (PR #150993)

2025-07-28 Thread Muhammad Bassiouni via llvm-branch-commits

https://github.com/bassiounix ready_for_review 
https://github.com/llvm/llvm-project/pull/150993
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [IR] Introduce the `ptrtoaddr` instruction (PR #139357)

2025-07-28 Thread Alexander Richardson via llvm-branch-commits

https://github.com/arichardson updated 
https://github.com/llvm/llvm-project/pull/139357

>From 25dc175562349410f161ef0e80246301d9a7ba79 Mon Sep 17 00:00:00 2001
From: Alex Richardson 
Date: Fri, 9 May 2025 22:43:37 -0700
Subject: [PATCH] fix docs build

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 2d18d0d97aaee..38be6918ff73c 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -12435,7 +12435,7 @@ Example:
 .. _i_ptrtoaddr:
 
 '``ptrtoaddr .. to``' Instruction
-
+^
 
 Syntax:
 """

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [IR] Introduce the `ptrtoaddr` instruction (PR #139357)

2025-07-28 Thread Alexander Richardson via llvm-branch-commits

https://github.com/arichardson updated 
https://github.com/llvm/llvm-project/pull/139357

>From 25dc175562349410f161ef0e80246301d9a7ba79 Mon Sep 17 00:00:00 2001
From: Alex Richardson 
Date: Fri, 9 May 2025 22:43:37 -0700
Subject: [PATCH] fix docs build

Created using spr 1.3.6-beta.1
---
 llvm/docs/LangRef.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 2d18d0d97aaee..38be6918ff73c 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -12435,7 +12435,7 @@ Example:
 .. _i_ptrtoaddr:
 
 '``ptrtoaddr .. to``' Instruction
-
+^
 
 Syntax:
 """

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/21.x: [DAG] visitFREEZE - limit freezing of multiple operands (PR #150425)

2025-07-28 Thread Simon Pilgrim via llvm-branch-commits

https://github.com/RKSimon edited 
https://github.com/llvm/llvm-project/pull/150425
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/21.x: [DAG] visitFREEZE - limit freezing of multiple operands (PR #150425)

2025-07-28 Thread Simon Pilgrim via llvm-branch-commits

RKSimon wrote:

I'll rebase with fewer patches once #150746 has landed - its going to be a mess 
anyhow

https://github.com/llvm/llvm-project/pull/150425
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [Driver] Default to -mv8plus on 32-bit Solaris/SPARC (#150176) (PR #150898)

2025-07-28 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/150898

Backport 06233892e84f96a3b4e05338cd4f6c12b8f5a185

Requested by: @brad0

>From 10ba0b7bcef00e9cf0f611e47d84db4a35af52f8 Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Wed, 23 Jul 2025 17:03:34 +0200
Subject: [PATCH] [Driver] Default to -mv8plus on 32-bit Solaris/SPARC
 (#150176)

While investigating PR #149990, I noticed that while both the Oracle
Studio compilers and GCC default to `-mv8plus` on 32-bit Solaris/SPARC,
Clang does not.

This patch fixes this by enabling the `v8plus` feature.

Tested on `sparcv9-sun-solaris2.11` and `sparc64-unknown-linux-gnu`.

(cherry picked from commit 06233892e84f96a3b4e05338cd4f6c12b8f5a185)
---
 clang/lib/Driver/ToolChains/Arch/Sparc.cpp | 13 -
 clang/test/Driver/sparc-target-features.c  |  4 
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp 
b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
index 1351244e1..94a94f1e9c487 100644
--- a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
@@ -37,6 +37,13 @@ const char *sparc::getSparcAsmModeForCPU(StringRef Name,
 .Case("niagara4", "-Av9d")
 .Default(DefV9CPU);
   } else {
+const char *DefV8CPU;
+
+if (Triple.isOSSolaris())
+  DefV8CPU = "-Av8plus";
+else
+  DefV8CPU = "-Av8";
+
 return llvm::StringSwitch(Name)
 .Case("v8", "-Av8")
 .Case("supersparc", "-Av8")
@@ -72,7 +79,7 @@ const char *sparc::getSparcAsmModeForCPU(StringRef Name,
 .Case("gr712rc", "-Aleon")
 .Case("leon4", "-Aleon")
 .Case("gr740", "-Aleon")
-.Default("-Av8");
+.Default(DefV8CPU);
   }
 }
 
@@ -160,6 +167,8 @@ void sparc::getSparcTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
   (Triple.getArch() == llvm::Triple::sparcv9) &&
   (Triple.isOSLinux() || Triple.isOSFreeBSD() || Triple.isOSOpenBSD());
   bool IsSparcV9BTarget = Triple.isOSSolaris();
+  bool IsSparcV8PlusTarget =
+  Triple.getArch() == llvm::Triple::sparc && Triple.isOSSolaris();
   if (Arg *A = Args.getLastArg(options::OPT_mvis, options::OPT_mno_vis)) {
 if (A->getOption().matches(options::OPT_mvis))
   Features.push_back("+vis");
@@ -196,6 +205,8 @@ void sparc::getSparcTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
   if (Arg *A = Args.getLastArg(options::OPT_mv8plus, options::OPT_mno_v8plus)) 
{
 if (A->getOption().matches(options::OPT_mv8plus))
   Features.push_back("+v8plus");
+  } else if (IsSparcV8PlusTarget) {
+Features.push_back("+v8plus");
   }
 
   if (Args.hasArg(options::OPT_ffixed_g1))
diff --git a/clang/test/Driver/sparc-target-features.c 
b/clang/test/Driver/sparc-target-features.c
index 48a180caf259b..bd17da112bbd2 100644
--- a/clang/test/Driver/sparc-target-features.c
+++ b/clang/test/Driver/sparc-target-features.c
@@ -39,4 +39,8 @@
 // SOFT-QUAD-FLOAT: "-target-feature" "-hard-quad-float"
 
 // RUN: %clang --target=sparc -mv8plus %s -### 2>&1 | FileCheck 
-check-prefix=V8PLUS %s
+/// 32-bit Solaris/SPARC defaults to -mv8plus
+// RUN: %clang --target=sparc-sun-solaris2.11 %s -### 2>&1 | FileCheck 
-check-prefix=V8PLUS %s
+// RUN: %clang --target=sparc-sun-solaris2.11 -mno-v8plus %s -### 2>&1 | 
FileCheck -check-prefix=NO-V8PLUS %s
 // V8PLUS: "-target-feature" "+v8plus"
+// NO-V8PLUS-NOT: "-target-feature" "+v8plus"

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [Driver] Default to -mv8plus on 32-bit Solaris/SPARC (#150176) (PR #150898)

2025-07-28 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/150898
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [Driver] Default to -mv8plus on 32-bit Solaris/SPARC (#150176) (PR #150898)

2025-07-28 Thread via llvm-branch-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-sparc

Author: None (llvmbot)


Changes

Backport 06233892e84f96a3b4e05338cd4f6c12b8f5a185

Requested by: @brad0

---
Full diff: https://github.com/llvm/llvm-project/pull/150898.diff


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Arch/Sparc.cpp (+12-1) 
- (modified) clang/test/Driver/sparc-target-features.c (+4) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp 
b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
index 1351244e1..94a94f1e9c487 100644
--- a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
@@ -37,6 +37,13 @@ const char *sparc::getSparcAsmModeForCPU(StringRef Name,
 .Case("niagara4", "-Av9d")
 .Default(DefV9CPU);
   } else {
+const char *DefV8CPU;
+
+if (Triple.isOSSolaris())
+  DefV8CPU = "-Av8plus";
+else
+  DefV8CPU = "-Av8";
+
 return llvm::StringSwitch(Name)
 .Case("v8", "-Av8")
 .Case("supersparc", "-Av8")
@@ -72,7 +79,7 @@ const char *sparc::getSparcAsmModeForCPU(StringRef Name,
 .Case("gr712rc", "-Aleon")
 .Case("leon4", "-Aleon")
 .Case("gr740", "-Aleon")
-.Default("-Av8");
+.Default(DefV8CPU);
   }
 }
 
@@ -160,6 +167,8 @@ void sparc::getSparcTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
   (Triple.getArch() == llvm::Triple::sparcv9) &&
   (Triple.isOSLinux() || Triple.isOSFreeBSD() || Triple.isOSOpenBSD());
   bool IsSparcV9BTarget = Triple.isOSSolaris();
+  bool IsSparcV8PlusTarget =
+  Triple.getArch() == llvm::Triple::sparc && Triple.isOSSolaris();
   if (Arg *A = Args.getLastArg(options::OPT_mvis, options::OPT_mno_vis)) {
 if (A->getOption().matches(options::OPT_mvis))
   Features.push_back("+vis");
@@ -196,6 +205,8 @@ void sparc::getSparcTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
   if (Arg *A = Args.getLastArg(options::OPT_mv8plus, options::OPT_mno_v8plus)) 
{
 if (A->getOption().matches(options::OPT_mv8plus))
   Features.push_back("+v8plus");
+  } else if (IsSparcV8PlusTarget) {
+Features.push_back("+v8plus");
   }
 
   if (Args.hasArg(options::OPT_ffixed_g1))
diff --git a/clang/test/Driver/sparc-target-features.c 
b/clang/test/Driver/sparc-target-features.c
index 48a180caf259b..bd17da112bbd2 100644
--- a/clang/test/Driver/sparc-target-features.c
+++ b/clang/test/Driver/sparc-target-features.c
@@ -39,4 +39,8 @@
 // SOFT-QUAD-FLOAT: "-target-feature" "-hard-quad-float"
 
 // RUN: %clang --target=sparc -mv8plus %s -### 2>&1 | FileCheck 
-check-prefix=V8PLUS %s
+/// 32-bit Solaris/SPARC defaults to -mv8plus
+// RUN: %clang --target=sparc-sun-solaris2.11 %s -### 2>&1 | FileCheck 
-check-prefix=V8PLUS %s
+// RUN: %clang --target=sparc-sun-solaris2.11 -mno-v8plus %s -### 2>&1 | 
FileCheck -check-prefix=NO-V8PLUS %s
 // V8PLUS: "-target-feature" "+v8plus"
+// NO-V8PLUS-NOT: "-target-feature" "+v8plus"

``




https://github.com/llvm/llvm-project/pull/150898
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [Driver] Default to -mv8plus on 32-bit Solaris/SPARC (#150176) (PR #150898)

2025-07-28 Thread via llvm-branch-commits

llvmbot wrote:

@koachan What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/150898
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [Driver] Default to -mv8plus on 32-bit Solaris/SPARC (#150176) (PR #150898)

2025-07-28 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: None (llvmbot)


Changes

Backport 06233892e84f96a3b4e05338cd4f6c12b8f5a185

Requested by: @brad0

---
Full diff: https://github.com/llvm/llvm-project/pull/150898.diff


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Arch/Sparc.cpp (+12-1) 
- (modified) clang/test/Driver/sparc-target-features.c (+4) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp 
b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
index 1351244e1..94a94f1e9c487 100644
--- a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
@@ -37,6 +37,13 @@ const char *sparc::getSparcAsmModeForCPU(StringRef Name,
 .Case("niagara4", "-Av9d")
 .Default(DefV9CPU);
   } else {
+const char *DefV8CPU;
+
+if (Triple.isOSSolaris())
+  DefV8CPU = "-Av8plus";
+else
+  DefV8CPU = "-Av8";
+
 return llvm::StringSwitch(Name)
 .Case("v8", "-Av8")
 .Case("supersparc", "-Av8")
@@ -72,7 +79,7 @@ const char *sparc::getSparcAsmModeForCPU(StringRef Name,
 .Case("gr712rc", "-Aleon")
 .Case("leon4", "-Aleon")
 .Case("gr740", "-Aleon")
-.Default("-Av8");
+.Default(DefV8CPU);
   }
 }
 
@@ -160,6 +167,8 @@ void sparc::getSparcTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
   (Triple.getArch() == llvm::Triple::sparcv9) &&
   (Triple.isOSLinux() || Triple.isOSFreeBSD() || Triple.isOSOpenBSD());
   bool IsSparcV9BTarget = Triple.isOSSolaris();
+  bool IsSparcV8PlusTarget =
+  Triple.getArch() == llvm::Triple::sparc && Triple.isOSSolaris();
   if (Arg *A = Args.getLastArg(options::OPT_mvis, options::OPT_mno_vis)) {
 if (A->getOption().matches(options::OPT_mvis))
   Features.push_back("+vis");
@@ -196,6 +205,8 @@ void sparc::getSparcTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
   if (Arg *A = Args.getLastArg(options::OPT_mv8plus, options::OPT_mno_v8plus)) 
{
 if (A->getOption().matches(options::OPT_mv8plus))
   Features.push_back("+v8plus");
+  } else if (IsSparcV8PlusTarget) {
+Features.push_back("+v8plus");
   }
 
   if (Args.hasArg(options::OPT_ffixed_g1))
diff --git a/clang/test/Driver/sparc-target-features.c 
b/clang/test/Driver/sparc-target-features.c
index 48a180caf259b..bd17da112bbd2 100644
--- a/clang/test/Driver/sparc-target-features.c
+++ b/clang/test/Driver/sparc-target-features.c
@@ -39,4 +39,8 @@
 // SOFT-QUAD-FLOAT: "-target-feature" "-hard-quad-float"
 
 // RUN: %clang --target=sparc -mv8plus %s -### 2>&1 | FileCheck 
-check-prefix=V8PLUS %s
+/// 32-bit Solaris/SPARC defaults to -mv8plus
+// RUN: %clang --target=sparc-sun-solaris2.11 %s -### 2>&1 | FileCheck 
-check-prefix=V8PLUS %s
+// RUN: %clang --target=sparc-sun-solaris2.11 -mno-v8plus %s -### 2>&1 | 
FileCheck -check-prefix=NO-V8PLUS %s
 // V8PLUS: "-target-feature" "+v8plus"
+// NO-V8PLUS-NOT: "-target-feature" "+v8plus"

``




https://github.com/llvm/llvm-project/pull/150898
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [AMDGPU][GISel] Use buildObjectPtrOffset instead of buildPtrAdd (PR #150899)

2025-07-28 Thread Fabian Ritter via llvm-branch-commits

ritter-x2a wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/150899?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#150900** https://app.graphite.dev/github/pr/llvm/llvm-project/150900?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#150899** https://app.graphite.dev/github/pr/llvm/llvm-project/150899?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/150899?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#150392** https://app.graphite.dev/github/pr/llvm/llvm-project/150392?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


https://github.com/llvm/llvm-project/pull/150899
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GISel] Introduce MIFlags::InBounds (PR #150900)

2025-07-28 Thread Fabian Ritter via llvm-branch-commits

ritter-x2a wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/150900?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#150900** https://app.graphite.dev/github/pr/llvm/llvm-project/150900?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/150900?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#150899** https://app.graphite.dev/github/pr/llvm/llvm-project/150899?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#150392** https://app.graphite.dev/github/pr/llvm/llvm-project/150392?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


https://github.com/llvm/llvm-project/pull/150900
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [AMDGPU][GISel] Use buildObjectPtrOffset instead of buildPtrAdd (PR #150899)

2025-07-28 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-amdgpu

Author: Fabian Ritter (ritter-x2a)


Changes

This concerns offset computations for kernargs and
RegBankLegalizeHelper::splitLoad, which should all be within the bounds of a
memory object. See #150392 for the motivation for introducing the
buildObjectPtrOffset function.

For SWDEV-516125.

---

Patch is 113.72 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/150899.diff


10 Files Affected:

- (modified) llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp (+10-10) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPURegBankLegalizeHelper.cpp (+2-1) 
- (modified) 
llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call-abi-attribute-hints.ll 
(+3-3) 
- (modified) 
llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call-implicit-args.ll (+16-16) 
- (modified) 
llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call-return-values.ll (+45-45) 
- (modified) llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call-sret.ll 
(+8-8) 
- (modified) llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call.ll (+64-64) 
- (modified) llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-indirect-call.ll 
(+1-1) 
- (modified) llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-addrspacecast.mir 
(+9-5) 
- (modified) llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-load.mir 
(+26-26) 


``diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
index fedfa3f9dd900..3d494374fb33b 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
@@ -2295,8 +2295,8 @@ Register AMDGPULegalizerInfo::getSegmentAperture(
 LLT::scalar(32), commonAlignment(Align(64), Offset));
 
 // Pointer address
-B.buildPtrAdd(LoadAddr, KernargPtrReg,
-  B.buildConstant(LLT::scalar(64), Offset).getReg(0));
+B.buildObjectPtrOffset(LoadAddr, KernargPtrReg,
+   B.buildConstant(LLT::scalar(64), Offset).getReg(0));
 // Load address
 return B.buildLoad(S32, LoadAddr, *MMO).getReg(0);
   }
@@ -2317,8 +2317,9 @@ Register AMDGPULegalizerInfo::getSegmentAperture(
   MachineMemOperand::MOInvariant,
   LLT::scalar(32), commonAlignment(Align(64), StructOffset));
 
-  B.buildPtrAdd(LoadAddr, QueuePtr,
-B.buildConstant(LLT::scalar(64), StructOffset).getReg(0));
+  B.buildObjectPtrOffset(
+  LoadAddr, QueuePtr,
+  B.buildConstant(LLT::scalar(64), StructOffset).getReg(0));
   return B.buildLoad(S32, LoadAddr, *MMO).getReg(0);
 }
 
@@ -4500,8 +4501,7 @@ Register 
AMDGPULegalizerInfo::getKernargParameterPtr(MachineIRBuilder &B,
 llvm_unreachable("failed to find kernarg segment ptr");
 
   auto COffset = B.buildConstant(LLT::scalar(64), Offset);
-  // TODO: Should get nuw
-  return B.buildPtrAdd(PtrTy, KernArgReg, COffset).getReg(0);
+  return B.buildObjectPtrOffset(PtrTy, KernArgReg, COffset).getReg(0);
 }
 
 /// Legalize a value that's loaded from kernel arguments. This is only used by
@@ -5676,8 +5676,8 @@ bool AMDGPULegalizerInfo::getImplicitArgPtr(Register 
DstReg,
   AMDGPUFunctionArgInfo::KERNARG_SEGMENT_PTR))
 return false;
 
-  // FIXME: This should be nuw
-  B.buildPtrAdd(DstReg, KernargPtrReg, B.buildConstant(IdxTy, 
Offset).getReg(0));
+  B.buildObjectPtrOffset(DstReg, KernargPtrReg,
+ B.buildConstant(IdxTy, Offset).getReg(0));
   return true;
 }
 
@@ -7019,8 +7019,8 @@ bool AMDGPULegalizerInfo::legalizeTrapHsaQueuePtr(
 // Pointer address
 Register LoadAddr = MRI.createGenericVirtualRegister(
 LLT::pointer(AMDGPUAS::CONSTANT_ADDRESS, 64));
-B.buildPtrAdd(LoadAddr, KernargPtrReg,
-  B.buildConstant(LLT::scalar(64), Offset).getReg(0));
+B.buildObjectPtrOffset(LoadAddr, KernargPtrReg,
+   B.buildConstant(LLT::scalar(64), Offset).getReg(0));
 // Load address
 Register Temp = B.buildLoad(S64, LoadAddr, *MMO).getReg(0);
 B.buildCopy(SGPR01, Temp);
diff --git a/llvm/lib/Target/AMDGPU/AMDGPURegBankLegalizeHelper.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPURegBankLegalizeHelper.cpp
index f471881ee7693..b45627d9c1c5d 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPURegBankLegalizeHelper.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPURegBankLegalizeHelper.cpp
@@ -294,7 +294,8 @@ void RegBankLegalizeHelper::splitLoad(MachineInstr &MI,
   BasePlusOffset = Base;
 } else {
   auto Offset = B.buildConstant({PtrRB, OffsetTy}, ByteOffset);
-  BasePlusOffset = B.buildPtrAdd({PtrRB, PtrTy}, Base, Offset).getReg(0);
+  BasePlusOffset =
+  B.buildObjectPtrOffset({PtrRB, PtrTy}, Base, Offset).getReg(0);
 }
 auto *OffsetMMO = MF.getMachineMemOperand(&BaseMMO, ByteOffset, PartTy);
 auto LoadPart = B.buildLoad({DstRB, PartTy}, BasePlusOffset, *OffsetMMO);
diff --git 
a/llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call-abi-attribute-hints.ll 
b/llvm/test/Code

[llvm-branch-commits] [llvm] [AMDGPU][GISel] Use buildObjectPtrOffset instead of buildPtrAdd (PR #150899)

2025-07-28 Thread Fabian Ritter via llvm-branch-commits

https://github.com/ritter-x2a ready_for_review 
https://github.com/llvm/llvm-project/pull/150899
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libunwind] release/21.x: [libunwind] Fix return type of `DwarfFDECache::findFDE()` in definition (#146308) (PR #150126)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

tru wrote:

@alexrp can you rebase this one to get the fixes for libc++ ci, and we'll see 
if it works. @ldionne  do you see any risks with this being merged to the 
release branch? I don't know who reviews libunwind, and I saw it was not 
reviewed for the main branch at all.

https://github.com/llvm/llvm-project/pull/150126
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lldb] release/21.x: [lldb] Allow building using Mingw-w64 on Windows. (#150398) (PR #150591)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

tru wrote:

Can we get a review and it approved?

https://github.com/llvm/llvm-project/pull/150591
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [clang] Fix potential constant expression checking with constexpr-unknown. (PR #149402)

2025-07-28 Thread Corentin Jabot via llvm-branch-commits

https://github.com/cor3ntin approved this pull request.

LGTM!

https://github.com/llvm/llvm-project/pull/149402
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] f6c4f0e - [lld] Add thunks for hexagon (#111217)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

Author: Brian Cain
Date: 2025-07-28T09:27:54+02:00
New Revision: f6c4f0eb7037bf58f0082f52e08356c4693df1fa

URL: 
https://github.com/llvm/llvm-project/commit/f6c4f0eb7037bf58f0082f52e08356c4693df1fa
DIFF: 
https://github.com/llvm/llvm-project/commit/f6c4f0eb7037bf58f0082f52e08356c4693df1fa.diff

LOG: [lld] Add thunks for hexagon (#111217)

Without thunks, programs will encounter link errors complaining that the
branch target is out of range. Thunks will extend the range of branch
targets, which is a critical need for large programs. Thunks provide
this flexibility at a cost of some modest code size increase.

When configured with the maximal feature set, the hexagon port of the
linux kernel would often encounter these limitations when linking with
`lld`.

The relocations which will be extended by thunks are:

* R_HEX_B22_PCREL, R_HEX_{G,L}D_PLT_B22_PCREL, R_HEX_PLT_B22_PCREL
relocations have a range of ± 8MiB on the baseline
* R_HEX_B15_PCREL: ±65,532 bytes
* R_HEX_B13_PCREL: ±16,380 bytes
* R_HEX_B9_PCREL: ±1,020 bytes

Fixes #149689

Co-authored-by: Alexey Karyakin 

-

Co-authored-by: Alexey Karyakin 
(cherry picked from commit b42f96bc057fd9e31572069b241ba130c21144e5)

Added: 
lld/test/ELF/hexagon-thunk-range-b22rel.s
lld/test/ELF/hexagon-thunk-range-gdplt.s
lld/test/ELF/hexagon-thunk-range-plt.s
lld/test/ELF/hexagon-thunks-packets.s
lld/test/ELF/hexagon-thunks.s

Modified: 
lld/ELF/Arch/Hexagon.cpp
lld/ELF/Relocations.cpp
lld/ELF/Thunks.cpp

Removed: 
lld/test/ELF/hexagon-jump-error.s



diff  --git a/lld/ELF/Arch/Hexagon.cpp b/lld/ELF/Arch/Hexagon.cpp
index 479131a24dcfc..9b33e78731c97 100644
--- a/lld/ELF/Arch/Hexagon.cpp
+++ b/lld/ELF/Arch/Hexagon.cpp
@@ -11,6 +11,7 @@
 #include "Symbols.h"
 #include "SyntheticSections.h"
 #include "Target.h"
+#include "Thunks.h"
 #include "lld/Common/ErrorHandler.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/BinaryFormat/ELF.h"
@@ -36,6 +37,10 @@ class Hexagon final : public TargetInfo {
  const uint8_t *loc) const override;
   RelType getDynRel(RelType type) const override;
   int64_t getImplicitAddend(const uint8_t *buf, RelType type) const override;
+  bool needsThunk(RelExpr expr, RelType type, const InputFile *file,
+  uint64_t branchAddr, const Symbol &s,
+  int64_t a) const override;
+  bool inBranchRange(RelType type, uint64_t src, uint64_t dst) const override;
   void relocate(uint8_t *loc, const Relocation &rel,
 uint64_t val) const override;
   void writePltHeader(uint8_t *buf) const override;
@@ -63,6 +68,8 @@ Hexagon::Hexagon(Ctx &ctx) : TargetInfo(ctx) {
   tlsGotRel = R_HEX_TPREL_32;
   tlsModuleIndexRel = R_HEX_DTPMOD_32;
   tlsOffsetRel = R_HEX_DTPREL_32;
+
+  needsThunks = true;
 }
 
 uint32_t Hexagon::calcEFlags() const {
@@ -258,6 +265,46 @@ static uint32_t findMaskR16(Ctx &ctx, uint32_t insn) {
 
 static void or32le(uint8_t *p, int32_t v) { write32le(p, read32le(p) | v); }
 
+bool Hexagon::inBranchRange(RelType type, uint64_t src, uint64_t dst) const {
+  int64_t offset = dst - src;
+  switch (type) {
+  case llvm::ELF::R_HEX_B22_PCREL:
+  case llvm::ELF::R_HEX_PLT_B22_PCREL:
+  case llvm::ELF::R_HEX_GD_PLT_B22_PCREL:
+  case llvm::ELF::R_HEX_LD_PLT_B22_PCREL:
+return llvm::isInt<22>(offset >> 2);
+  case llvm::ELF::R_HEX_B15_PCREL:
+return llvm::isInt<15>(offset >> 2);
+break;
+  case llvm::ELF::R_HEX_B13_PCREL:
+return llvm::isInt<13>(offset >> 2);
+break;
+  case llvm::ELF::R_HEX_B9_PCREL:
+return llvm::isInt<9>(offset >> 2);
+  default:
+return true;
+  }
+  llvm_unreachable("unsupported relocation");
+}
+
+bool Hexagon::needsThunk(RelExpr expr, RelType type, const InputFile *file,
+ uint64_t branchAddr, const Symbol &s,
+ int64_t a) const {
+  // Only check branch range for supported branch relocation types
+  switch (type) {
+  case R_HEX_B22_PCREL:
+  case R_HEX_PLT_B22_PCREL:
+  case R_HEX_GD_PLT_B22_PCREL:
+  case R_HEX_LD_PLT_B22_PCREL:
+  case R_HEX_B15_PCREL:
+  case R_HEX_B13_PCREL:
+  case R_HEX_B9_PCREL:
+return !ctx.target->inBranchRange(type, branchAddr, s.getVA(ctx, a));
+  default:
+return false;
+  }
+}
+
 void Hexagon::relocate(uint8_t *loc, const Relocation &rel,
uint64_t val) const {
   switch (rel.type) {

diff  --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index c6dba7558396f..2ee308a2d1b3c 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -2139,17 +2139,44 @@ void ThunkCreator::mergeThunks(ArrayRef outputSections) {
   });
 }
 
-static int64_t getPCBias(Ctx &ctx, RelType type) {
-  if (ctx.arg.emachine != EM_ARM)
-return 0;
-  switch (type) {
-  case R_ARM_THM_JUMP19:
-  case R_ARM_THM_JUMP24:
-  case R_ARM_THM_CALL:
-return 4;
-  default:
-return 8;
+constexpr uint32_

[llvm-branch-commits] [libcxx] 564ed8e - [libc++] Fix hash_multi{map, set}::insert (#149290)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

Author: Nikolas Klauser
Date: 2025-07-28T09:27:10+02:00
New Revision: 564ed8e06421148f4a415df1cb154cd28572bfdb

URL: 
https://github.com/llvm/llvm-project/commit/564ed8e06421148f4a415df1cb154cd28572bfdb
DIFF: 
https://github.com/llvm/llvm-project/commit/564ed8e06421148f4a415df1cb154cd28572bfdb.diff

LOG: [libc++] Fix hash_multi{map,set}::insert (#149290)

(cherry picked from commit be3d614cc13f016b16634e18e10caed508d183d2)

Added: 
libcxx/test/extensions/gnu/hash_multimap/insert.pass.cpp
libcxx/test/extensions/gnu/hash_multiset/insert.pass.cpp

Modified: 
libcxx/include/ext/hash_map
libcxx/include/ext/hash_set

Removed: 




diff  --git a/libcxx/include/ext/hash_map b/libcxx/include/ext/hash_map
index d6b92204f4376..46815eaffa8bd 100644
--- a/libcxx/include/ext/hash_map
+++ b/libcxx/include/ext/hash_map
@@ -744,7 +744,7 @@ public:
   _LIBCPP_HIDE_FROM_ABI const_iterator begin() const { return 
__table_.begin(); }
   _LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __table_.end(); }
 
-  _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return 
__table_.__emplace_unique(__x); }
+  _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return 
__table_.__emplace_multi(__x); }
   _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) 
{ return insert(__x); }
   template 
   _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator 
__last);
@@ -831,7 +831,7 @@ template 
 template 
 inline void hash_multimap<_Key, _Tp, _Hash, _Pred, 
_Alloc>::insert(_InputIterator __first, _InputIterator __last) {
   for (; __first != __last; ++__first)
-__table_.__emplace_unique(*__first);
+__table_.__emplace_multi(*__first);
 }
 
 template 

diff  --git a/libcxx/include/ext/hash_set b/libcxx/include/ext/hash_set
index 7fd5df24ed3a8..62a7a0dbcffb9 100644
--- a/libcxx/include/ext/hash_set
+++ b/libcxx/include/ext/hash_set
@@ -458,7 +458,7 @@ public:
   _LIBCPP_HIDE_FROM_ABI const_iterator begin() const { return 
__table_.begin(); }
   _LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __table_.end(); }
 
-  _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return 
__table_.__emplace_unique(__x); }
+  _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return 
__table_.__emplace_multi(__x); }
   _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) 
{ return insert(__x); }
   template 
   _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator 
__last);
@@ -543,7 +543,7 @@ template 
 template 
 inline void hash_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator 
__first, _InputIterator __last) {
   for (; __first != __last; ++__first)
-__table_.__emplace_unique(*__first);
+__table_.__emplace_multi(*__first);
 }
 
 template 

diff  --git a/libcxx/test/extensions/gnu/hash_multimap/insert.pass.cpp 
b/libcxx/test/extensions/gnu/hash_multimap/insert.pass.cpp
new file mode 100644
index 0..ea80359f1fea2
--- /dev/null
+++ b/libcxx/test/extensions/gnu/hash_multimap/insert.pass.cpp
@@ -0,0 +1,35 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// ADDITIONAL_COMPILE_FLAGS: -Wno-deprecated
+
+// hash_multimap::insert
+
+#include 
+#include 
+
+int main(int, char**) {
+  __gnu_cxx::hash_multimap map;
+
+  map.insert(std::make_pair(1, 1));
+  map.insert(std::make_pair(1, 1));
+
+  assert(map.size() == 2);
+  assert(map.equal_range(1).first == map.begin());
+  assert(map.equal_range(1).second == map.end());
+
+  std::pair arr[] = {std::make_pair(1, 1), std::make_pair(1, 1)};
+
+  map.insert(arr, arr + 2);
+
+  assert(map.size() == 4);
+  assert(map.equal_range(1).first == map.begin());
+  assert(map.equal_range(1).second == map.end());
+
+  return 0;
+}

diff  --git a/libcxx/test/extensions/gnu/hash_multiset/insert.pass.cpp 
b/libcxx/test/extensions/gnu/hash_multiset/insert.pass.cpp
new file mode 100644
index 0..1a60cac158a40
--- /dev/null
+++ b/libcxx/test/extensions/gnu/hash_multiset/insert.pass.cpp
@@ -0,0 +1,35 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// ADDITIONAL_COMPILE_FLAGS: -Wno-deprecated
+
+// hash_multimap::insert
+
+#include 
+#include 
+
+int main(int, char**) {
+  __gnu_cxx::hash

[llvm-branch-commits] [libcxx] release/21.x: [libc++] Fix hash_multi{map, set}::insert (#149290) (PR #149435)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru updated https://github.com/llvm/llvm-project/pull/149435

>From 564ed8e06421148f4a415df1cb154cd28572bfdb Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Thu, 17 Jul 2025 23:23:04 +0200
Subject: [PATCH] [libc++] Fix hash_multi{map,set}::insert (#149290)

(cherry picked from commit be3d614cc13f016b16634e18e10caed508d183d2)
---
 libcxx/include/ext/hash_map   |  4 +--
 libcxx/include/ext/hash_set   |  4 +--
 .../gnu/hash_multimap/insert.pass.cpp | 35 +++
 .../gnu/hash_multiset/insert.pass.cpp | 35 +++
 4 files changed, 74 insertions(+), 4 deletions(-)
 create mode 100644 libcxx/test/extensions/gnu/hash_multimap/insert.pass.cpp
 create mode 100644 libcxx/test/extensions/gnu/hash_multiset/insert.pass.cpp

diff --git a/libcxx/include/ext/hash_map b/libcxx/include/ext/hash_map
index d6b92204f4376..46815eaffa8bd 100644
--- a/libcxx/include/ext/hash_map
+++ b/libcxx/include/ext/hash_map
@@ -744,7 +744,7 @@ public:
   _LIBCPP_HIDE_FROM_ABI const_iterator begin() const { return 
__table_.begin(); }
   _LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __table_.end(); }
 
-  _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return 
__table_.__emplace_unique(__x); }
+  _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return 
__table_.__emplace_multi(__x); }
   _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) 
{ return insert(__x); }
   template 
   _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator 
__last);
@@ -831,7 +831,7 @@ template 
 template 
 inline void hash_multimap<_Key, _Tp, _Hash, _Pred, 
_Alloc>::insert(_InputIterator __first, _InputIterator __last) {
   for (; __first != __last; ++__first)
-__table_.__emplace_unique(*__first);
+__table_.__emplace_multi(*__first);
 }
 
 template 
diff --git a/libcxx/include/ext/hash_set b/libcxx/include/ext/hash_set
index 7fd5df24ed3a8..62a7a0dbcffb9 100644
--- a/libcxx/include/ext/hash_set
+++ b/libcxx/include/ext/hash_set
@@ -458,7 +458,7 @@ public:
   _LIBCPP_HIDE_FROM_ABI const_iterator begin() const { return 
__table_.begin(); }
   _LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __table_.end(); }
 
-  _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return 
__table_.__emplace_unique(__x); }
+  _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return 
__table_.__emplace_multi(__x); }
   _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) 
{ return insert(__x); }
   template 
   _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator 
__last);
@@ -543,7 +543,7 @@ template 
 template 
 inline void hash_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator 
__first, _InputIterator __last) {
   for (; __first != __last; ++__first)
-__table_.__emplace_unique(*__first);
+__table_.__emplace_multi(*__first);
 }
 
 template 
diff --git a/libcxx/test/extensions/gnu/hash_multimap/insert.pass.cpp 
b/libcxx/test/extensions/gnu/hash_multimap/insert.pass.cpp
new file mode 100644
index 0..ea80359f1fea2
--- /dev/null
+++ b/libcxx/test/extensions/gnu/hash_multimap/insert.pass.cpp
@@ -0,0 +1,35 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// ADDITIONAL_COMPILE_FLAGS: -Wno-deprecated
+
+// hash_multimap::insert
+
+#include 
+#include 
+
+int main(int, char**) {
+  __gnu_cxx::hash_multimap map;
+
+  map.insert(std::make_pair(1, 1));
+  map.insert(std::make_pair(1, 1));
+
+  assert(map.size() == 2);
+  assert(map.equal_range(1).first == map.begin());
+  assert(map.equal_range(1).second == map.end());
+
+  std::pair arr[] = {std::make_pair(1, 1), std::make_pair(1, 1)};
+
+  map.insert(arr, arr + 2);
+
+  assert(map.size() == 4);
+  assert(map.equal_range(1).first == map.begin());
+  assert(map.equal_range(1).second == map.end());
+
+  return 0;
+}
diff --git a/libcxx/test/extensions/gnu/hash_multiset/insert.pass.cpp 
b/libcxx/test/extensions/gnu/hash_multiset/insert.pass.cpp
new file mode 100644
index 0..1a60cac158a40
--- /dev/null
+++ b/libcxx/test/extensions/gnu/hash_multiset/insert.pass.cpp
@@ -0,0 +1,35 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// ADDITIONAL_COMPILE_FLAGS: -Wno-deprecated
+
+// hash_multimap

[llvm-branch-commits] [libcxx] release/21.x: [libc++] Fix hash_multi{map, set}::insert (#149290) (PR #149435)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru closed https://github.com/llvm/llvm-project/pull/149435
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] release/21.x: [libc++] Fix hash_multi{map, set}::insert (#149290) (PR #149435)

2025-07-28 Thread via llvm-branch-commits

github-actions[bot] wrote:

@frederick-vs-ja (or anyone else). If you would like to add a note about this 
fix in the release notes (completely optional). Please reply to this comment 
with a one or two sentence description of the fix.  When you are done, please 
add the release:note label to this PR. 

https://github.com/llvm/llvm-project/pull/149435
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/21.x: [lld] Add thunks for hexagon (#111217) (PR #149723)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru closed https://github.com/llvm/llvm-project/pull/149723
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/21.x: [lld] Add thunks for hexagon (#111217) (PR #149723)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru updated https://github.com/llvm/llvm-project/pull/149723

>From f6c4f0eb7037bf58f0082f52e08356c4693df1fa Mon Sep 17 00:00:00 2001
From: Brian Cain 
Date: Sun, 20 Jul 2025 11:46:31 -0500
Subject: [PATCH] [lld] Add thunks for hexagon (#111217)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Without thunks, programs will encounter link errors complaining that the
branch target is out of range. Thunks will extend the range of branch
targets, which is a critical need for large programs. Thunks provide
this flexibility at a cost of some modest code size increase.

When configured with the maximal feature set, the hexagon port of the
linux kernel would often encounter these limitations when linking with
`lld`.

The relocations which will be extended by thunks are:

* R_HEX_B22_PCREL, R_HEX_{G,L}D_PLT_B22_PCREL, R_HEX_PLT_B22_PCREL
relocations have a range of ± 8MiB on the baseline
* R_HEX_B15_PCREL: ±65,532 bytes
* R_HEX_B13_PCREL: ±16,380 bytes
* R_HEX_B9_PCREL: ±1,020 bytes

Fixes #149689

Co-authored-by: Alexey Karyakin 

-

Co-authored-by: Alexey Karyakin 
(cherry picked from commit b42f96bc057fd9e31572069b241ba130c21144e5)
---
 lld/ELF/Arch/Hexagon.cpp  |  47 +
 lld/ELF/Relocations.cpp   |  53 +++---
 lld/ELF/Thunks.cpp|  72 -
 lld/test/ELF/hexagon-jump-error.s |  32 --
 lld/test/ELF/hexagon-thunk-range-b22rel.s | 115 
 lld/test/ELF/hexagon-thunk-range-gdplt.s  |  95 +
 lld/test/ELF/hexagon-thunk-range-plt.s|  75 +
 lld/test/ELF/hexagon-thunks-packets.s | 122 ++
 lld/test/ELF/hexagon-thunks.s |  53 ++
 9 files changed, 618 insertions(+), 46 deletions(-)
 delete mode 100644 lld/test/ELF/hexagon-jump-error.s
 create mode 100644 lld/test/ELF/hexagon-thunk-range-b22rel.s
 create mode 100644 lld/test/ELF/hexagon-thunk-range-gdplt.s
 create mode 100644 lld/test/ELF/hexagon-thunk-range-plt.s
 create mode 100644 lld/test/ELF/hexagon-thunks-packets.s
 create mode 100644 lld/test/ELF/hexagon-thunks.s

diff --git a/lld/ELF/Arch/Hexagon.cpp b/lld/ELF/Arch/Hexagon.cpp
index 479131a24dcfc..9b33e78731c97 100644
--- a/lld/ELF/Arch/Hexagon.cpp
+++ b/lld/ELF/Arch/Hexagon.cpp
@@ -11,6 +11,7 @@
 #include "Symbols.h"
 #include "SyntheticSections.h"
 #include "Target.h"
+#include "Thunks.h"
 #include "lld/Common/ErrorHandler.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/BinaryFormat/ELF.h"
@@ -36,6 +37,10 @@ class Hexagon final : public TargetInfo {
  const uint8_t *loc) const override;
   RelType getDynRel(RelType type) const override;
   int64_t getImplicitAddend(const uint8_t *buf, RelType type) const override;
+  bool needsThunk(RelExpr expr, RelType type, const InputFile *file,
+  uint64_t branchAddr, const Symbol &s,
+  int64_t a) const override;
+  bool inBranchRange(RelType type, uint64_t src, uint64_t dst) const override;
   void relocate(uint8_t *loc, const Relocation &rel,
 uint64_t val) const override;
   void writePltHeader(uint8_t *buf) const override;
@@ -63,6 +68,8 @@ Hexagon::Hexagon(Ctx &ctx) : TargetInfo(ctx) {
   tlsGotRel = R_HEX_TPREL_32;
   tlsModuleIndexRel = R_HEX_DTPMOD_32;
   tlsOffsetRel = R_HEX_DTPREL_32;
+
+  needsThunks = true;
 }
 
 uint32_t Hexagon::calcEFlags() const {
@@ -258,6 +265,46 @@ static uint32_t findMaskR16(Ctx &ctx, uint32_t insn) {
 
 static void or32le(uint8_t *p, int32_t v) { write32le(p, read32le(p) | v); }
 
+bool Hexagon::inBranchRange(RelType type, uint64_t src, uint64_t dst) const {
+  int64_t offset = dst - src;
+  switch (type) {
+  case llvm::ELF::R_HEX_B22_PCREL:
+  case llvm::ELF::R_HEX_PLT_B22_PCREL:
+  case llvm::ELF::R_HEX_GD_PLT_B22_PCREL:
+  case llvm::ELF::R_HEX_LD_PLT_B22_PCREL:
+return llvm::isInt<22>(offset >> 2);
+  case llvm::ELF::R_HEX_B15_PCREL:
+return llvm::isInt<15>(offset >> 2);
+break;
+  case llvm::ELF::R_HEX_B13_PCREL:
+return llvm::isInt<13>(offset >> 2);
+break;
+  case llvm::ELF::R_HEX_B9_PCREL:
+return llvm::isInt<9>(offset >> 2);
+  default:
+return true;
+  }
+  llvm_unreachable("unsupported relocation");
+}
+
+bool Hexagon::needsThunk(RelExpr expr, RelType type, const InputFile *file,
+ uint64_t branchAddr, const Symbol &s,
+ int64_t a) const {
+  // Only check branch range for supported branch relocation types
+  switch (type) {
+  case R_HEX_B22_PCREL:
+  case R_HEX_PLT_B22_PCREL:
+  case R_HEX_GD_PLT_B22_PCREL:
+  case R_HEX_LD_PLT_B22_PCREL:
+  case R_HEX_B15_PCREL:
+  case R_HEX_B13_PCREL:
+  case R_HEX_B9_PCREL:
+return !ctx.target->inBranchRange(type, branchAddr, s.getVA(ctx, a));
+  default:
+return false;
+  }
+}
+
 void Hexagon::relocate(uint8_t *loc, const Relocation &rel,
uint64_t val) const {
  

[llvm-branch-commits] [lld] release/21.x: [lld] Add thunks for hexagon (#111217) (PR #149723)

2025-07-28 Thread via llvm-branch-commits

github-actions[bot] wrote:

@androm3da (or anyone else). If you would like to add a note about this fix in 
the release notes (completely optional). Please reply to this comment with a 
one or two sentence description of the fix.  When you are done, please add the 
release:note label to this PR. 

https://github.com/llvm/llvm-project/pull/149723
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/21.x: [AArch64, TTI] Remove RealUse check for vector insert/extract costs. (#146526) (PR #149815)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru closed https://github.com/llvm/llvm-project/pull/149815
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/21.x: [AArch64, TTI] Remove RealUse check for vector insert/extract costs. (#146526) (PR #149815)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

tru wrote:

Merged in 6df2bfd66b3930e848a4906a000624ce199825b9

https://github.com/llvm/llvm-project/pull/149815
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/21.x: [MachinePipeliner] Fix incorrect dependency direction (#149436) (PR #149950)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru closed https://github.com/llvm/llvm-project/pull/149950
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/21.x: [MachinePipeliner] Fix incorrect dependency direction (#149436) (PR #149950)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru updated https://github.com/llvm/llvm-project/pull/149950

>From ba5aa84b543d100df5dafffbf0c9874b592d0c37 Mon Sep 17 00:00:00 2001
From: Ryotaro Kasuga 
Date: Tue, 22 Jul 2025 09:53:13 +0900
Subject: [PATCH] [MachinePipeliner] Fix incorrect dependency direction
 (#149436)

This patch fixes a bug introduced in #145878. A dependency was added in
the wrong direction, causing an assertion failure due to broken
topological order.

(cherry picked from commit 6df012ab48ececd27359bdc9448ee101b39eea7a)
---
 llvm/lib/CodeGen/MachinePipeliner.cpp |  4 +-
 .../Hexagon/swp-load-to-store-forward.mir | 50 +++
 2 files changed, 52 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/CodeGen/Hexagon/swp-load-to-store-forward.mir

diff --git a/llvm/lib/CodeGen/MachinePipeliner.cpp 
b/llvm/lib/CodeGen/MachinePipeliner.cpp
index b38a4d1c55af9..90005bd181f3a 100644
--- a/llvm/lib/CodeGen/MachinePipeliner.cpp
+++ b/llvm/lib/CodeGen/MachinePipeliner.cpp
@@ -4279,8 +4279,8 @@ void LoopCarriedEdges::modifySUnits(std::vector 
&SUnits,
 !TII->isGlobalMemoryObject(FromMI) &&
 !TII->isGlobalMemoryObject(ToMI) && !isSuccOrder(From, To)) {
   SDep Pred = Dep;
-  Pred.setSUnit(Src);
-  Dst->addPred(Pred);
+  Pred.setSUnit(From);
+  To->addPred(Pred);
 }
   }
 }
diff --git a/llvm/test/CodeGen/Hexagon/swp-load-to-store-forward.mir 
b/llvm/test/CodeGen/Hexagon/swp-load-to-store-forward.mir
new file mode 100644
index 0..2960343564fca
--- /dev/null
+++ b/llvm/test/CodeGen/Hexagon/swp-load-to-store-forward.mir
@@ -0,0 +1,50 @@
+# RUN: llc -mtriple=hexagon -run-pass pipeliner %s -o /dev/null
+
+# Check that edges that violate topological order are not added to the
+# SwingSchedulerDAG. This is a case where the crash was caused by PR 145878.
+
+--- |
+  target triple = "hexagon"
+  
+  define void @crash_145878() {
+  entry:
+br label %loop
+  
+  loop: ; preds = %loop, %entry
+%lsr.iv2 = phi i32 [ %lsr.iv.next, %loop ], [ 1, %entry ]
+%lsr.iv = phi ptr [ %cgep3, %loop ], [ inttoptr (i32 -8 to ptr), %entry ]
+%cgep = getelementptr i8, ptr %lsr.iv, i32 12
+%load = load i32, ptr %cgep, align 4
+store i32 %load, ptr %lsr.iv, align 4
+%lsr.iv.next = add nsw i32 %lsr.iv2, -1
+%iv.cmp.not = icmp eq i32 %lsr.iv.next, 0
+%cgep3 = getelementptr i8, ptr %lsr.iv, i32 -8
+br i1 %iv.cmp.not, label %exit, label %loop
+  
+  exit: ; preds = %loop
+ret void
+  }
+...
+---
+name:crash_145878
+tracksRegLiveness: true
+body: |
+  bb.0.entry:
+successors: %bb.1(0x8000)
+  
+%5:intregs = A2_tfrsi -8
+J2_loop0i %bb.1, 1, implicit-def $lc0, implicit-def $sa0, implicit-def $usr
+  
+  bb.1.loop (machine-block-address-taken):
+successors: %bb.2(0x0400), %bb.1(0x7c00)
+  
+%1:intregs = PHI %5, %bb.0, %3, %bb.1
+%6:intregs = L2_loadri_io %1, 12 :: (load (s32) from %ir.cgep)
+S2_storeri_io %1, 0, killed %6 :: (store (s32) into %ir.lsr.iv)
+%3:intregs = A2_addi %1, -8
+ENDLOOP0 %bb.1, implicit-def $pc, implicit-def $lc0, implicit $sa0, 
implicit $lc0
+J2_jump %bb.2, implicit-def dead $pc
+  
+  bb.2.exit:
+PS_jmpret $r31, implicit-def dead $pc
+...

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 5345dc9 - [RISCV] Don't lose elements from False in vmerge -> vmv peephole (#149720)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

Author: Luke Lau
Date: 2025-07-28T09:30:12+02:00
New Revision: 5345dc9cd35ed8944cfcba8d8423d5cb0c9f2a77

URL: 
https://github.com/llvm/llvm-project/commit/5345dc9cd35ed8944cfcba8d8423d5cb0c9f2a77
DIFF: 
https://github.com/llvm/llvm-project/commit/5345dc9cd35ed8944cfcba8d8423d5cb0c9f2a77.diff

LOG: [RISCV] Don't lose elements from False in vmerge -> vmv peephole (#149720)

In the vmerge peephole, we currently allow different AVLs for the vmerge
and its true operand.
If vmerge's VL > true's VL, vmerge can "preserve" elements from false
that would otherwise be clobbered with a tail agnostic policy on true.

mask1 1 1 1 0 0 0 0
truex x x x|. . . . AVL=4
vmerge  x x x x f f|. . AVL=6

If we convert this to vmv.v.v we will lose those false elements:

mask1 1 1 1 0 0 0 0
truex x x x|. . . . AVL=4
vmv.v.v x x x x . .|. . AVL=6

Fix this by checking that vmerge's AVL is <= true's AVL.

Should fix #149335

(cherry picked from commit eafe31b293a5166522fff4f3e2d88c2b5c881381)

Added: 


Modified: 
llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp
llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-to-vmv.mir
llvm/test/CodeGen/RISCV/rvv/rvv-vmerge-to-vmv.ll

Removed: 




diff  --git a/llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp 
b/llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp
index 84ef53985484f..c1cc19b503deb 100644
--- a/llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp
+++ b/llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp
@@ -434,6 +434,15 @@ bool 
RISCVVectorPeephole::convertSameMaskVMergeToVMv(MachineInstr &MI) {
   if (!isKnownSameDefs(TrueMask.getReg(), MIMask.getReg()))
 return false;
 
+  // Masked off lanes past TrueVL will come from False, and converting to vmv
+  // will lose these lanes unless MIVL <= TrueVL.
+  // TODO: We could relax this for False == Passthru and True policy == TU
+  const MachineOperand &MIVL = 
MI.getOperand(RISCVII::getVLOpNum(MI.getDesc()));
+  const MachineOperand &TrueVL =
+  True->getOperand(RISCVII::getVLOpNum(True->getDesc()));
+  if (!RISCV::isVLKnownLE(MIVL, TrueVL))
+return false;
+
   // True's passthru needs to be equivalent to False
   Register TruePassthruReg = True->getOperand(1).getReg();
   Register FalseReg = MI.getOperand(2).getReg();

diff  --git a/llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-to-vmv.mir 
b/llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-to-vmv.mir
index a050034c63168..a7eaf39793236 100644
--- a/llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-to-vmv.mir
+++ b/llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-to-vmv.mir
@@ -78,12 +78,12 @@ body: |
 ; CHECK-NEXT: %false:vrnov0 = COPY $v9
 ; CHECK-NEXT: %mask:vmv0 = COPY $v0
 ; CHECK-NEXT: %true:vrnov0 = PseudoVADD_VV_M1_MASK %false, $noreg, $noreg, 
%mask, 4, 5 /* e32 */, 0 /* tu, mu */
-; CHECK-NEXT: %x:vr = PseudoVMV_V_V_M1 %pt, %true, 8, 5 /* e32 */, 0 /* 
tu, mu */
+; CHECK-NEXT: %x:vr = PseudoVMV_V_V_M1 %pt, %true, 4, 5 /* e32 */, 0 /* 
tu, mu */
 %pt:vrnov0 = COPY $v8
 %false:vrnov0 = COPY $v9
 %mask:vmv0 = COPY $v0
-%true:vrnov0 = PseudoVADD_VV_M1_MASK %false, $noreg, $noreg, %mask, 4, 5 
/* e32 */, 0 /* tu, mu */
-%x:vrnov0 = PseudoVMERGE_VVM_M1 %pt, %false, %true, %mask, 8, 5 /* e32 */
+%true:vrnov0 = PseudoVADD_VV_M1_MASK %false, $noreg, $noreg, %mask, 8, 5 
/* e32 */, 0 /* tu, mu */
+%x:vrnov0 = PseudoVMERGE_VVM_M1 %pt, %false, %true, %mask, 4, 5 /* e32 */
 ...
 ---
 # Shouldn't be converted because false operands are 
diff erent
@@ -163,3 +163,47 @@ body: |
 %true:vrnov0 = PseudoVADD_VV_M1_MASK $noreg, $noreg, $noreg, %mask, 4, 5 
/* e32 */, 0 /* tu, mu */
   bb.1:
 %5:vrnov0 = PseudoVMERGE_VVM_M1 $noreg, %false, %true, %mask, 4, 5 /* e32 
*/
+...
+---
+# Shouldn't be converted because vmerge adds back in elements from false past 
avl that would be lost if we converted to vmv.v.v
+name: preserve_false
+body: |
+  bb.0:
+liveins: $v8, $v9, $v0, $x8, $x9
+; CHECK-LABEL: name: preserve_false
+; CHECK: liveins: $v8, $v9, $v0, $x8, $x9
+; CHECK-NEXT: {{  $}}
+; CHECK-NEXT: %pt:vrnov0 = COPY $v8
+; CHECK-NEXT: %false:vr = COPY $v9
+; CHECK-NEXT: %mask:vmv0 = COPY $v0
+; CHECK-NEXT: %avl1:gprnox0 = COPY $x8
+; CHECK-NEXT: %avl2:gprnox0 = COPY $x9
+; CHECK-NEXT: %true:vrnov0 = PseudoVADD_VV_M1_MASK $noreg, $noreg, $noreg, 
%mask, %avl1, 5 /* e32 */, 3 /* ta, ma */
+; CHECK-NEXT: [[PseudoVMERGE_VVM_M1_:%[0-9]+]]:vrnov0 = 
PseudoVMERGE_VVM_M1 %pt, %false, %true, %mask, %avl2, 5 /* e32 */
+%pt:vrnov0 = COPY $v8
+%false:vr = COPY $v9
+%mask:vmv0 = COPY $v0
+%avl1:gprnox0 = COPY $x8
+%avl2:gprnox0 = COPY $x9
+%true:vrnov0 = PseudoVADD_VV_M1_MASK $noreg, $noreg, $noreg, %mask, %avl1, 
5 /* e32 */, 3 /* ta, ma */
+%5:vrnov0 = PseudoVMERGE_VVM_M1 %pt, %false, %true, %mask, %avl2, 5 /* e32 
*/
+...
+---
+# But we can

[llvm-branch-commits] [llvm] release/21.x: [RISCV] Don't lose elements from False in vmerge -> vmv peephole (#149720) (PR #149968)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru updated https://github.com/llvm/llvm-project/pull/149968

>From 5345dc9cd35ed8944cfcba8d8423d5cb0c9f2a77 Mon Sep 17 00:00:00 2001
From: Luke Lau 
Date: Tue, 22 Jul 2025 15:21:42 +0800
Subject: [PATCH] [RISCV] Don't lose elements from False in vmerge -> vmv
 peephole (#149720)

In the vmerge peephole, we currently allow different AVLs for the vmerge
and its true operand.
If vmerge's VL > true's VL, vmerge can "preserve" elements from false
that would otherwise be clobbered with a tail agnostic policy on true.

mask1 1 1 1 0 0 0 0
truex x x x|. . . . AVL=4
vmerge  x x x x f f|. . AVL=6

If we convert this to vmv.v.v we will lose those false elements:

mask1 1 1 1 0 0 0 0
truex x x x|. . . . AVL=4
vmv.v.v x x x x . .|. . AVL=6

Fix this by checking that vmerge's AVL is <= true's AVL.

Should fix #149335

(cherry picked from commit eafe31b293a5166522fff4f3e2d88c2b5c881381)
---
 llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp |  9 
 .../RISCV/rvv/rvv-peephole-vmerge-to-vmv.mir  | 50 +--
 .../CodeGen/RISCV/rvv/rvv-vmerge-to-vmv.ll| 35 ++---
 3 files changed, 84 insertions(+), 10 deletions(-)

diff --git a/llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp 
b/llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp
index 84ef53985484f..c1cc19b503deb 100644
--- a/llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp
+++ b/llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp
@@ -434,6 +434,15 @@ bool 
RISCVVectorPeephole::convertSameMaskVMergeToVMv(MachineInstr &MI) {
   if (!isKnownSameDefs(TrueMask.getReg(), MIMask.getReg()))
 return false;
 
+  // Masked off lanes past TrueVL will come from False, and converting to vmv
+  // will lose these lanes unless MIVL <= TrueVL.
+  // TODO: We could relax this for False == Passthru and True policy == TU
+  const MachineOperand &MIVL = 
MI.getOperand(RISCVII::getVLOpNum(MI.getDesc()));
+  const MachineOperand &TrueVL =
+  True->getOperand(RISCVII::getVLOpNum(True->getDesc()));
+  if (!RISCV::isVLKnownLE(MIVL, TrueVL))
+return false;
+
   // True's passthru needs to be equivalent to False
   Register TruePassthruReg = True->getOperand(1).getReg();
   Register FalseReg = MI.getOperand(2).getReg();
diff --git a/llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-to-vmv.mir 
b/llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-to-vmv.mir
index a050034c63168..a7eaf39793236 100644
--- a/llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-to-vmv.mir
+++ b/llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-to-vmv.mir
@@ -78,12 +78,12 @@ body: |
 ; CHECK-NEXT: %false:vrnov0 = COPY $v9
 ; CHECK-NEXT: %mask:vmv0 = COPY $v0
 ; CHECK-NEXT: %true:vrnov0 = PseudoVADD_VV_M1_MASK %false, $noreg, $noreg, 
%mask, 4, 5 /* e32 */, 0 /* tu, mu */
-; CHECK-NEXT: %x:vr = PseudoVMV_V_V_M1 %pt, %true, 8, 5 /* e32 */, 0 /* 
tu, mu */
+; CHECK-NEXT: %x:vr = PseudoVMV_V_V_M1 %pt, %true, 4, 5 /* e32 */, 0 /* 
tu, mu */
 %pt:vrnov0 = COPY $v8
 %false:vrnov0 = COPY $v9
 %mask:vmv0 = COPY $v0
-%true:vrnov0 = PseudoVADD_VV_M1_MASK %false, $noreg, $noreg, %mask, 4, 5 
/* e32 */, 0 /* tu, mu */
-%x:vrnov0 = PseudoVMERGE_VVM_M1 %pt, %false, %true, %mask, 8, 5 /* e32 */
+%true:vrnov0 = PseudoVADD_VV_M1_MASK %false, $noreg, $noreg, %mask, 8, 5 
/* e32 */, 0 /* tu, mu */
+%x:vrnov0 = PseudoVMERGE_VVM_M1 %pt, %false, %true, %mask, 4, 5 /* e32 */
 ...
 ---
 # Shouldn't be converted because false operands are different
@@ -163,3 +163,47 @@ body: |
 %true:vrnov0 = PseudoVADD_VV_M1_MASK $noreg, $noreg, $noreg, %mask, 4, 5 
/* e32 */, 0 /* tu, mu */
   bb.1:
 %5:vrnov0 = PseudoVMERGE_VVM_M1 $noreg, %false, %true, %mask, 4, 5 /* e32 
*/
+...
+---
+# Shouldn't be converted because vmerge adds back in elements from false past 
avl that would be lost if we converted to vmv.v.v
+name: preserve_false
+body: |
+  bb.0:
+liveins: $v8, $v9, $v0, $x8, $x9
+; CHECK-LABEL: name: preserve_false
+; CHECK: liveins: $v8, $v9, $v0, $x8, $x9
+; CHECK-NEXT: {{  $}}
+; CHECK-NEXT: %pt:vrnov0 = COPY $v8
+; CHECK-NEXT: %false:vr = COPY $v9
+; CHECK-NEXT: %mask:vmv0 = COPY $v0
+; CHECK-NEXT: %avl1:gprnox0 = COPY $x8
+; CHECK-NEXT: %avl2:gprnox0 = COPY $x9
+; CHECK-NEXT: %true:vrnov0 = PseudoVADD_VV_M1_MASK $noreg, $noreg, $noreg, 
%mask, %avl1, 5 /* e32 */, 3 /* ta, ma */
+; CHECK-NEXT: [[PseudoVMERGE_VVM_M1_:%[0-9]+]]:vrnov0 = 
PseudoVMERGE_VVM_M1 %pt, %false, %true, %mask, %avl2, 5 /* e32 */
+%pt:vrnov0 = COPY $v8
+%false:vr = COPY $v9
+%mask:vmv0 = COPY $v0
+%avl1:gprnox0 = COPY $x8
+%avl2:gprnox0 = COPY $x9
+%true:vrnov0 = PseudoVADD_VV_M1_MASK $noreg, $noreg, $noreg, %mask, %avl1, 
5 /* e32 */, 3 /* ta, ma */
+%5:vrnov0 = PseudoVMERGE_VVM_M1 %pt, %false, %true, %mask, %avl2, 5 /* e32 
*/
+...
+---
+# But we can convert this one because vmerge's avl being <= true's means we 
don't lose any false elements past avl.
+name: preser

[llvm-branch-commits] [llvm] release/21.x: [RISCV] Don't lose elements from False in vmerge -> vmv peephole (#149720) (PR #149968)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru closed https://github.com/llvm/llvm-project/pull/149968
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] ba5aa84 - [MachinePipeliner] Fix incorrect dependency direction (#149436)

2025-07-28 Thread Tobias Hieta via llvm-branch-commits

Author: Ryotaro Kasuga
Date: 2025-07-28T09:29:43+02:00
New Revision: ba5aa84b543d100df5dafffbf0c9874b592d0c37

URL: 
https://github.com/llvm/llvm-project/commit/ba5aa84b543d100df5dafffbf0c9874b592d0c37
DIFF: 
https://github.com/llvm/llvm-project/commit/ba5aa84b543d100df5dafffbf0c9874b592d0c37.diff

LOG: [MachinePipeliner] Fix incorrect dependency direction (#149436)

This patch fixes a bug introduced in #145878. A dependency was added in
the wrong direction, causing an assertion failure due to broken
topological order.

(cherry picked from commit 6df012ab48ececd27359bdc9448ee101b39eea7a)

Added: 
llvm/test/CodeGen/Hexagon/swp-load-to-store-forward.mir

Modified: 
llvm/lib/CodeGen/MachinePipeliner.cpp

Removed: 




diff  --git a/llvm/lib/CodeGen/MachinePipeliner.cpp 
b/llvm/lib/CodeGen/MachinePipeliner.cpp
index b38a4d1c55af9..90005bd181f3a 100644
--- a/llvm/lib/CodeGen/MachinePipeliner.cpp
+++ b/llvm/lib/CodeGen/MachinePipeliner.cpp
@@ -4279,8 +4279,8 @@ void LoopCarriedEdges::modifySUnits(std::vector 
&SUnits,
 !TII->isGlobalMemoryObject(FromMI) &&
 !TII->isGlobalMemoryObject(ToMI) && !isSuccOrder(From, To)) {
   SDep Pred = Dep;
-  Pred.setSUnit(Src);
-  Dst->addPred(Pred);
+  Pred.setSUnit(From);
+  To->addPred(Pred);
 }
   }
 }

diff  --git a/llvm/test/CodeGen/Hexagon/swp-load-to-store-forward.mir 
b/llvm/test/CodeGen/Hexagon/swp-load-to-store-forward.mir
new file mode 100644
index 0..2960343564fca
--- /dev/null
+++ b/llvm/test/CodeGen/Hexagon/swp-load-to-store-forward.mir
@@ -0,0 +1,50 @@
+# RUN: llc -mtriple=hexagon -run-pass pipeliner %s -o /dev/null
+
+# Check that edges that violate topological order are not added to the
+# SwingSchedulerDAG. This is a case where the crash was caused by PR 145878.
+
+--- |
+  target triple = "hexagon"
+  
+  define void @crash_145878() {
+  entry:
+br label %loop
+  
+  loop: ; preds = %loop, %entry
+%lsr.iv2 = phi i32 [ %lsr.iv.next, %loop ], [ 1, %entry ]
+%lsr.iv = phi ptr [ %cgep3, %loop ], [ inttoptr (i32 -8 to ptr), %entry ]
+%cgep = getelementptr i8, ptr %lsr.iv, i32 12
+%load = load i32, ptr %cgep, align 4
+store i32 %load, ptr %lsr.iv, align 4
+%lsr.iv.next = add nsw i32 %lsr.iv2, -1
+%iv.cmp.not = icmp eq i32 %lsr.iv.next, 0
+%cgep3 = getelementptr i8, ptr %lsr.iv, i32 -8
+br i1 %iv.cmp.not, label %exit, label %loop
+  
+  exit: ; preds = %loop
+ret void
+  }
+...
+---
+name:crash_145878
+tracksRegLiveness: true
+body: |
+  bb.0.entry:
+successors: %bb.1(0x8000)
+  
+%5:intregs = A2_tfrsi -8
+J2_loop0i %bb.1, 1, implicit-def $lc0, implicit-def $sa0, implicit-def $usr
+  
+  bb.1.loop (machine-block-address-taken):
+successors: %bb.2(0x0400), %bb.1(0x7c00)
+  
+%1:intregs = PHI %5, %bb.0, %3, %bb.1
+%6:intregs = L2_loadri_io %1, 12 :: (load (s32) from %ir.cgep)
+S2_storeri_io %1, 0, killed %6 :: (store (s32) into %ir.lsr.iv)
+%3:intregs = A2_addi %1, -8
+ENDLOOP0 %bb.1, implicit-def $pc, implicit-def $lc0, implicit $sa0, 
implicit $lc0
+J2_jump %bb.2, implicit-def dead $pc
+  
+  bb.2.exit:
+PS_jmpret $r31, implicit-def dead $pc
+...



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GISel] Introduce MIFlags::InBounds (PR #150900)

2025-07-28 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-globalisel

Author: Fabian Ritter (ritter-x2a)


Changes

This flag applies to G_PTR_ADD instructions and indicates that the operation
implements an inbounds getelementptr operation, i.e., the pointer operand is in
bounds wrt. the allocated object it is based on, and the arithmetic does not
change that.

It is set when the IRTranslator lowers inbounds GEPs (currently only in some
cases, to be extended with a future PR), and in the
(build|materialize)ObjectPtrOffset functions.

Inbounds information is useful in ISel when we have instructions that perform
address computations whose intermediate steps must be in the same memory region
as the final result. A follow-up patch will start using it for AMDGPU's flat
memory instructions, where the immediate offset must not affect the memory
aperture of the address.

This is analogous to a concurrent effort in SDAG: #131862
(related: #140017, #141725).

For SWDEV-516125.

---

Patch is 4.78 MiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/150900.diff


92 Files Affected:

- (modified) llvm/include/llvm/CodeGen/GlobalISel/GenericMachineInstrs.h (+3-3) 
- (modified) llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h (+2-2) 
- (modified) llvm/include/llvm/CodeGen/MachineInstr.h (+3-1) 
- (modified) llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp (+5-2) 
- (modified) llvm/lib/CodeGen/MIRParser/MILexer.cpp (+1) 
- (modified) llvm/lib/CodeGen/MIRParser/MILexer.h (+1) 
- (modified) llvm/lib/CodeGen/MIRParser/MIParser.cpp (+4-1) 
- (modified) llvm/lib/CodeGen/MIRPrinter.cpp (+2) 
- (modified) llvm/lib/CodeGen/MachineInstr.cpp (+6) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator-gep.ll 
(+4-4) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator-switch.ll 
(+2-2) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll 
(+41-41) 
- (modified) 
llvm/test/CodeGen/AArch64/GlobalISel/call-lowering-sret-demotion.ll (+24-24) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/call-translator-cse.ll (+1-1) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/call-translator-ios.ll (+1-1) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/call-translator.ll (+8-8) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/inline-memcpy-forced.mir 
(+16-16) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/inline-memcpy.mir (+40-40) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/inline-memmove.mir (+24-24) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/inline-memset.mir (+11-11) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/inline-small-memcpy.mir 
(+2-2) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/legalize-and.mir (+12-12) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/legalize-bswap.mir (+3-3) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/legalize-constant.mir (+8-8) 
- (modified) 
llvm/test/CodeGen/AArch64/GlobalISel/legalize-extract-vector-elt.mir (+4-4) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/legalize-fpext.mir (+1-1) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/legalize-fptrunc.mir (+1-1) 
- (modified) 
llvm/test/CodeGen/AArch64/GlobalISel/legalize-insert-vector-elt.mir (+2-2) 
- (modified) 
llvm/test/CodeGen/AArch64/GlobalISel/legalize-load-store-vector.mir (+5-5) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/legalize-load-store.mir 
(+24-24) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/legalize-min-max.mir (+16-16) 
- (modified) 
llvm/test/CodeGen/AArch64/GlobalISel/legalize-non-pow2-load-store.mir (+12-12) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/legalize-or.mir (+4-4) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/legalize-phi.mir (+4-4) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/legalize-shuffle-vector.mir 
(+5-5) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/legalize-vacopy.mir (+6-6) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/legalize-xor.mir (+10-10) 
- (modified) llvm/test/CodeGen/AArch64/arm64-this-return.ll (+1-1) 
- (modified) 
llvm/test/CodeGen/AMDGPU/GlobalISel/bug-legalization-artifact-combiner-dead-def.mir
 (+1-1) 
- (modified) llvm/test/CodeGen/AMDGPU/GlobalISel/function-returns.ll (+12-12) 
- (modified) llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-amdgpu_kernel.ll 
(+2-2) 
- (modified) 
llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call-abi-attribute-hints.ll 
(+3-3) 
- (modified) 
llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call-implicit-args.ll (+16-16) 
- (modified) llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call-non-fixed.ll 
(+2-2) 
- (modified) 
llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call-return-values.ll (+48-48) 
- (modified) llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call-sret.ll 
(+3-3) 
- (modified) llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call.ll (+69-69) 
- (modified) llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-function-args.ll 
(+10-10) 
- (modified) llvm/test/CodeGen/AMDGP

[llvm-branch-commits] [llvm] [GISel] Introduce MIFlags::InBounds (PR #150900)

2025-07-28 Thread Fabian Ritter via llvm-branch-commits

https://github.com/ritter-x2a ready_for_review 
https://github.com/llvm/llvm-project/pull/150900
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [Driver] Default to -mv8plus on 32-bit Solaris/SPARC (#150176) (PR #150898)

2025-07-28 Thread Brad Smith via llvm-branch-commits

https://github.com/brad0 approved this pull request.


https://github.com/llvm/llvm-project/pull/150898
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libunwind] release/21.x: [libunwind] Fix return type of `DwarfFDECache::findFDE()` in definition (#146308) (PR #150126)

2025-07-28 Thread Alex Rønne Petersen via llvm-branch-commits

https://github.com/alexrp updated 
https://github.com/llvm/llvm-project/pull/150126

From cee508a85aa058a1fb0dc99b142843880e98faa1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= 
Date: Wed, 23 Jul 2025 00:03:19 +0200
Subject: [PATCH] [libunwind] Fix return type of `DwarfFDECache::findFDE()` in
 definition (#146308)

Needed to resolve this compilation error on some systems:

lib/libunwind/src/UnwindCursor.hpp:153:38: error: return type of
out-of-line definition of 'libunwind::DwarfFDECache::findFDE' differs
from that in the declaration
typename A::pint_t DwarfFDECache::findFDE(pint_t mh, pint_t pc) {
~^
lib/libunwind/src/libunwind.cpp:31:10: note: in file included from
lib/libunwind/src/libunwind.cpp:31:
#include "UnwindCursor.hpp"
 ^
lib/libunwind/src/UnwindCursor.hpp:100:17: note: previous declaration is
here
  static pint_t findFDE(pint_t mh, pint_t pc);
 ~~~^

(cherry picked from commit eb0d8f9272f7c734cdaf31bc33a18e1619e021e4)
---
 libunwind/src/UnwindCursor.hpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 55db035e62040..9a1afd3721f5a 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -173,7 +173,8 @@ bool DwarfFDECache::_registeredForDyldUnloads = false;
 #endif
 
 template 
-typename A::pint_t DwarfFDECache::findFDE(pint_t mh, pint_t pc) {
+typename DwarfFDECache::pint_t DwarfFDECache::findFDE(pint_t mh,
+pint_t pc) {
   pint_t result = 0;
   _LIBUNWIND_LOG_IF_FALSE(_lock.lock_shared());
   for (entry *p = _buffer; p < _bufferUsed; ++p) {

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/21.x: Revert "[MIPS]Fix QNaNs in the MIPS legacy NaN encodings" (#150773) (PR #150902)

2025-07-28 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-mips

Author: None (llvmbot)


Changes

Backport 525090e83ca392753d371602b5e64f06e7debd9a

Requested by: @nikic

---
Full diff: https://github.com/llvm/llvm-project/pull/150902.diff


4 Files Affected:

- (modified) llvm/lib/Target/Mips/MipsISelLowering.cpp (-29) 
- (modified) llvm/lib/Target/Mips/MipsISelLowering.h (-1) 
- (added) llvm/test/CodeGen/Mips/nan_lowering.ll (+25) 
- (removed) llvm/test/CodeGen/Mips/qnan.ll (-14) 


``diff
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp 
b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index 0e581a7a16503..ec6b382151660 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -522,9 +522,6 @@ MipsTargetLowering::MipsTargetLowering(const 
MipsTargetMachine &TM,
 
   setOperationAction(ISD::TRAP, MVT::Other, Legal);
 
-  setOperationAction(ISD::ConstantFP, MVT::f32, Custom);
-  setOperationAction(ISD::ConstantFP, MVT::f64, Custom);
-
   setTargetDAGCombine({ISD::SDIVREM, ISD::UDIVREM, ISD::SELECT, ISD::AND,
ISD::OR, ISD::ADD, ISD::SUB, ISD::AssertZext, ISD::SHL,
ISD::SIGN_EXTEND});
@@ -1360,8 +1357,6 @@ LowerOperation(SDValue Op, SelectionDAG &DAG) const
   case ISD::FP_TO_SINT: return lowerFP_TO_SINT(Op, DAG);
   case ISD::READCYCLECOUNTER:
 return lowerREADCYCLECOUNTER(Op, DAG);
-  case ISD::ConstantFP:
-return lowerConstantFP(Op, DAG);
   }
   return SDValue();
 }
@@ -3019,30 +3014,6 @@ SDValue MipsTargetLowering::lowerFP_TO_SINT(SDValue Op,
   return DAG.getNode(ISD::BITCAST, SDLoc(Op), Op.getValueType(), Trunc);
 }
 
-SDValue MipsTargetLowering::lowerConstantFP(SDValue Op,
-SelectionDAG &DAG) const {
-  SDLoc DL(Op);
-  EVT VT = Op.getSimpleValueType();
-  SDNode *N = Op.getNode();
-  ConstantFPSDNode *CFP = cast(N);
-
-  if (!CFP->isNaN() || Subtarget.isNaN2008()) {
-return SDValue();
-  }
-
-  APFloat NaNValue = CFP->getValueAPF();
-  auto &Sem = NaNValue.getSemantics();
-
-  // The MSB of the mantissa should be zero for QNaNs in the MIPS legacy NaN
-  // encodings, and one for sNaNs. Check every NaN constants and make sure
-  // they are correctly encoded for legacy encodings.
-  if (!NaNValue.isSignaling()) {
-APFloat RealQNaN = NaNValue.getSNaN(Sem);
-return DAG.getConstantFP(RealQNaN, DL, VT);
-  }
-  return SDValue();
-}
-
 
//===--===//
 //  Calling Convention Implementation
 
//===--===//
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.h 
b/llvm/lib/Target/Mips/MipsISelLowering.h
index 31ac5d4c185bc..c65c76ccffc75 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.h
+++ b/llvm/lib/Target/Mips/MipsISelLowering.h
@@ -592,7 +592,6 @@ class TargetRegisterClass;
 SDValue lowerEH_DWARF_CFA(SDValue Op, SelectionDAG &DAG) const;
 SDValue lowerFP_TO_SINT(SDValue Op, SelectionDAG &DAG) const;
 SDValue lowerREADCYCLECOUNTER(SDValue Op, SelectionDAG &DAG) const;
-SDValue lowerConstantFP(SDValue Op, SelectionDAG &DAG) const;
 
 /// isEligibleForTailCallOptimization - Check whether the call is eligible
 /// for tail call optimization.
diff --git a/llvm/test/CodeGen/Mips/nan_lowering.ll 
b/llvm/test/CodeGen/Mips/nan_lowering.ll
new file mode 100644
index 0..2a11278e14b6c
--- /dev/null
+++ b/llvm/test/CodeGen/Mips/nan_lowering.ll
@@ -0,0 +1,25 @@
+; RUN: llc -mtriple=mips-linux-gnu -mattr=-nan2008 < %s | FileCheck %s
+; RUN: llc -mtriple=mips-linux-gnu -mattr=+nan2008 < %s | FileCheck %s
+
+; Make sure that lowering does not corrupt the value of NaN values,
+; regardless of what the NaN mode is.
+
+define float @test1() {
+; CHECK: .4byte 0x7fc0
+  ret float bitcast (i32 u0x7fc0 to float)
+}
+
+define float @test2() {
+; CHECK: .4byte 0x7fc1
+  ret float bitcast (i32 u0x7fc1 to float)
+}
+
+define float @test3() {
+; CHECK: .4byte 0x7f80
+  ret float bitcast (i32 u0x7f80 to float)
+}
+
+define float @test4() {
+; CHECK: .4byte 0x7f81
+  ret float bitcast (i32 u0x7f81 to float)
+}
diff --git a/llvm/test/CodeGen/Mips/qnan.ll b/llvm/test/CodeGen/Mips/qnan.ll
deleted file mode 100644
index e5b4aa1b42ee7..0
--- a/llvm/test/CodeGen/Mips/qnan.ll
+++ /dev/null
@@ -1,14 +0,0 @@
-; RUN: llc -O3 -mcpu=mips32r2 -mtriple=mips-linux-gnu < %s -o - | FileCheck %s 
-check-prefixes=MIPS_Legacy
-; RUN: llc -O3 -mcpu=mips32r2 -mtriple=mips-linux-gnu -mattr=+nan2008 < %s -o 
- | FileCheck %s -check-prefixes=MIPS_NaN2008
-
-define dso_local float @nan(float noundef %a, float noundef %b) 
local_unnamed_addr #0 {
-; MIPS_Legacy: $CPI0_0:
-; MIPS_Legacy-NEXT: .4byte  0x7fa0 # float NaN
-
-; MIPS_NaN2008: $CPI0_0:
-; MIPS_NaN2008-NEXT: .4byte  0x7fc0 # float NaN
-
-entry:
-  %0 = tail call float @llvm.minimum.f32(float %a, f

[llvm-branch-commits] [llvm] release/21.x: Revert "[MIPS]Fix QNaNs in the MIPS legacy NaN encodings" (#150773) (PR #150902)

2025-07-28 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/150902

Backport 525090e83ca392753d371602b5e64f06e7debd9a

Requested by: @nikic

>From 407df99c3ac41129f3143a5bfe23cfa104232a63 Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Mon, 28 Jul 2025 10:36:40 +0200
Subject: [PATCH] Revert "[MIPS]Fix QNaNs in the MIPS legacy NaN encodings"
 (#150773)

Reverts llvm/llvm-project#139829.

We can't just randomly change the value of constants during lowering.

Fixes https://github.com/llvm/llvm-project/issues/149295.

(cherry picked from commit 525090e83ca392753d371602b5e64f06e7debd9a)
---
 llvm/lib/Target/Mips/MipsISelLowering.cpp | 29 ---
 llvm/lib/Target/Mips/MipsISelLowering.h   |  1 -
 llvm/test/CodeGen/Mips/nan_lowering.ll| 25 +++
 llvm/test/CodeGen/Mips/qnan.ll| 14 ---
 4 files changed, 25 insertions(+), 44 deletions(-)
 create mode 100644 llvm/test/CodeGen/Mips/nan_lowering.ll
 delete mode 100644 llvm/test/CodeGen/Mips/qnan.ll

diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp 
b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index 0e581a7a16503..ec6b382151660 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -522,9 +522,6 @@ MipsTargetLowering::MipsTargetLowering(const 
MipsTargetMachine &TM,
 
   setOperationAction(ISD::TRAP, MVT::Other, Legal);
 
-  setOperationAction(ISD::ConstantFP, MVT::f32, Custom);
-  setOperationAction(ISD::ConstantFP, MVT::f64, Custom);
-
   setTargetDAGCombine({ISD::SDIVREM, ISD::UDIVREM, ISD::SELECT, ISD::AND,
ISD::OR, ISD::ADD, ISD::SUB, ISD::AssertZext, ISD::SHL,
ISD::SIGN_EXTEND});
@@ -1360,8 +1357,6 @@ LowerOperation(SDValue Op, SelectionDAG &DAG) const
   case ISD::FP_TO_SINT: return lowerFP_TO_SINT(Op, DAG);
   case ISD::READCYCLECOUNTER:
 return lowerREADCYCLECOUNTER(Op, DAG);
-  case ISD::ConstantFP:
-return lowerConstantFP(Op, DAG);
   }
   return SDValue();
 }
@@ -3019,30 +3014,6 @@ SDValue MipsTargetLowering::lowerFP_TO_SINT(SDValue Op,
   return DAG.getNode(ISD::BITCAST, SDLoc(Op), Op.getValueType(), Trunc);
 }
 
-SDValue MipsTargetLowering::lowerConstantFP(SDValue Op,
-SelectionDAG &DAG) const {
-  SDLoc DL(Op);
-  EVT VT = Op.getSimpleValueType();
-  SDNode *N = Op.getNode();
-  ConstantFPSDNode *CFP = cast(N);
-
-  if (!CFP->isNaN() || Subtarget.isNaN2008()) {
-return SDValue();
-  }
-
-  APFloat NaNValue = CFP->getValueAPF();
-  auto &Sem = NaNValue.getSemantics();
-
-  // The MSB of the mantissa should be zero for QNaNs in the MIPS legacy NaN
-  // encodings, and one for sNaNs. Check every NaN constants and make sure
-  // they are correctly encoded for legacy encodings.
-  if (!NaNValue.isSignaling()) {
-APFloat RealQNaN = NaNValue.getSNaN(Sem);
-return DAG.getConstantFP(RealQNaN, DL, VT);
-  }
-  return SDValue();
-}
-
 
//===--===//
 //  Calling Convention Implementation
 
//===--===//
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.h 
b/llvm/lib/Target/Mips/MipsISelLowering.h
index 31ac5d4c185bc..c65c76ccffc75 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.h
+++ b/llvm/lib/Target/Mips/MipsISelLowering.h
@@ -592,7 +592,6 @@ class TargetRegisterClass;
 SDValue lowerEH_DWARF_CFA(SDValue Op, SelectionDAG &DAG) const;
 SDValue lowerFP_TO_SINT(SDValue Op, SelectionDAG &DAG) const;
 SDValue lowerREADCYCLECOUNTER(SDValue Op, SelectionDAG &DAG) const;
-SDValue lowerConstantFP(SDValue Op, SelectionDAG &DAG) const;
 
 /// isEligibleForTailCallOptimization - Check whether the call is eligible
 /// for tail call optimization.
diff --git a/llvm/test/CodeGen/Mips/nan_lowering.ll 
b/llvm/test/CodeGen/Mips/nan_lowering.ll
new file mode 100644
index 0..2a11278e14b6c
--- /dev/null
+++ b/llvm/test/CodeGen/Mips/nan_lowering.ll
@@ -0,0 +1,25 @@
+; RUN: llc -mtriple=mips-linux-gnu -mattr=-nan2008 < %s | FileCheck %s
+; RUN: llc -mtriple=mips-linux-gnu -mattr=+nan2008 < %s | FileCheck %s
+
+; Make sure that lowering does not corrupt the value of NaN values,
+; regardless of what the NaN mode is.
+
+define float @test1() {
+; CHECK: .4byte 0x7fc0
+  ret float bitcast (i32 u0x7fc0 to float)
+}
+
+define float @test2() {
+; CHECK: .4byte 0x7fc1
+  ret float bitcast (i32 u0x7fc1 to float)
+}
+
+define float @test3() {
+; CHECK: .4byte 0x7f80
+  ret float bitcast (i32 u0x7f80 to float)
+}
+
+define float @test4() {
+; CHECK: .4byte 0x7f81
+  ret float bitcast (i32 u0x7f81 to float)
+}
diff --git a/llvm/test/CodeGen/Mips/qnan.ll b/llvm/test/CodeGen/Mips/qnan.ll
deleted file mode 100644
index e5b4aa1b42ee7..0
--- a/llvm/test/CodeGen/Mips/qnan.ll
+++ /dev/null
@@ -1,14 +0,0 @@
-; RUN: llc -O3 

[llvm-branch-commits] [llvm] release/21.x: Revert "[MIPS]Fix QNaNs in the MIPS legacy NaN encodings" (#150773) (PR #150902)

2025-07-28 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/150902
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/21.x: Revert "[MIPS]Fix QNaNs in the MIPS legacy NaN encodings" (#150773) (PR #150902)

2025-07-28 Thread via llvm-branch-commits

llvmbot wrote:

@arsenm What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/150902
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [AMDGPU] Propagate Constants for Wave Reduction Intrinsics (PR #150395)

2025-07-28 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm approved this pull request.


https://github.com/llvm/llvm-project/pull/150395
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


  1   2   3   4   >