[llvm-branch-commits] [clang] [clang][DebugInfo] Disable VTable debug info (#130255) on COFF platforms (PR #150938)
https://github.com/jmorse approved this pull request. LGTM with a minor test question to confirm my understanding. https://github.com/llvm/llvm-project/pull/150938 ___ llvm-branch-commits mailing list [email protected] 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)
https://github.com/jmorse edited https://github.com/llvm/llvm-project/pull/150938 ___ llvm-branch-commits mailing list [email protected] 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)
@@ -222,3 +222,8 @@ void foo() {
// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "A",
// CHECK-SAME: DIFlagFwdDecl
+
+// There is a full definition of the type available in the module.
+// CHECKCOFF: !DICompositeType(tag: DW_TAG_structure_type, name: "Virtual",
+// CHECKCOFF-SAME: DIFlagFwdDecl
+// CHECKCOFF-SAME: identifier: "_ZTS7Virtual")
jmorse wrote:
If I'm reading this correctly, the DICompositeType is identical to the ELF
DICompositeType earlier, but presumably it's in a different location in the
output because it's no longer attached to a global variable?
If that's true, then this test coverage is somewhat indirectly covering that
behaviour -- but I think it's fine because the
vtable-debug-info-inheritance-simple.cpp is precisely checking the behaviour.
https://github.com/llvm/llvm-project/pull/150938
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/21.x: [C23] Handle type compatibility for enumerations better (#150282) (PR #151137)
https://github.com/llvmbot created
https://github.com/llvm/llvm-project/pull/151137
Backport 315e2e2
Requested by: @AaronBallman
>From c487f6343852f141e5bf46ea4c7d7a39015dccfc Mon Sep 17 00:00:00 2001
From: Aaron Ballman
Date: Tue, 29 Jul 2025 08:20:59 -0400
Subject: [PATCH] [C23] Handle type compatibility for enumerations better
(#150282)
An enumeration is compatible with its underlying type, which means that
code like the following should be accepted:
struct A { int h; };
void func() {
extern struct A x;
enum E : int { e };
struct A { enum E h; };
extern struct A x;
}
because the structures are declared in different scopes, the two
declarations of 'x' are both compatible.
Note, the structural equivalence checker does not take scope into
account, but that is something the C standard requires. This means we
are accepting code we should be rejecting per the standard, like:
void func() {
struct A { int h; };
extern struct A x;
enum E : int { e };
struct A { enum E h; };
extern struct A x;
}
Because the structures are declared in the same scope, the type
compatibility rule require the structures to use the same types, not
merely compatible ones.
Fixes #149965
(cherry picked from commit 315e2e28b13285a352d409b739ba31fb453d661b)
---
clang/lib/AST/ASTStructuralEquivalence.cpp | 24 ++-
clang/test/C/C23/n3037.c | 36 ++
2 files changed, 59 insertions(+), 1 deletion(-)
diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 3aa6b37844103..f8996b264ed7b 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -873,7 +873,29 @@ static bool
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
else if (T1->getTypeClass() == Type::FunctionNoProto &&
T2->getTypeClass() == Type::FunctionProto)
TC = Type::FunctionNoProto;
-else
+else if (Context.LangOpts.C23 && !Context.StrictTypeSpelling &&
+ (T1->getTypeClass() == Type::Enum ||
+ T2->getTypeClass() == Type::Enum)) {
+ // In C23, if not being strict about token equivalence, we need to handle
+ // the case where one type is an enumeration and the other type is an
+ // integral type.
+ //
+ // C23 6.7.3.3p16: The enumerated type is compatible with the underlying
+ // type of the enumeration.
+ //
+ // Treat the enumeration as its underlying type and use the builtin type
+ // class comparison.
+ if (T1->getTypeClass() == Type::Enum) {
+T1 = T1->getAs()->getDecl()->getIntegerType();
+if (!T2->isBuiltinType() || T1.isNull()) // Sanity check
+ return false;
+ } else if (T2->getTypeClass() == Type::Enum) {
+T2 = T2->getAs()->getDecl()->getIntegerType();
+if (!T1->isBuiltinType() || T2.isNull()) // Sanity check
+ return false;
+ }
+ TC = Type::Builtin;
+} else
return false;
}
diff --git a/clang/test/C/C23/n3037.c b/clang/test/C/C23/n3037.c
index ce6f4c4ea7acf..c5828133cee2e 100644
--- a/clang/test/C/C23/n3037.c
+++ b/clang/test/C/C23/n3037.c
@@ -401,3 +401,39 @@ _Static_assert(0 == _Generic(inner_anon_tagged.untagged,
struct { int i; } : 1,
// unions and structures are both RecordDecl objects, whereas EnumDecl is not).
enum { E_Untagged1 } nontag_enum; // both-note {{previous definition is here}}
_Static_assert(0 == _Generic(nontag_enum, enum { E_Untagged1 } : 1, default :
0)); // both-error {{redefinition of enumerator 'E_Untagged1'}}
+
+// Test that enumerations are compatible with their underlying type, but still
+// diagnose when "same type" is required rather than merely "compatible type".
+enum E1 : int { e1 }; // Fixed underlying type
+enum E2 { e2 }; // Unfixed underlying type, defaults to int or unsigned
int
+
+struct GH149965_1 { int h; };
+// This typeof trick is used to get the underlying type of the enumeration in a
+// platform agnostic way.
+struct GH149965_2 { __typeof__(+(enum E2){}) h; };
+void gh149965(void) {
+ extern struct GH149965_1 x1; // c17-note {{previous declaration is here}}
+ extern struct GH149965_2 x2; // c17-note {{previous declaration is here}}
+
+ // Both the structure and the variable declarations are fine because only a
+ // compatible type is required, not the same type, because the structures are
+ // declared in different scopes.
+ struct GH149965_1 { enum E1 h; };
+ struct GH149965_2 { enum E2 h; };
+
+ extern struct GH149965_1 x1; // c17-error {{redeclaration of 'x1'}}
+ extern struct GH149965_2 x2; // c17-error {{redeclaration of 'x2'}}
+
+ // However, in the same scope, the same type is required, not just compatible
+ // types.
+ // FIXME: this should be an error in both C17 and C23 mode.
+ struct GH149965_3 { int h; }; // c17-note {{previous definition is here}}
+ struct GH149965_3 { enum E1 h;
[llvm-branch-commits] [clang] release/21.x: [C23] Handle type compatibility for enumerations better (#150282) (PR #151137)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/151137 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/21.x: [C23] Handle type compatibility for enumerations better (#150282) (PR #151137)
llvmbot wrote: @Sirraide What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/151137 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/21.x: [C23] Handle type compatibility for enumerations better (#150282) (PR #151137)
llvmbot wrote:
@llvm/pr-subscribers-clang
Author: None (llvmbot)
Changes
Backport 315e2e2
Requested by: @AaronBallman
---
Full diff: https://github.com/llvm/llvm-project/pull/151137.diff
2 Files Affected:
- (modified) clang/lib/AST/ASTStructuralEquivalence.cpp (+23-1)
- (modified) clang/test/C/C23/n3037.c (+36)
``diff
diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 3aa6b37844103..f8996b264ed7b 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -873,7 +873,29 @@ static bool
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
else if (T1->getTypeClass() == Type::FunctionNoProto &&
T2->getTypeClass() == Type::FunctionProto)
TC = Type::FunctionNoProto;
-else
+else if (Context.LangOpts.C23 && !Context.StrictTypeSpelling &&
+ (T1->getTypeClass() == Type::Enum ||
+ T2->getTypeClass() == Type::Enum)) {
+ // In C23, if not being strict about token equivalence, we need to handle
+ // the case where one type is an enumeration and the other type is an
+ // integral type.
+ //
+ // C23 6.7.3.3p16: The enumerated type is compatible with the underlying
+ // type of the enumeration.
+ //
+ // Treat the enumeration as its underlying type and use the builtin type
+ // class comparison.
+ if (T1->getTypeClass() == Type::Enum) {
+T1 = T1->getAs()->getDecl()->getIntegerType();
+if (!T2->isBuiltinType() || T1.isNull()) // Sanity check
+ return false;
+ } else if (T2->getTypeClass() == Type::Enum) {
+T2 = T2->getAs()->getDecl()->getIntegerType();
+if (!T1->isBuiltinType() || T2.isNull()) // Sanity check
+ return false;
+ }
+ TC = Type::Builtin;
+} else
return false;
}
diff --git a/clang/test/C/C23/n3037.c b/clang/test/C/C23/n3037.c
index ce6f4c4ea7acf..c5828133cee2e 100644
--- a/clang/test/C/C23/n3037.c
+++ b/clang/test/C/C23/n3037.c
@@ -401,3 +401,39 @@ _Static_assert(0 == _Generic(inner_anon_tagged.untagged,
struct { int i; } : 1,
// unions and structures are both RecordDecl objects, whereas EnumDecl is not).
enum { E_Untagged1 } nontag_enum; // both-note {{previous definition is here}}
_Static_assert(0 == _Generic(nontag_enum, enum { E_Untagged1 } : 1, default :
0)); // both-error {{redefinition of enumerator 'E_Untagged1'}}
+
+// Test that enumerations are compatible with their underlying type, but still
+// diagnose when "same type" is required rather than merely "compatible type".
+enum E1 : int { e1 }; // Fixed underlying type
+enum E2 { e2 }; // Unfixed underlying type, defaults to int or unsigned
int
+
+struct GH149965_1 { int h; };
+// This typeof trick is used to get the underlying type of the enumeration in a
+// platform agnostic way.
+struct GH149965_2 { __typeof__(+(enum E2){}) h; };
+void gh149965(void) {
+ extern struct GH149965_1 x1; // c17-note {{previous declaration is here}}
+ extern struct GH149965_2 x2; // c17-note {{previous declaration is here}}
+
+ // Both the structure and the variable declarations are fine because only a
+ // compatible type is required, not the same type, because the structures are
+ // declared in different scopes.
+ struct GH149965_1 { enum E1 h; };
+ struct GH149965_2 { enum E2 h; };
+
+ extern struct GH149965_1 x1; // c17-error {{redeclaration of 'x1'}}
+ extern struct GH149965_2 x2; // c17-error {{redeclaration of 'x2'}}
+
+ // However, in the same scope, the same type is required, not just compatible
+ // types.
+ // FIXME: this should be an error in both C17 and C23 mode.
+ struct GH149965_3 { int h; }; // c17-note {{previous definition is here}}
+ struct GH149965_3 { enum E1 h; }; // c17-error {{redefinition of
'GH149965_3'}}
+
+ // For Clang, the composite type after declaration merging is the enumeration
+ // type rather than an integer type.
+ enum E1 *eptr;
+ [[maybe_unused]] __typeof__(x1.h) *ptr = eptr;
+ enum E2 *eptr2;
+ [[maybe_unused]] __typeof__(x2.h) *ptr2 = eptr2;
+}
``
https://github.com/llvm/llvm-project/pull/151137
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/21.x: [Clang] Fix a partial ordering bug involving CTAD injected template arguments (#149782) (PR #151075)
https://github.com/cor3ntin approved this pull request. https://github.com/llvm/llvm-project/pull/151075 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lldb] release/21.x: [lldb][AArch64][Linux] Show MTE store only setting in mte_ctrl (#145033) (PR #151111)
DavidSpickett wrote: My pitch for backporting this is that it was intended to make this branch but missed it by a couple of weeks. It displays a new feature bit in a Linux control register, if the hardware has FEAT_MTE_STORE_ONLY. So the impact of a bug here is very low, and only visible on that niche hardware. I'll add a release note via. PR to 21.x if this backport is accepted. If not, I'll note it on main. https://github.com/llvm/llvm-project/pull/15 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] f7ac2b8 - Revert "[mlir][core] Move `InitAll***` implementation into static library. (#…"
Author: Mehdi Amini
Date: 2025-07-29T12:26:11+02:00
New Revision: f7ac2b89efa61b44c42dad62ae71a43733d895f4
URL:
https://github.com/llvm/llvm-project/commit/f7ac2b89efa61b44c42dad62ae71a43733d895f4
DIFF:
https://github.com/llvm/llvm-project/commit/f7ac2b89efa61b44c42dad62ae71a43733d895f4.diff
LOG: Revert "[mlir][core] Move `InitAll***` implementation into static library.
(#…"
This reverts commit ace42cf063a52d097f505b7d9afeb53d02bc04db.
Added:
Modified:
clang/tools/cir-lsp-server/CMakeLists.txt
clang/tools/cir-opt/cir-opt.cpp
flang/include/flang/Optimizer/Support/InitFIR.h
flang/lib/Optimizer/Support/CMakeLists.txt
mlir/examples/standalone/standalone-opt/CMakeLists.txt
mlir/examples/standalone/standalone-opt/standalone-opt.cpp
mlir/examples/toy/Ch5/CMakeLists.txt
mlir/examples/toy/Ch5/toyc.cpp
mlir/examples/toy/Ch6/CMakeLists.txt
mlir/examples/toy/Ch6/toyc.cpp
mlir/examples/toy/Ch7/CMakeLists.txt
mlir/examples/toy/Ch7/toyc.cpp
mlir/examples/transform-opt/CMakeLists.txt
mlir/examples/transform-opt/mlir-transform-opt.cpp
mlir/include/mlir/InitAllDialects.h
mlir/include/mlir/InitAllExtensions.h
mlir/include/mlir/InitAllPasses.h
mlir/lib/CAPI/RegisterEverything/CMakeLists.txt
mlir/lib/CMakeLists.txt
mlir/tools/mlir-lsp-server/CMakeLists.txt
mlir/tools/mlir-lsp-server/mlir-lsp-server.cpp
mlir/tools/mlir-opt/CMakeLists.txt
mlir/tools/mlir-query/CMakeLists.txt
mlir/tools/mlir-reduce/CMakeLists.txt
mlir/tools/mlir-rewrite/CMakeLists.txt
mlir/tools/mlir-rewrite/mlir-rewrite.cpp
mlir/unittests/ExecutionEngine/CMakeLists.txt
mlir/unittests/Target/LLVM/CMakeLists.txt
Removed:
mlir/lib/RegisterAllDialects.cpp
mlir/lib/RegisterAllExtensions.cpp
mlir/lib/RegisterAllPasses.cpp
diff --git a/clang/tools/cir-lsp-server/CMakeLists.txt
b/clang/tools/cir-lsp-server/CMakeLists.txt
index f421215173e62..aad2646ce0187 100644
--- a/clang/tools/cir-lsp-server/CMakeLists.txt
+++ b/clang/tools/cir-lsp-server/CMakeLists.txt
@@ -1,23 +1,26 @@
+get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
+get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
+
include_directories(${LLVM_MAIN_SRC_DIR}/../mlir/include)
include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include)
set(LIBS
+ ${dialect_libs}
+ ${conversion_libs}
${test_libs}
clangCIR
clangCIRLoweringDirectToLLVM
+ MLIRCIR
MLIRAffineAnalysis
MLIRAnalysis
- MLIRCIR
MLIRDialect
- MLIRIR
MLIRLspServerLib
MLIRParser
MLIRPass
- MLIRRegisterAllDialects
- MLIRRegisterAllPasses
- MLIRSupport
- MLIRTransformUtils
MLIRTransforms
+ MLIRTransformUtils
+ MLIRSupport
+ MLIRIR
)
add_mlir_tool(cir-lsp-server
diff --git a/clang/tools/cir-opt/cir-opt.cpp b/clang/tools/cir-opt/cir-opt.cpp
index c4d29a2117c75..3dad3b18f7082 100644
--- a/clang/tools/cir-opt/cir-opt.cpp
+++ b/clang/tools/cir-opt/cir-opt.cpp
@@ -17,12 +17,11 @@
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
-#include "mlir/IR/BuiltinDialect.h"
+#include "mlir/InitAllPasses.h"
#include "mlir/Pass/PassManager.h"
#include "mlir/Pass/PassOptions.h"
#include "mlir/Pass/PassRegistry.h"
#include "mlir/Tools/mlir-opt/MlirOptMain.h"
-#include "mlir/Transforms/Passes.h"
#include "clang/CIR/Dialect/IR/CIRDialect.h"
#include "clang/CIR/Dialect/Passes.h"
#include "clang/CIR/Passes.h"
diff --git a/flang/include/flang/Optimizer/Support/InitFIR.h
b/flang/include/flang/Optimizer/Support/InitFIR.h
index 3e42ffd41591e..aacba233a2b32 100644
--- a/flang/include/flang/Optimizer/Support/InitFIR.h
+++ b/flang/include/flang/Optimizer/Support/InitFIR.h
@@ -20,20 +20,12 @@
#include "flang/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.h"
#include "flang/Optimizer/OpenMP/Support/RegisterOpenMPExtensions.h"
#include "mlir/Conversion/Passes.h"
-#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Affine/Passes.h"
#include "mlir/Dialect/Complex/IR/Complex.h"
-#include "mlir/Dialect/ControlFlow/IR/ControlFlow.h"
-#include "mlir/Dialect/DLTI/DLTI.h"
#include "mlir/Dialect/Func/Extensions/InlinerExtension.h"
-#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/Index/IR/IndexDialect.h"
#include "mlir/Dialect/LLVMIR/NVVMDialect.h"
-#include "mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h"
-#include "mlir/Dialect/Math/IR/Math.h"
-#include "mlir/Dialect/OpenACC/OpenACC.h"
#include "mlir/Dialect/OpenACC/Transforms/Passes.h"
-#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/Dialect/SCF/Transforms/Passes.h"
#include "mlir/InitAllDialects.h"
#include "mlir/Pass/Pass.h"
diff --git a/flang/lib/Optimizer/Support/CMakeLists.txt
b/flang/lib/Optimizer/Support/CMakeLists.txt
index 38038e1e9821d..7ccdd4fd9c25c 100644
--- a/flang/lib/Optimizer/
[llvm-branch-commits] [libcxx] [libcxxabi] [llvm] release/21.x: [libc++][hardening] Introduce assertion semantics. (#149459) (PR #151095)
var-const wrote: Reason for cherry-picking: this patch is a follow-up to https://github.com/llvm/llvm-project/pull/150481 and the same rationale applies: we want to gain real-world experience with this under the experimental flag to allow us to roll this out in the next release. https://github.com/llvm/llvm-project/pull/151095 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] release/21.x: [PAC][compiler-rt] Fix init/fini array signing schema (#150691) (PR #151096)
https://github.com/llvmbot created
https://github.com/llvm/llvm-project/pull/151096
Backport 19ba224fb8a925d095d84836bc9896bf564dfd99
Requested by: @kovdan01
>From c86dd3da51444d4f1b4110c0276c7edbe96b77ad Mon Sep 17 00:00:00 2001
From: Daniil Kovalev
Date: Tue, 29 Jul 2025 07:29:04 +0300
Subject: [PATCH] [PAC][compiler-rt] Fix init/fini array signing schema
(#150691)
When `ptrauth_calls` is present but `ptrauth_init_fini` is not, compiler
emits raw unsigned pointers in `.init_array`/`.fini_array` sections.
Previously, `__do_init`/`__do_fini` pointers, which are explicitly added
to the sections, were implicitly signed (due to the presense of
`ptrauth_calls`), while all the other pointers in the sections were
implicitly added by the compiler and thus non-signed.. As a result, the
sections contained a mix of unsigned function pointers and function
pointers signed with default signing schema.
This patch introduces use of inline assembly for this particular case,
so we can manually specify that we do not want to sign the pointers.
Note that we cannot use `__builtin_ptrauth_strip` for this purpose since
its result is not a constant expression.
(cherry picked from commit 19ba224fb8a925d095d84836bc9896bf564dfd99)
---
compiler-rt/lib/builtins/crtbegin.c | 46 +
1 file changed, 34 insertions(+), 12 deletions(-)
diff --git a/compiler-rt/lib/builtins/crtbegin.c
b/compiler-rt/lib/builtins/crtbegin.c
index d5f7756308b09..447474bd0b692 100644
--- a/compiler-rt/lib/builtins/crtbegin.c
+++ b/compiler-rt/lib/builtins/crtbegin.c
@@ -54,22 +54,33 @@ static void __attribute__((used)) __do_init(void) {
}
#ifdef CRT_HAS_INITFINI_ARRAY
-#if __has_feature(ptrauth_init_fini)
+# if __has_feature(ptrauth_init_fini)
// TODO: use __ptrauth-qualified pointers when they are supported on clang side
-#if __has_feature(ptrauth_init_fini_address_discrimination)
+# if __has_feature(ptrauth_init_fini_address_discrimination)
__attribute__((section(".init_array"), used)) static void *__init =
ptrauth_sign_constant(&__do_init, ptrauth_key_init_fini_pointer,
ptrauth_blend_discriminator(
&__init, __ptrauth_init_fini_discriminator));
-#else
+# else
__attribute__((section(".init_array"), used)) static void *__init =
ptrauth_sign_constant(&__do_init, ptrauth_key_init_fini_pointer,
__ptrauth_init_fini_discriminator);
-#endif
-#else
+# endif
+# elif __has_feature(ptrauth_calls)
+# ifdef __aarch64__
+// If ptrauth_init_fini feature is not present, compiler emits raw unsigned
+// pointers in .init_array. Use inline assembly to avoid implicit signing of
+// __do_init function pointer with ptrauth_calls enabled.
+__asm__(".pushsection .init_array,\"aw\",@init_array\n\t"
+".xword __do_init\n\t"
+".popsection");
+# else
+# error "ptrauth_calls is only supported for AArch64"
+# endif
+# else
__attribute__((section(".init_array"),
used)) static void (*__init)(void) = __do_init;
-#endif
+# endif
#elif defined(__i386__) || defined(__x86_64__)
__asm__(".pushsection .init,\"ax\",@progbits\n\t"
"call __do_init\n\t"
@@ -125,22 +136,33 @@ static void __attribute__((used)) __do_fini(void) {
}
#ifdef CRT_HAS_INITFINI_ARRAY
-#if __has_feature(ptrauth_init_fini)
+# if __has_feature(ptrauth_init_fini)
// TODO: use __ptrauth-qualified pointers when they are supported on clang side
-#if __has_feature(ptrauth_init_fini_address_discrimination)
+# if __has_feature(ptrauth_init_fini_address_discrimination)
__attribute__((section(".fini_array"), used)) static void *__fini =
ptrauth_sign_constant(&__do_fini, ptrauth_key_init_fini_pointer,
ptrauth_blend_discriminator(
&__fini, __ptrauth_init_fini_discriminator));
-#else
+# else
__attribute__((section(".fini_array"), used)) static void *__fini =
ptrauth_sign_constant(&__do_fini, ptrauth_key_init_fini_pointer,
__ptrauth_init_fini_discriminator);
-#endif
-#else
+# endif
+# elif __has_feature(ptrauth_calls)
+# ifdef __aarch64__
+// If ptrauth_init_fini feature is not present, compiler emits raw unsigned
+// pointers in .fini_array. Use inline assembly to avoid implicit signing of
+// __do_fini function pointer with ptrauth_calls enabled.
+__asm__(".pushsection .fini_array,\"aw\",@fini_array\n\t"
+".xword __do_fini\n\t"
+".popsection");
+# else
+# error "ptrauth_calls is only supported for AArch64"
+# endif
+# else
__attribute__((section(".fini_array"),
used)) static void (*__fini)(void) = __do_fini;
-#endif
+# endif
#elif defined(__i386__) || defined(__x86_64__)
__asm__(".pushsection .fini,\"ax\",@progbits\n\t"
"call __do_fini\n\t"
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinf
[llvm-branch-commits] [compiler-rt] release/21.x: [PAC][compiler-rt] Fix init/fini array signing schema (#150691) (PR #151096)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/151096 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] release/21.x: [PAC][compiler-rt] Fix init/fini array signing schema (#150691) (PR #151096)
llvmbot wrote: @atrosinenko What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/151096 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [libcxx] [libcxxabi] [llvm] release/21.x: [libc++][hardening] Introduce assertion semantics. (#149459) (PR #151095)
https://github.com/var-const approved this pull request. https://github.com/llvm/llvm-project/pull/151095 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [libcxx] [libcxxabi] [llvm] release/21.x: [libc++][hardening] Introduce assertion semantics. (#149459) (PR #151095)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/151095 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [libcxx] [libcxxabi] [llvm] release/21.x: [libc++][hardening] Introduce assertion semantics. (#149459) (PR #151095)
llvmbot wrote: @var-const What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/151095 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [libcxx] [libcxxabi] [llvm] release/21.x: [libc++][hardening] Introduce assertion semantics. (#149459) (PR #151095)
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/151095 Backport 3eee9fc2c4d1973904b1a26fa96a8c7473ef6a5e Requested by: @var-const >From 99dcfce5806ed04be8f9e844768ba8727e8044fb Mon Sep 17 00:00:00 2001 From: Konstantin Varlamov Date: Tue, 29 Jul 2025 00:19:15 -0700 Subject: [PATCH] [libc++][hardening] Introduce assertion semantics. (#149459) Assertion semantics closely mimic C++26 Contracts evaluation semantics. This brings our implementation closer in line with C++26 Library Hardening (one particular benefit is that using the `observe` semantic makes adopting hardening easier for projects). (cherry picked from commit 3eee9fc2c4d1973904b1a26fa96a8c7473ef6a5e) --- .github/workflows/libcxx-build-and-test.yaml | 1 + ...ning-mode-extensive-observe-semantic.cmake | 2 + libcxx/docs/Hardening.rst | 68 + libcxx/docs/ReleaseNotes/21.rst | 6 + libcxx/docs/UserDocumentation.rst | 5 + libcxx/include/__config | 90 +--- libcxx/include/__cxx03/__config | 4 + .../thread.barrier/assert.arrive.pass.cpp | 2 + .../assert.arrive_and_wait.pass.cpp | 2 + libcxx/test/support/check_assertion.h | 137 +++--- .../test_check_assertion.pass.cpp | 20 ++- libcxx/utils/ci/run-buildbot | 6 + libcxx/utils/libcxx/test/params.py| 19 +++ .../vendor/llvm/default_assertion_handler.in | 35 - libcxxabi/src/demangle/DemangleConfig.h | 8 + 15 files changed, 353 insertions(+), 52 deletions(-) create mode 100644 libcxx/cmake/caches/Generic-hardening-mode-extensive-observe-semantic.cmake diff --git a/.github/workflows/libcxx-build-and-test.yaml b/.github/workflows/libcxx-build-and-test.yaml index a5be912b1ab07..7c18560bd163a 100644 --- a/.github/workflows/libcxx-build-and-test.yaml +++ b/.github/workflows/libcxx-build-and-test.yaml @@ -128,6 +128,7 @@ jobs: 'generic-abi-unstable', 'generic-hardening-mode-debug', 'generic-hardening-mode-extensive', + 'generic-hardening-mode-extensive-observe-semantic', 'generic-hardening-mode-fast', 'generic-hardening-mode-fast-with-abi-breaks', 'generic-merged', diff --git a/libcxx/cmake/caches/Generic-hardening-mode-extensive-observe-semantic.cmake b/libcxx/cmake/caches/Generic-hardening-mode-extensive-observe-semantic.cmake new file mode 100644 index 0..c843c02977a87 --- /dev/null +++ b/libcxx/cmake/caches/Generic-hardening-mode-extensive-observe-semantic.cmake @@ -0,0 +1,2 @@ +set(LIBCXX_HARDENING_MODE "extensive" CACHE STRING "") +set(LIBCXX_TEST_PARAMS "assertion_semantic=observe" CACHE STRING "") diff --git a/libcxx/docs/Hardening.rst b/libcxx/docs/Hardening.rst index 17808841bd9ec..1cdb3605c38ab 100644 --- a/libcxx/docs/Hardening.rst +++ b/libcxx/docs/Hardening.rst @@ -39,6 +39,8 @@ modes are: Enabling hardening has no impact on the ABI. +.. _notes-for-users: + Notes for users --- @@ -72,6 +74,10 @@ to control the level by passing **one** of the following options to the compiler pre-built components. Most libc++ code is header-based, so a user-provided value for ``_LIBCPP_HARDENING_MODE`` will be mostly respected. +In some cases, users might want to override the assertion semantic used by the +library. This can be done similarly to setting the hardening mode; please refer +to the :ref:`relevant section `. + Notes for vendors - @@ -260,6 +266,68 @@ output. This is less secure and increases the size of the binary (among other things, it has to store the error message strings) but makes the failure easier to debug. It also allows testing the error messages in our test suite. +This default behavior can be customized by users via :ref:`assertion semantics +`; it can also be completely overridden by vendors by +providing a :ref:`custom assertion failure handler +`. + +.. _assertion-semantics: + +Assertion semantics +--- + +.. warning:: + + Assertion semantics are currently an experimental feature. + +.. note:: + + Assertion semantics are not available in the C++03 mode. + +What happens when an assertion fails depends on the assertion semantic being +used. Four assertion semantics are available, based on C++26 Contracts +evaluation semantics: + +- ``ignore`` evaluates the assertion but has no effect if it fails (note that it + differs from the Contracts ``ignore`` semantic which would not evaluate + the assertion at all); +- ``observe`` logs an error (indicating, if possible on the platform, that the + error is fatal) but continues execution; +- ``quick-enforce`` terminates the program as fast as possible via a trap + instruction. It is the default semantic for the production modes (``fast`` and + ``extensive``); +- ``enforce`` logs an error and then terminates the program. It is the def
[llvm-branch-commits] [libcxx] [libcxxabi] [llvm] release/21.x: [libc++][hardening] Introduce assertion semantics. (#149459) (PR #151095)
llvmbot wrote: @llvm/pr-subscribers-github-workflow Author: None (llvmbot) Changes Backport 3eee9fc2c4d1973904b1a26fa96a8c7473ef6a5e Requested by: @var-const --- Patch is 31.22 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/151095.diff 15 Files Affected: - (modified) .github/workflows/libcxx-build-and-test.yaml (+1) - (added) libcxx/cmake/caches/Generic-hardening-mode-extensive-observe-semantic.cmake (+2) - (modified) libcxx/docs/Hardening.rst (+68) - (modified) libcxx/docs/ReleaseNotes/21.rst (+6) - (modified) libcxx/docs/UserDocumentation.rst (+5) - (modified) libcxx/include/__config (+66-24) - (modified) libcxx/include/__cxx03/__config (+4) - (modified) libcxx/test/libcxx/thread/thread.barrier/assert.arrive.pass.cpp (+2) - (modified) libcxx/test/libcxx/thread/thread.latch/assert.arrive_and_wait.pass.cpp (+2) - (modified) libcxx/test/support/check_assertion.h (+119-18) - (modified) libcxx/test/support/test.support/test_check_assertion.pass.cpp (+14-6) - (modified) libcxx/utils/ci/run-buildbot (+6) - (modified) libcxx/utils/libcxx/test/params.py (+19) - (modified) libcxx/vendor/llvm/default_assertion_handler.in (+31-4) - (modified) libcxxabi/src/demangle/DemangleConfig.h (+8) ``diff diff --git a/.github/workflows/libcxx-build-and-test.yaml b/.github/workflows/libcxx-build-and-test.yaml index a5be912b1ab07..7c18560bd163a 100644 --- a/.github/workflows/libcxx-build-and-test.yaml +++ b/.github/workflows/libcxx-build-and-test.yaml @@ -128,6 +128,7 @@ jobs: 'generic-abi-unstable', 'generic-hardening-mode-debug', 'generic-hardening-mode-extensive', + 'generic-hardening-mode-extensive-observe-semantic', 'generic-hardening-mode-fast', 'generic-hardening-mode-fast-with-abi-breaks', 'generic-merged', diff --git a/libcxx/cmake/caches/Generic-hardening-mode-extensive-observe-semantic.cmake b/libcxx/cmake/caches/Generic-hardening-mode-extensive-observe-semantic.cmake new file mode 100644 index 0..c843c02977a87 --- /dev/null +++ b/libcxx/cmake/caches/Generic-hardening-mode-extensive-observe-semantic.cmake @@ -0,0 +1,2 @@ +set(LIBCXX_HARDENING_MODE "extensive" CACHE STRING "") +set(LIBCXX_TEST_PARAMS "assertion_semantic=observe" CACHE STRING "") diff --git a/libcxx/docs/Hardening.rst b/libcxx/docs/Hardening.rst index 17808841bd9ec..1cdb3605c38ab 100644 --- a/libcxx/docs/Hardening.rst +++ b/libcxx/docs/Hardening.rst @@ -39,6 +39,8 @@ modes are: Enabling hardening has no impact on the ABI. +.. _notes-for-users: + Notes for users --- @@ -72,6 +74,10 @@ to control the level by passing **one** of the following options to the compiler pre-built components. Most libc++ code is header-based, so a user-provided value for ``_LIBCPP_HARDENING_MODE`` will be mostly respected. +In some cases, users might want to override the assertion semantic used by the +library. This can be done similarly to setting the hardening mode; please refer +to the :ref:`relevant section `. + Notes for vendors - @@ -260,6 +266,68 @@ output. This is less secure and increases the size of the binary (among other things, it has to store the error message strings) but makes the failure easier to debug. It also allows testing the error messages in our test suite. +This default behavior can be customized by users via :ref:`assertion semantics +`; it can also be completely overridden by vendors by +providing a :ref:`custom assertion failure handler +`. + +.. _assertion-semantics: + +Assertion semantics +--- + +.. warning:: + + Assertion semantics are currently an experimental feature. + +.. note:: + + Assertion semantics are not available in the C++03 mode. + +What happens when an assertion fails depends on the assertion semantic being +used. Four assertion semantics are available, based on C++26 Contracts +evaluation semantics: + +- ``ignore`` evaluates the assertion but has no effect if it fails (note that it + differs from the Contracts ``ignore`` semantic which would not evaluate + the assertion at all); +- ``observe`` logs an error (indicating, if possible on the platform, that the + error is fatal) but continues execution; +- ``quick-enforce`` terminates the program as fast as possible via a trap + instruction. It is the default semantic for the production modes (``fast`` and + ``extensive``); +- ``enforce`` logs an error and then terminates the program. It is the default + semantic for the ``debug`` mode. + +Notes: + +- Continuing execution after a hardening check fails results in undefined + behavior; the ``observe`` semantic is meant to make adopting hardening easier + but should not be used outside of the adoption period; +- C++26 wording for Library Hardening precludes a conforming Hardened + implementation from using the Contracts ``ignore`` semantic when evaluating + hardened precondi
[llvm-branch-commits] [llvm] release/21.x: [CodeGenPrepare] Make sure that `AddOffset` is also a loop invariant (#150625) (PR #150646)
https://github.com/tru updated https://github.com/llvm/llvm-project/pull/150646
>From 8c7cf7c06d5d3f872664a8a1af7775935e0671a3 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
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] 8c7cf7c - [CodeGenPrepare] Make sure that `AddOffset` is also a loop invariant (#150625)
Author: Yingwei Zheng
Date: 2025-07-29T09:37:27+02:00
New Revision: 8c7cf7c06d5d3f872664a8a1af7775935e0671a3
URL:
https://github.com/llvm/llvm-project/commit/8c7cf7c06d5d3f872664a8a1af7775935e0671a3
DIFF:
https://github.com/llvm/llvm-project/commit/8c7cf7c06d5d3f872664a8a1af7775935e0671a3.diff
LOG: [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)
Added:
Modified:
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/test/Transforms/CodeGenPrepare/X86/fold-loop-of-urem.ll
Removed:
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
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/21.x: [CodeGenPrepare] Make sure that `AddOffset` is also a loop invariant (#150625) (PR #150646)
https://github.com/tru closed https://github.com/llvm/llvm-project/pull/150646 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/21.x: [CodeGenPrepare] Make sure that `AddOffset` is also a loop invariant (#150625) (PR #150646)
github-actions[bot] wrote: @dtcxzyw (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/150646 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/21.x: [flang-rt] Remove hard-coded dependency on compiler-rt path on Windows (#150244) (PR #150764)
https://github.com/tru updated https://github.com/llvm/llvm-project/pull/150764
>From 949c6cc95a9b80fbfc6b3918f66b0470b592a5e4 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
[email protected]
https://lists.llvm.org/cg
[llvm-branch-commits] [llvm] release/21.x: [flang-rt] Remove hard-coded dependency on compiler-rt path on Windows (#150244) (PR #150764)
https://github.com/tru closed https://github.com/llvm/llvm-project/pull/150764 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/21.x: [flang-rt] Remove hard-coded dependency on compiler-rt path on Windows (#150244) (PR #150764)
github-actions[bot] wrote: @DavidTruby (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/150764 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] bde97f2 - [Mips] Fix wrong ELF FP ABI info when inline asm was empty (#146457)
Author: yingopq
Date: 2025-07-29T09:44:28+02:00
New Revision: bde97f2cefba49a9753c23517918c07e743a9a9b
URL:
https://github.com/llvm/llvm-project/commit/bde97f2cefba49a9753c23517918c07e743a9a9b
DIFF:
https://github.com/llvm/llvm-project/commit/bde97f2cefba49a9753c23517918c07e743a9a9b.diff
LOG: [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)
Added:
llvm/test/CodeGen/Mips/abiflags-soft-float.ll
Modified:
llvm/lib/Target/Mips/MipsAsmPrinter.cpp
Removed:
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
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/21.x: [Mips] Fix wrong ELF FP ABI info when inline asm was empty (#146457) (PR #150866)
https://github.com/tru updated https://github.com/llvm/llvm-project/pull/150866 >From bde97f2cefba49a9753c23517918c07e743a9a9b Mon Sep 17 00:00:00 2001 From: yingopq <[email protected]> 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 [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/21.x: [Mips] Fix wrong ELF FP ABI info when inline asm was empty (#146457) (PR #150866)
https://github.com/tru closed https://github.com/llvm/llvm-project/pull/150866 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/21.x: [Mips] Fix wrong ELF FP ABI info when inline asm was empty (#146457) (PR #150866)
github-actions[bot] wrote: @brad0 (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/150866 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] release/21.x [ObjCARC] Delete empty autoreleasepools with no autoreleases in them and remove ObjCARCAPElimPass (PR #150771)
nikic wrote: Yes, I feel strongly that this should not be backported. This patch is both unimportant and risky. https://github.com/llvm/llvm-project/pull/150771 ___ llvm-branch-commits mailing list [email protected] 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)
https://github.com/tru updated https://github.com/llvm/llvm-project/pull/150895
>From 16d81f85e90dbbbed6a2d024c426f7c16b0c8d48 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] [lld] 16d81f8 - [lld][LoongArch] Support relaxation during TLSDESC GD/LD to IE/LE conversion (#123730)
Author: Zhaoxin Yang
Date: 2025-07-29T09:51:50+02:00
New Revision: 16d81f85e90dbbbed6a2d024c426f7c16b0c8d48
URL:
https://github.com/llvm/llvm-project/commit/16d81f85e90dbbbed6a2d024c426f7c16b0c8d48
DIFF:
https://github.com/llvm/llvm-project/commit/16d81f85e90dbbbed6a2d024c426f7c16b0c8d48.diff
LOG: [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)
Added:
Modified:
lld/ELF/Arch/LoongArch.cpp
lld/test/ELF/loongarch-relax-tlsdesc.s
Removed:
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_T
[llvm-branch-commits] [lld] release/21.x: [lld][LoongArch] Support relaxation during TLSDESC GD/LD to IE/LE conversion (#123730) (PR #150895)
https://github.com/tru closed https://github.com/llvm/llvm-project/pull/150895 ___ llvm-branch-commits mailing list [email protected] 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)
github-actions[bot] wrote: @brad0 (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/150895 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] d4955d9 - [Driver] Default to -mv8plus on 32-bit Solaris/SPARC (#150176)
Author: Rainer Orth
Date: 2025-07-29T09:53:42+02:00
New Revision: d4955d9b9512bdd5bc5c37a4ab587ddbdaff0be3
URL:
https://github.com/llvm/llvm-project/commit/d4955d9b9512bdd5bc5c37a4ab587ddbdaff0be3
DIFF:
https://github.com/llvm/llvm-project/commit/d4955d9b9512bdd5bc5c37a4ab587ddbdaff0be3.diff
LOG: [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)
Added:
Modified:
clang/lib/Driver/ToolChains/Arch/Sparc.cpp
clang/test/Driver/sparc-target-features.c
Removed:
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
[email protected]
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)
https://github.com/tru updated https://github.com/llvm/llvm-project/pull/150898
>From d4955d9b9512bdd5bc5c37a4ab587ddbdaff0be3 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
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] c52ff1a - Revert "[MIPS]Fix QNaNs in the MIPS legacy NaN encodings" (#150773)
Author: Nikita Popov
Date: 2025-07-29T09:54:17+02:00
New Revision: c52ff1a82579c0730151aca412449ea75ae12d03
URL:
https://github.com/llvm/llvm-project/commit/c52ff1a82579c0730151aca412449ea75ae12d03
DIFF:
https://github.com/llvm/llvm-project/commit/c52ff1a82579c0730151aca412449ea75ae12d03.diff
LOG: 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)
Added:
llvm/test/CodeGen/Mips/nan_lowering.ll
Modified:
llvm/lib/Target/Mips/MipsISelLowering.cpp
llvm/lib/Target/Mips/MipsISelLowering.h
Removed:
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-prefixes=MIPS_Legacy
-; RUN: llc -O3 -mcpu=mips32r2 -mtripl
[llvm-branch-commits] [clang] release/21.x: [Driver] Default to -mv8plus on 32-bit Solaris/SPARC (#150176) (PR #150898)
github-actions[bot] wrote: @brad0 (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/150898 ___ llvm-branch-commits mailing list [email protected] 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)
https://github.com/tru updated https://github.com/llvm/llvm-project/pull/150902
>From c52ff1a82579c0730151aca412449ea75ae12d03 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: Revert "[MIPS]Fix QNaNs in the MIPS legacy NaN encodings" (#150773) (PR #150902)
https://github.com/tru closed https://github.com/llvm/llvm-project/pull/150902 ___ llvm-branch-commits mailing list [email protected] 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)
https://github.com/tru closed https://github.com/llvm/llvm-project/pull/150898 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lldb] release/21.x: [lldb] [Windows] Silence format string warnings (#150886) (PR #150919)
https://github.com/tru updated https://github.com/llvm/llvm-project/pull/150919
>From 67cec1afdbc2fde0765fd27b5d039fa5823e5a69 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 c1a018238432d..c0b10797e506a 100644
--- a/lldb/source/Host/windows/MainLoopWindows.cpp
+++ b/lldb/source/Host/windows/MainLoopWindows.cpp
@@ -223,7 +223,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;
}
@@ -235,7 +235,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
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lldb] release/21.x: [lldb] [Windows] Silence format string warnings (#150886) (PR #150919)
https://github.com/tru closed https://github.com/llvm/llvm-project/pull/150919 ___ llvm-branch-commits mailing list [email protected] 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)
github-actions[bot] wrote: @nikic (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/150902 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lldb] 67cec1a - [lldb] [Windows] Silence format string warnings (#150886)
Author: Martin Storsjö
Date: 2025-07-29T09:54:48+02:00
New Revision: 67cec1afdbc2fde0765fd27b5d039fa5823e5a69
URL:
https://github.com/llvm/llvm-project/commit/67cec1afdbc2fde0765fd27b5d039fa5823e5a69
DIFF:
https://github.com/llvm/llvm-project/commit/67cec1afdbc2fde0765fd27b5d039fa5823e5a69.diff
LOG: [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)
Added:
Modified:
lldb/source/Host/windows/MainLoopWindows.cpp
Removed:
diff --git a/lldb/source/Host/windows/MainLoopWindows.cpp
b/lldb/source/Host/windows/MainLoopWindows.cpp
index c1a018238432d..c0b10797e506a 100644
--- a/lldb/source/Host/windows/MainLoopWindows.cpp
+++ b/lldb/source/Host/windows/MainLoopWindows.cpp
@@ -223,7 +223,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;
}
@@ -235,7 +235,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
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lldb] release/21.x: [lldb] [Windows] Silence format string warnings (#150886) (PR #150919)
github-actions[bot] wrote: @mstorsjo (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/150919 ___ llvm-branch-commits mailing list [email protected] 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)
https://github.com/tru closed https://github.com/llvm/llvm-project/pull/150960 ___ llvm-branch-commits mailing list [email protected] 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)
https://github.com/tru updated https://github.com/llvm/llvm-project/pull/150960 >From 431af6d04c9da4cab060f429bade6ed341d080e5 Mon Sep 17 00:00:00 2001 From: Felix Weiglhofer <[email protected]> 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 [email protected] 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)
github-actions[bot] wrote: @svenvh (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/150960 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] 431af6d - opencl: Ensure printf symbol is not mangled. (#150210)
Author: Felix Weiglhofer
Date: 2025-07-29T09:55:29+02:00
New Revision: 431af6d04c9da4cab060f429bade6ed341d080e5
URL:
https://github.com/llvm/llvm-project/commit/431af6d04c9da4cab060f429bade6ed341d080e5
DIFF:
https://github.com/llvm/llvm-project/commit/431af6d04c9da4cab060f429bade6ed341d080e5.diff
LOG: opencl: Ensure printf symbol is not mangled. (#150210)
Fixes #122453.
(cherry picked from commit a22d010002baf761f84d0a8fa5fcaaf6f3b1455f)
Added:
Modified:
clang/lib/Headers/opencl-c-base.h
Removed:
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
[email protected]
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)
https://github.com/tru updated https://github.com/llvm/llvm-project/pull/150970
>From 81a3436485f262a2d8ed14b8bbf22dcfb9c6f110 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 default to Expand, but we have instructions
// for them.
setOperationAction
[llvm-branch-commits] [llvm] release/21.x: [CodeGen] More consistently expand float ops by default (#150597) (PR #150970)
https://github.com/tru closed https://github.com/llvm/llvm-project/pull/150970 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] 81a3436 - [CodeGen] More consistently expand float ops by default (#150597)
Author: Nikita Popov
Date: 2025-07-29T09:57:11+02:00
New Revision: 81a3436485f262a2d8ed14b8bbf22dcfb9c6f110
URL:
https://github.com/llvm/llvm-project/commit/81a3436485f262a2d8ed14b8bbf22dcfb9c6f110
DIFF:
https://github.com/llvm/llvm-project/commit/81a3436485f262a2d8ed14b8bbf22dcfb9c6f110.diff
LOG: [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)
Added:
llvm/test/CodeGen/PowerPC/froundeven-legalization.ll
Modified:
llvm/lib/CodeGen/TargetLoweringBase.cpp
llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
llvm/lib/Target/ARM/ARMISelLowering.cpp
Removed:
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.
s
[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)
https://github.com/tru updated https://github.com/llvm/llvm-project/pull/150969
>From 9c307cd44f2e33631364be8cec29798dfdec96e5 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
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] dc90bf0 - [clang] Fix const eval of constexpr-unknown relational comparisons. (#150088)
Author: Eli Friedman
Date: 2025-07-29T09:57:43+02:00
New Revision: dc90bf0329259c8a34b5c4c6de53c8e2a7ca055a
URL:
https://github.com/llvm/llvm-project/commit/dc90bf0329259c8a34b5c4c6de53c8e2a7ca055a
DIFF:
https://github.com/llvm/llvm-project/commit/dc90bf0329259c8a34b5c4c6de53c8e2a7ca055a.diff
LOG: [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)
Added:
Modified:
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/constant-expression-p2280r4.cpp
Removed:
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
diff erent base classes has unspecified value}} \
+ // interpreter-note
{{initializer of 'z' is unknown}}
+}
___
llvm-branch-commits mailing list
[email protected]
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)
https://github.com/tru updated https://github.com/llvm/llvm-project/pull/150981
>From dc90bf0329259c8a34b5c4c6de53c8e2a7ca055a 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
[email protected]
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)
github-actions[bot] wrote: @nikic (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/150970 ___ llvm-branch-commits mailing list [email protected] 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)
github-actions[bot] wrote: @efriedma-quic (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/150981 ___ llvm-branch-commits mailing list [email protected] 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)
https://github.com/tru closed https://github.com/llvm/llvm-project/pull/150981 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld] bbc8346 - [LLD][COFF] Avoid resolving symbols with -alternatename if the target is undefined (#149496)
Author: Jacek Caban
Date: 2025-07-29T09:58:55+02:00
New Revision: bbc8346e6bb543b0a87f52114fed7d766446bee1
URL:
https://github.com/llvm/llvm-project/commit/bbc8346e6bb543b0a87f52114fed7d766446bee1
DIFF:
https://github.com/llvm/llvm-project/commit/bbc8346e6bb543b0a87f52114fed7d766446bee1.diff
LOG: [LLD][COFF] Avoid resolving symbols with -alternatename if the target is
undefined (#149496)
This change fixes an issue with the use of `-alternatename` in the MSVC
CRT on ARM64EC, where both mangled and demangled symbol names are
specified. Without this patch, the demangled name could be resolved to
an anti-dependency alias of the target. Since chaining anti-dependency
aliases is not allowed, this results in an undefined symbol.
The root cause isn't specific to ARM64EC, it can affect other targets as
well, even when anti-dependency aliases aren't involved. The
accompanying test case demonstrates a scenario where the symbol could be
resolved from an archive. However, because the archive member is pulled
in after the first pass of alternate name resolution, and archive
members don't override weak aliases, eager resolution would incorrectly
skip it.
(cherry picked from commit ac31d64a64e8a648f6834f4cf9de10c56c8d1083)
Added:
lld/test/COFF/alternatename-alias.s
lld/test/COFF/alternatename-antidep.s
lld/test/COFF/alternatename-lib.s
Modified:
lld/COFF/SymbolTable.cpp
lld/test/COFF/arm64ec-altnames.s
Removed:
diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp
index 1cf750393e6b3..189e75dfc3ff5 100644
--- a/lld/COFF/SymbolTable.cpp
+++ b/lld/COFF/SymbolTable.cpp
@@ -1364,7 +1364,19 @@ void SymbolTable::resolveAlternateNames() {
!isArm64ECMangledFunctionName(u->getName()))
continue;
}
- u->setWeakAlias(addUndefined(to));
+
+ // Check if the destination symbol is defined. If not, skip it.
+ // It may still be resolved later if more input files are added.
+ // Also skip anti-dependency targets, as they can't be chained anyway.
+ Symbol *toSym = find(to);
+ if (!toSym)
+continue;
+ auto toUndef = dyn_cast(toSym);
+ if (toUndef && (!toUndef->weakAlias || toUndef->isAntiDep))
+continue;
+ if (toSym->isLazy())
+forceLazy(toSym);
+ u->setWeakAlias(toSym);
}
}
}
diff --git a/lld/test/COFF/alternatename-alias.s
b/lld/test/COFF/alternatename-alias.s
new file mode 100644
index 0..bd0a861380e94
--- /dev/null
+++ b/lld/test/COFF/alternatename-alias.s
@@ -0,0 +1,15 @@
+// REQUIRES: x86
+
+// Check that a weak alias can be used as an alternate name target.
+// RUN: llvm-mc -filetype=obj -triple=x86_64-windows %s -o %t.obj
+// RUN: lld-link -dll -noentry %t.obj -alternatename:sym=altsym
+
+.data
+.rva sym
+
+.weak altsym
+.set altsym,a
+
+.globl a
+a:
+.word 1
diff --git a/lld/test/COFF/alternatename-antidep.s
b/lld/test/COFF/alternatename-antidep.s
new file mode 100644
index 0..1188a9b75d481
--- /dev/null
+++ b/lld/test/COFF/alternatename-antidep.s
@@ -0,0 +1,16 @@
+// REQUIRES: x86
+
+// Check that an anti-dependency alias can't be used as an alternate name
target.
+// RUN: llvm-mc -filetype=obj -triple=x86_64-windows %s -o %t.obj
+// RUN: not lld-link -dll -noentry %t.obj -alternatename:sym=altsym 2>&1 |
FileCheck %s
+// CHECK: error: undefined symbol: sym
+
+.data
+.rva sym
+
+.weak_anti_dep altsym
+.set altsym,a
+
+.globl a
+a:
+.word 1
diff --git a/lld/test/COFF/alternatename-lib.s
b/lld/test/COFF/alternatename-lib.s
new file mode 100644
index 0..206fe6bc23978
--- /dev/null
+++ b/lld/test/COFF/alternatename-lib.s
@@ -0,0 +1,43 @@
+// REQUIRES: x86
+// RUN: split-file %s %t.dir && cd %t.dir
+
+// RUN: llvm-mc -filetype=obj -triple=x86_64-windows refab.s -o refab.obj
+// RUN: llvm-mc -filetype=obj -triple=x86_64-windows aa.s -o aa.obj
+// RUN: llvm-mc -filetype=obj -triple=x86_64-windows b.s -o b.obj
+// RUN: llvm-mc -filetype=obj -triple=x86_64-windows antidep.s -o antidep.obj
+// RUN: llvm-lib -out:aa.lib aa.obj
+// RUN: llvm-lib -out:b.lib b.obj
+
+// Check that -alternatename with an undefined target does not prevent the
symbol from being resolved to a library,
+// once another alternate name is resolved and pulls in the source symbol.
+// RUN: lld-link -out:out.dll -dll -noentry -machine:amd64 refab.obj aa.lib
-alternatename:a=aa -alternatename:b=undef
+
+// Check that -alternatename with an anti-dependency target does not prevent
the symbol from being resolved to a library,
+// after another alternate name is resolved and pulls in the source symbol.
+// RUN: lld-link -out:out2.dll -dll -noentry -machine:amd64 antidep.obj
refab.obj aa.lib -alternatename:a=aa -alternatename:b=u
+
+#--- refab.s
+.data
+.rva a
+.rva
[llvm-branch-commits] [lld] release/21.x: [LLD][COFF] Avoid resolving symbols with -alternatename if the target is undefined (#149496) (PR #151027)
https://github.com/tru updated https://github.com/llvm/llvm-project/pull/151027
>From f1bca175afd4deab1cdfdcc8b1d7c705d7b07ab3 Mon Sep 17 00:00:00 2001
From: Jacek Caban
Date: Mon, 28 Jul 2025 08:02:49 -0700
Subject: [PATCH 1/2] [LLD][COFF] Move resolving alternate names to SymbolTable
(NFC) (#149495)
(cherry picked from commit 38cd66a6ceef5a3208367967d8537b6a7e31ebc0)
---
lld/COFF/Driver.cpp | 23 +--
lld/COFF/SymbolTable.cpp | 25 +
lld/COFF/SymbolTable.h | 3 +++
3 files changed, 29 insertions(+), 22 deletions(-)
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 83040b534be9c..570b8f9d05906 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -2554,28 +2554,7 @@ void LinkerDriver::linkerMain(ArrayRef
argsArr) {
e.symbolName = symtab.mangleMaybe(e.sym);
}
-// Add weak aliases. Weak aliases is a mechanism to give remaining
-// undefined symbols final chance to be resolved successfully.
-for (auto pair : symtab.alternateNames) {
- StringRef from = pair.first;
- StringRef to = pair.second;
- Symbol *sym = symtab.find(from);
- if (!sym)
-continue;
- if (auto *u = dyn_cast(sym)) {
-if (u->weakAlias) {
- // On ARM64EC, anti-dependency aliases are treated as undefined
- // symbols unless a demangled symbol aliases a defined one, which
- // is part of the implementation.
- if (!symtab.isEC() || !u->isAntiDep)
-continue;
- if (!isa(u->weakAlias) &&
- !isArm64ECMangledFunctionName(u->getName()))
-continue;
-}
-u->setWeakAlias(symtab.addUndefined(to));
- }
-}
+symtab.resolveAlternateNames();
});
ctx.forEachActiveSymtab([&](SymbolTable &symtab) {
diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp
index 0062df5820e63..1cf750393e6b3 100644
--- a/lld/COFF/SymbolTable.cpp
+++ b/lld/COFF/SymbolTable.cpp
@@ -1344,6 +1344,31 @@ void SymbolTable::parseAlternateName(StringRef s) {
alternateNames.insert(it, std::make_pair(from, to));
}
+void SymbolTable::resolveAlternateNames() {
+ // Add weak aliases. Weak aliases is a mechanism to give remaining
+ // undefined symbols final chance to be resolved successfully.
+ for (auto pair : alternateNames) {
+StringRef from = pair.first;
+StringRef to = pair.second;
+Symbol *sym = find(from);
+if (!sym)
+ continue;
+if (auto *u = dyn_cast(sym)) {
+ if (u->weakAlias) {
+// On ARM64EC, anti-dependency aliases are treated as undefined
+// symbols unless a demangled symbol aliases a defined one, which
+// is part of the implementation.
+if (!isEC() || !u->isAntiDep)
+ continue;
+if (!isa(u->weakAlias) &&
+!isArm64ECMangledFunctionName(u->getName()))
+ continue;
+ }
+ u->setWeakAlias(addUndefined(to));
+}
+ }
+}
+
// Parses /aligncomm option argument.
void SymbolTable::parseAligncomm(StringRef s) {
auto [name, align] = s.split(',');
diff --git a/lld/COFF/SymbolTable.h b/lld/COFF/SymbolTable.h
index 15e2644a6f519..7eb067640dc85 100644
--- a/lld/COFF/SymbolTable.h
+++ b/lld/COFF/SymbolTable.h
@@ -69,6 +69,9 @@ class SymbolTable {
// symbols and warn about imported local symbols.
void resolveRemainingUndefines();
+ // Try to resolve undefined symbols with alternate names.
+ void resolveAlternateNames();
+
// Load lazy objects that are needed for MinGW automatic import and for
// doing stdcall fixups.
void loadMinGWSymbols();
>From bbc8346e6bb543b0a87f52114fed7d766446bee1 Mon Sep 17 00:00:00 2001
From: Jacek Caban
Date: Mon, 28 Jul 2025 10:26:25 -0700
Subject: [PATCH 2/2] [LLD][COFF] Avoid resolving symbols with -alternatename
if the target is undefined (#149496)
This change fixes an issue with the use of `-alternatename` in the MSVC
CRT on ARM64EC, where both mangled and demangled symbol names are
specified. Without this patch, the demangled name could be resolved to
an anti-dependency alias of the target. Since chaining anti-dependency
aliases is not allowed, this results in an undefined symbol.
The root cause isn't specific to ARM64EC, it can affect other targets as
well, even when anti-dependency aliases aren't involved. The
accompanying test case demonstrates a scenario where the symbol could be
resolved from an archive. However, because the archive member is pulled
in after the first pass of alternate name resolution, and archive
members don't override weak aliases, eager resolution would incorrectly
skip it.
(cherry picked from commit ac31d64a64e8a648f6834f4cf9de10c56c8d1083)
---
lld/COFF/SymbolTable.cpp | 14 -
lld/test/COFF/alternatename-alias.s | 15 ++
lld/test/COFF/alternatename-antidep.s | 16 ++
lld/test/COFF
[llvm-branch-commits] [lld] release/21.x: [LLD][COFF] Avoid resolving symbols with -alternatename if the target is undefined (#149496) (PR #151027)
https://github.com/tru closed https://github.com/llvm/llvm-project/pull/151027 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld] f1bca17 - [LLD][COFF] Move resolving alternate names to SymbolTable (NFC) (#149495)
Author: Jacek Caban
Date: 2025-07-29T09:58:55+02:00
New Revision: f1bca175afd4deab1cdfdcc8b1d7c705d7b07ab3
URL:
https://github.com/llvm/llvm-project/commit/f1bca175afd4deab1cdfdcc8b1d7c705d7b07ab3
DIFF:
https://github.com/llvm/llvm-project/commit/f1bca175afd4deab1cdfdcc8b1d7c705d7b07ab3.diff
LOG: [LLD][COFF] Move resolving alternate names to SymbolTable (NFC) (#149495)
(cherry picked from commit 38cd66a6ceef5a3208367967d8537b6a7e31ebc0)
Added:
Modified:
lld/COFF/Driver.cpp
lld/COFF/SymbolTable.cpp
lld/COFF/SymbolTable.h
Removed:
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 83040b534be9c..570b8f9d05906 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -2554,28 +2554,7 @@ void LinkerDriver::linkerMain(ArrayRef
argsArr) {
e.symbolName = symtab.mangleMaybe(e.sym);
}
-// Add weak aliases. Weak aliases is a mechanism to give remaining
-// undefined symbols final chance to be resolved successfully.
-for (auto pair : symtab.alternateNames) {
- StringRef from = pair.first;
- StringRef to = pair.second;
- Symbol *sym = symtab.find(from);
- if (!sym)
-continue;
- if (auto *u = dyn_cast(sym)) {
-if (u->weakAlias) {
- // On ARM64EC, anti-dependency aliases are treated as undefined
- // symbols unless a demangled symbol aliases a defined one, which
- // is part of the implementation.
- if (!symtab.isEC() || !u->isAntiDep)
-continue;
- if (!isa(u->weakAlias) &&
- !isArm64ECMangledFunctionName(u->getName()))
-continue;
-}
-u->setWeakAlias(symtab.addUndefined(to));
- }
-}
+symtab.resolveAlternateNames();
});
ctx.forEachActiveSymtab([&](SymbolTable &symtab) {
diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp
index 0062df5820e63..1cf750393e6b3 100644
--- a/lld/COFF/SymbolTable.cpp
+++ b/lld/COFF/SymbolTable.cpp
@@ -1344,6 +1344,31 @@ void SymbolTable::parseAlternateName(StringRef s) {
alternateNames.insert(it, std::make_pair(from, to));
}
+void SymbolTable::resolveAlternateNames() {
+ // Add weak aliases. Weak aliases is a mechanism to give remaining
+ // undefined symbols final chance to be resolved successfully.
+ for (auto pair : alternateNames) {
+StringRef from = pair.first;
+StringRef to = pair.second;
+Symbol *sym = find(from);
+if (!sym)
+ continue;
+if (auto *u = dyn_cast(sym)) {
+ if (u->weakAlias) {
+// On ARM64EC, anti-dependency aliases are treated as undefined
+// symbols unless a demangled symbol aliases a defined one, which
+// is part of the implementation.
+if (!isEC() || !u->isAntiDep)
+ continue;
+if (!isa(u->weakAlias) &&
+!isArm64ECMangledFunctionName(u->getName()))
+ continue;
+ }
+ u->setWeakAlias(addUndefined(to));
+}
+ }
+}
+
// Parses /aligncomm option argument.
void SymbolTable::parseAligncomm(StringRef s) {
auto [name, align] = s.split(',');
diff --git a/lld/COFF/SymbolTable.h b/lld/COFF/SymbolTable.h
index 15e2644a6f519..7eb067640dc85 100644
--- a/lld/COFF/SymbolTable.h
+++ b/lld/COFF/SymbolTable.h
@@ -69,6 +69,9 @@ class SymbolTable {
// symbols and warn about imported local symbols.
void resolveRemainingUndefines();
+ // Try to resolve undefined symbols with alternate names.
+ void resolveAlternateNames();
+
// Load lazy objects that are needed for MinGW automatic import and for
// doing stdcall fixups.
void loadMinGWSymbols();
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld] release/21.x: [LLD][COFF] Avoid resolving symbols with -alternatename if the target is undefined (#149496) (PR #151027)
github-actions[bot] wrote: @cjacek (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/151027 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] 317403d - [LLDB] Switch to using DIL as default implementation for 'frame var'. (#147887)
Author: cmtice
Date: 2025-07-29T10:00:12+02:00
New Revision: 317403d705acc9f72a81e853f649087cce3842d1
URL:
https://github.com/llvm/llvm-project/commit/317403d705acc9f72a81e853f649087cce3842d1
DIFF:
https://github.com/llvm/llvm-project/commit/317403d705acc9f72a81e853f649087cce3842d1.diff
LOG: [LLDB] Switch to using DIL as default implementation for 'frame var'.
(#147887)
(cherry picked from commit f5c676d6d95dc63b8dcb43dd2e4dfc913a9c5a50)
Added:
Modified:
lldb/source/Target/TargetProperties.td
lldb/source/ValueObject/DILEval.cpp
lldb/test/API/commands/frame/var-dil/basics/QualifiedId/TestFrameVarDILQualifiedId.py
lldb/test/API/commands/frame/var-dil/basics/QualifiedId/main.cpp
lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py
lldb/test/Shell/SymbolFile/DWARF/TestDedupWarnings.test
llvm/docs/ReleaseNotes.md
Removed:
diff --git a/lldb/source/Target/TargetProperties.td
b/lldb/source/Target/TargetProperties.td
index 4aa9e046d6077..656503bb8d228 100644
--- a/lldb/source/Target/TargetProperties.td
+++ b/lldb/source/Target/TargetProperties.td
@@ -5,8 +5,8 @@ let Definition = "target_experimental" in {
Global, DefaultTrue,
Desc<"If true, inject local variables explicitly into the expression text.
This will fix symbol resolution when there are name collisions between ivars
and local variables. But it can make expressions run much more slowly.">;
def UseDIL : Property<"use-DIL", "Boolean">,
-Global, DefaultFalse,
-Desc<"If true, use the alternative DIL implementation for frame variable
evaluation.">;
+Global, DefaultTrue,
+Desc<"If true, use the DIL implementation for frame variable evaluation.">;
}
let Definition = "target" in {
diff --git a/lldb/source/ValueObject/DILEval.cpp
b/lldb/source/ValueObject/DILEval.cpp
index fd3f9f8724608..6f28434c646cd 100644
--- a/lldb/source/ValueObject/DILEval.cpp
+++ b/lldb/source/ValueObject/DILEval.cpp
@@ -303,7 +303,7 @@ Interpreter::Visit(const MemberOfNode *node) {
}
}
- if (field_obj && field_obj->GetName() == node->GetFieldName()) {
+ if (field_obj) {
if (m_use_dynamic != lldb::eNoDynamicValues) {
lldb::ValueObjectSP dynamic_val_sp =
field_obj->GetDynamicValue(m_use_dynamic);
diff --git
a/lldb/test/API/commands/frame/var-dil/basics/QualifiedId/TestFrameVarDILQualifiedId.py
b/lldb/test/API/commands/frame/var-dil/basics/QualifiedId/TestFrameVarDILQualifiedId.py
index b2ce9602e6a50..8c009aa182d07 100644
---
a/lldb/test/API/commands/frame/var-dil/basics/QualifiedId/TestFrameVarDILQualifiedId.py
+++
b/lldb/test/API/commands/frame/var-dil/basics/QualifiedId/TestFrameVarDILQualifiedId.py
@@ -29,3 +29,17 @@ def test_frame_var(self):
self.expect_var_path("ns::i", value="1")
self.expect_var_path("::ns::ns::i", value="2")
self.expect_var_path("ns::ns::i", value="2")
+
+self.expect_var_path("foo", value="1")
+self.expect_var_path("::(anonymous namespace)::foo", value="13")
+self.expect_var_path("(anonymous namespace)::foo", value="13")
+self.expect_var_path("ns1::(anonymous namespace)::foo", value="5")
+self.expect_var_path(
+"(anonymous namespace)::ns2::(anonymous namespace)::foo",
+value="7",
+)
+self.expect_var_path("::ns1::(anonymous namespace)::foo", value="5")
+self.expect_var_path(
+"::(anonymous namespace)::ns2::(anonymous namespace)::foo",
+value="7",
+)
diff --git a/lldb/test/API/commands/frame/var-dil/basics/QualifiedId/main.cpp
b/lldb/test/API/commands/frame/var-dil/basics/QualifiedId/main.cpp
index 8a5c47a6f364c..10ffa1e54a991 100644
--- a/lldb/test/API/commands/frame/var-dil/basics/QualifiedId/main.cpp
+++ b/lldb/test/API/commands/frame/var-dil/basics/QualifiedId/main.cpp
@@ -10,7 +10,26 @@ int i = 2;
} // namespace ns
+namespace {
+int foo = 13;
+}
+
+namespace ns1 {
+namespace {
+int foo = 5;
+}
+} // namespace ns1
+
+namespace {
+namespace ns2 {
+namespace {
+int foo = 7;
+}
+} // namespace ns2
+} // namespace
+
int main(int argc, char **argv) {
+ int foo = 1;
- return 0; // Set a breakpoint here
+ return foo + ::foo + ns1::foo + ns2::foo; // Set a breakpoint here
}
diff --git a/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py
b/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py
index 0d2774b281710..20a75f4076e42 100644
--- a/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py
+++ b/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py
@@ -131,7 +131,7 @@ def run_test_evaluate_expressions(
self.assertEvaluateFailure("a_function(1)")
self.assertEvaluateFailure("var2 + struct1.foo")
self.assertEvaluateFailure("foo_func")
-self.assertEvaluateFailure("foo_var")
+self.assertEvaluate("foo_var", "44")
[llvm-branch-commits] [lldb] [llvm] release/21.x: [LLDB] Switch to using DIL as default implementation for 'frame var' (#149117) (PR #150600)
tru wrote: Merged as https://github.com/llvm/llvm-project/commit/317403d705acc9f72a81e853f649087cce3842d1 https://github.com/llvm/llvm-project/pull/150600 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lldb] [llvm] release/21.x: [LLDB] Switch to using DIL as default implementation for 'frame var' (#149117) (PR #150600)
https://github.com/tru closed https://github.com/llvm/llvm-project/pull/150600 ___ llvm-branch-commits mailing list [email protected] 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)
mstorsjo wrote: This now seems to pass tests just fine, on both linux and mingw targets. Can @jmorse ack the fix (and the test modifications), or is it enough with the comment in https://github.com/llvm/llvm-project/pull/130255#issuecomment-3109481798 saying this is what we should do? https://github.com/llvm/llvm-project/pull/150938 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lldb] release/21.x: [lldb][AArch64][Linux] Show MTE store only setting in mte_ctrl (#145033) (PR #151111)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/15 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lldb] release/21.x: [lldb][AArch64][Linux] Show MTE store only setting in mte_ctrl (#145033) (PR #151111)
https://github.com/llvmbot created
https://github.com/llvm/llvm-project/pull/15
Backport d26ca8b87266024546501051ccaf75cb3756aee3
0209e76fe6440bc45a9ed61b9671d9593db10957
Requested by: @DavidSpickett
>From ce64aae7a3db7e8cdb1156fc4a6f90a4c1d88699 Mon Sep 17 00:00:00 2001
From: David Spickett
Date: Mon, 28 Jul 2025 16:09:24 +0100
Subject: [PATCH 1/2] [lldb][AArch64] Add HWCAP3 to register field detection
(#145029)
This will be used to detect the presence of Arm's new Memory Tagging
store only checking feature. This commit just adds the plumbing to get
that value into the detection function.
FreeBSD has not allocated a number for HWCAP3 and already has AT_ARGV
defined as 29. So instead of attempting to read from FreeBSD processes,
I've explicitly passed 0. We don't want to be reading some other entry
accidentally.
If/when FreeBSD adds HWCAP3 we can handle it like we do for
AUXV_FREEBSD_AT_HWCAP.
No extra tests here, those will be coming with the next change for MTE
support.
(cherry picked from commit d26ca8b87266024546501051ccaf75cb3756aee3)
---
.../NativeRegisterContextFreeBSD_arm64.cpp| 3 +-
.../NativeRegisterContextLinux_arm64.cpp | 5 ++-
.../Plugins/Process/Utility/AuxVector.cpp | 1 +
.../Plugins/Process/Utility/AuxVector.h | 1 +
.../Utility/RegisterFlagsDetector_arm64.cpp | 36 +--
.../Utility/RegisterFlagsDetector_arm64.h | 25 -
.../RegisterContextPOSIXCore_arm64.cpp| 13 ---
7 files changed, 59 insertions(+), 25 deletions(-)
diff --git
a/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm64.cpp
b/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm64.cpp
index 7adc00622ec2d..d21dac221aa22 100644
--- a/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm64.cpp
+++ b/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm64.cpp
@@ -44,7 +44,8 @@
NativeRegisterContextFreeBSD::CreateHostNativeRegisterContextFreeBSD(
NativeProcessFreeBSD &process = native_thread.GetProcess();
g_register_flags_detector.DetectFields(
process.GetAuxValue(AuxVector::AUXV_FREEBSD_AT_HWCAP).value_or(0),
-process.GetAuxValue(AuxVector::AUXV_AT_HWCAP2).value_or(0));
+process.GetAuxValue(AuxVector::AUXV_AT_HWCAP2).value_or(0),
+/*hwcap3=*/0);
}
return new NativeRegisterContextFreeBSD_arm64(target_arch, native_thread);
diff --git
a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
index 884c7d4b9e359..b1c7421bef8d5 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
@@ -162,10 +162,13 @@
NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(
opt_regsets.Set(RegisterInfoPOSIX_arm64::eRegsetMaskTLS);
+std::optional auxv_at_hwcap3 =
+process.GetAuxValue(AuxVector::AUXV_AT_HWCAP3);
std::lock_guard lock(g_register_flags_detector_mutex);
if (!g_register_flags_detector.HasDetected())
g_register_flags_detector.DetectFields(auxv_at_hwcap.value_or(0),
- auxv_at_hwcap2.value_or(0));
+ auxv_at_hwcap2.value_or(0),
+ auxv_at_hwcap3.value_or(0));
auto register_info_up =
std::make_unique(target_arch, opt_regsets);
diff --git a/lldb/source/Plugins/Process/Utility/AuxVector.cpp
b/lldb/source/Plugins/Process/Utility/AuxVector.cpp
index f495ffb1924e7..50500a8593e1d 100644
--- a/lldb/source/Plugins/Process/Utility/AuxVector.cpp
+++ b/lldb/source/Plugins/Process/Utility/AuxVector.cpp
@@ -84,6 +84,7 @@ const char *AuxVector::GetEntryName(EntryType type) const {
case ENTRY_NAME(AUXV_AT_BASE_PLATFORM); break;
case ENTRY_NAME(AUXV_AT_RANDOM); break;
case ENTRY_NAME(AUXV_AT_HWCAP2); break;
+case ENTRY_NAME(AUXV_AT_HWCAP3); break;
case ENTRY_NAME(AUXV_AT_EXECFN); break;
case ENTRY_NAME(AUXV_AT_SYSINFO);break;
case ENTRY_NAME(AUXV_AT_SYSINFO_EHDR); break;
diff --git a/lldb/source/Plugins/Process/Utility/AuxVector.h
b/lldb/source/Plugins/Process/Utility/AuxVector.h
index 2670b34f6b0af..7733e0ffc6832 100644
--- a/lldb/source/Plugins/Process/Utility/AuxVector.h
+++ b/lldb/source/Plugins/Process/Utility/AuxVector.h
@@ -57,6 +57,7 @@ class AuxVector {
AUXV_AT_BASE_PLATFORM = 24, ///< String identifying real platforms.
AUXV_AT_RANDOM = 25,///< Address of 16 random bytes.
AUXV_AT_HWCAP2 = 26,///< Extension of AT_HWCAP.
+AUXV_AT_HWCAP3 = 29,///< Extension of AT_HWCAP.
AUXV_AT_EXECFN = 31,///< Filename of executable.
AUXV_AT_SYSINFO = 32, ///< Pointer to the global system page used for
system
/// calls an
[llvm-branch-commits] [llvm] [AMDGPU][GISel] Use buildObjectPtrOffset instead of buildPtrAdd (PR #150899)
ritter-x2a wrote: ### Merge activity * **Jul 29, 9:12 AM UTC**: A user started a stack merge that includes this pull request via [Graphite](https://app.graphite.dev/github/pr/llvm/llvm-project/150899). https://github.com/llvm/llvm-project/pull/150899 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lldb] release/21.x: [lldb][AArch64][Linux] Show MTE store only setting in mte_ctrl (#145033) (PR #151111)
llvmbot wrote: @omjavaid @omjavaid What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/15 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lldb] release/21.x: [lldb][AArch64][Linux] Show MTE store only setting in mte_ctrl (#145033) (PR #151111)
llvmbot wrote:
@llvm/pr-subscribers-lldb
Author: None (llvmbot)
Changes
Backport d26ca8b87266024546501051ccaf75cb3756aee3
0209e76fe6440bc45a9ed61b9671d9593db10957
Requested by: @DavidSpickett
---
Full diff: https://github.com/llvm/llvm-project/pull/15.diff
13 Files Affected:
- (modified) lldb/packages/Python/lldbsuite/test/lldbtest.py (+3)
- (modified)
lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm64.cpp
(+2-1)
- (modified)
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp (+4-1)
- (modified) lldb/source/Plugins/Process/Utility/AuxVector.cpp (+1)
- (modified) lldb/source/Plugins/Process/Utility/AuxVector.h (+1)
- (modified)
lldb/source/Plugins/Process/Utility/RegisterFlagsDetector_arm64.cpp (+40-13)
- (modified) lldb/source/Plugins/Process/Utility/RegisterFlagsDetector_arm64.h
(+16-9)
- (modified)
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.cpp (+9-4)
- (modified)
lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/TestMTECtrlRegister.py
(+22-10)
- (modified)
lldb/test/API/linux/aarch64/mte_core_file/TestAArch64LinuxMTEMemoryTagCoreFile.py
(+7-4)
- (modified) lldb/test/API/linux/aarch64/mte_core_file/core.mte ()
- (modified) lldb/test/API/linux/aarch64/mte_core_file/core.nomte ()
- (modified) lldb/test/API/linux/aarch64/mte_core_file/main.c (+1-1)
``diff
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py
b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index a4ff96e4158ce..a47ffabdecd0e 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -1380,6 +1380,9 @@ def isAArch64SMEFA64(self):
def isAArch64MTE(self):
return self.isAArch64() and "mte" in self.getCPUInfo()
+def isAArch64MTEStoreOnly(self):
+return self.isAArch64() and "mtestoreonly" in self.getCPUInfo()
+
def isAArch64GCS(self):
return self.isAArch64() and "gcs" in self.getCPUInfo()
diff --git
a/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm64.cpp
b/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm64.cpp
index 7adc00622ec2d..d21dac221aa22 100644
--- a/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm64.cpp
+++ b/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm64.cpp
@@ -44,7 +44,8 @@
NativeRegisterContextFreeBSD::CreateHostNativeRegisterContextFreeBSD(
NativeProcessFreeBSD &process = native_thread.GetProcess();
g_register_flags_detector.DetectFields(
process.GetAuxValue(AuxVector::AUXV_FREEBSD_AT_HWCAP).value_or(0),
-process.GetAuxValue(AuxVector::AUXV_AT_HWCAP2).value_or(0));
+process.GetAuxValue(AuxVector::AUXV_AT_HWCAP2).value_or(0),
+/*hwcap3=*/0);
}
return new NativeRegisterContextFreeBSD_arm64(target_arch, native_thread);
diff --git
a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
index 884c7d4b9e359..b1c7421bef8d5 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
@@ -162,10 +162,13 @@
NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(
opt_regsets.Set(RegisterInfoPOSIX_arm64::eRegsetMaskTLS);
+std::optional auxv_at_hwcap3 =
+process.GetAuxValue(AuxVector::AUXV_AT_HWCAP3);
std::lock_guard lock(g_register_flags_detector_mutex);
if (!g_register_flags_detector.HasDetected())
g_register_flags_detector.DetectFields(auxv_at_hwcap.value_or(0),
- auxv_at_hwcap2.value_or(0));
+ auxv_at_hwcap2.value_or(0),
+ auxv_at_hwcap3.value_or(0));
auto register_info_up =
std::make_unique(target_arch, opt_regsets);
diff --git a/lldb/source/Plugins/Process/Utility/AuxVector.cpp
b/lldb/source/Plugins/Process/Utility/AuxVector.cpp
index f495ffb1924e7..50500a8593e1d 100644
--- a/lldb/source/Plugins/Process/Utility/AuxVector.cpp
+++ b/lldb/source/Plugins/Process/Utility/AuxVector.cpp
@@ -84,6 +84,7 @@ const char *AuxVector::GetEntryName(EntryType type) const {
case ENTRY_NAME(AUXV_AT_BASE_PLATFORM); break;
case ENTRY_NAME(AUXV_AT_RANDOM); break;
case ENTRY_NAME(AUXV_AT_HWCAP2); break;
+case ENTRY_NAME(AUXV_AT_HWCAP3); break;
case ENTRY_NAME(AUXV_AT_EXECFN); break;
case ENTRY_NAME(AUXV_AT_SYSINFO);break;
case ENTRY_NAME(AUXV_AT_SYSINFO_EHDR); break;
diff --git a/lldb/source/Plugins/Process/Utility/AuxVector.h
b/lldb/source/Plugins/Process/Utility/AuxVector.h
index 2670b34f6b0af..7733e0ffc6832 100644
--- a/lldb/source/Plugins/Process/Utility/AuxVector.h
+++ b/lldb/source/Plugins/Process/Utility/AuxVector.h
@@ -
[llvm-branch-commits] [llvm] [AMDGPU] Improve StructurizeCFG pass performance by using SSAUpdaterBulk. (PR #150937)
vpykhtin wrote: > Can you request an internal psdb full cycle to test this PR? StructurizeCFG > seems very sensitive to changes and has caused a lot of downstream failures. I did that before and it passed, but I'll double check, thanks! https://github.com/llvm/llvm-project/pull/150937 ___ llvm-branch-commits mailing list [email protected] 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)
@@ -222,3 +222,8 @@ void foo() {
// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "A",
// CHECK-SAME: DIFlagFwdDecl
+
+// There is a full definition of the type available in the module.
+// CHECKCOFF: !DICompositeType(tag: DW_TAG_structure_type, name: "Virtual",
+// CHECKCOFF-SAME: DIFlagFwdDecl
+// CHECKCOFF-SAME: identifier: "_ZTS7Virtual")
kikairoya wrote:
To be honest, I'm not quite sure why this change happens, as this diff is
basically just a revert.
But your assumption sounds reasonable to me.
As you said, vtable-debug-info-inheritance-simple.cpp asserts that MinGW
doesn't emit the debug info.
https://github.com/llvm/llvm-project/pull/150938
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [C23] More improved type compatibility for enumerations (PR #151199)
llvmbot wrote:
@llvm/pr-subscribers-clang
Author: Aaron Ballman (AaronBallman)
Changes
The structural equivalence checker was not paying attention to whether
enumerations had compatible fixed underlying types or not.
Fixes #150594
---
Full diff: https://github.com/llvm/llvm-project/pull/151199.diff
6 Files Affected:
- (modified) clang/include/clang/Basic/DiagnosticASTKinds.td (+8)
- (modified) clang/lib/AST/ASTStructuralEquivalence.cpp (+42)
- (added) clang/test/ASTMerge/enum/Inputs/enum3.c (+14)
- (added) clang/test/ASTMerge/enum/Inputs/enum4.c (+14)
- (added) clang/test/ASTMerge/enum/test2.c (+16)
- (modified) clang/test/C/C23/n3037.c (+74)
``diff
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index a67b9995d3b54..4c7219c78c8bc 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -507,6 +507,14 @@ def note_odr_number_of_bases : Note<
"class has %0 base %plural{1:class|:classes}0">;
def note_odr_enumerator : Note<"enumerator %0 with value %1 here">;
def note_odr_missing_enumerator : Note<"no corresponding enumerator here">;
+def note_odr_incompatible_fixed_underlying_type : Note<
+ "enumeration %0 declared with incompatible fixed underlying types (%1 vs. "
+ "%2)">;
+def note_odr_fixed_underlying_type : Note<
+ "enumeration %0 has fixed underlying type here">;
+def note_odr_missing_fixed_underlying_type : Note<
+ "enumeration %0 missing fixed underlying type here">;
+
def err_odr_field_type_inconsistent : Error<
"field %0 declared with incompatible types in different "
"translation units (%1 vs. %2)">;
diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 3aa6b37844103..e26b3eaa81969 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -2067,6 +2067,48 @@ static bool
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
!CheckStructurallyEquivalentAttributes(Context, D1, D2))
return false;
+ // In C23, if one enumeration has a fixed underlying type, the other shall
+ // have a compatible fixed underlying type (6.2.7).
+ if (Context.LangOpts.C23) {
+if (D1->isFixed() != D2->isFixed()) {
+ if (Context.Complain) {
+Context.Diag2(D2->getLocation(),
+ Context.getApplicableDiagnostic(
+ diag::err_odr_tag_type_inconsistent))
+<< Context.ToCtx.getTypeDeclType(D2)
+<< (&Context.FromCtx != &Context.ToCtx);
+Context.Diag1(D1->getLocation(),
+ D1->isFixed()
+ ? diag::note_odr_fixed_underlying_type
+ : diag::note_odr_missing_fixed_underlying_type)
+<< D1;
+Context.Diag2(D2->getLocation(),
+ D2->isFixed()
+ ? diag::note_odr_fixed_underlying_type
+ : diag::note_odr_missing_fixed_underlying_type)
+<< D2;
+ }
+ return false;
+}
+if (D1->isFixed()) {
+ assert(D2->isFixed() && "enums expected to have fixed underlying types");
+ if (!IsStructurallyEquivalent(Context, D1->getIntegerType(),
+D2->getIntegerType())) {
+if (Context.Complain) {
+ Context.Diag2(D2->getLocation(),
+Context.getApplicableDiagnostic(
+diag::err_odr_tag_type_inconsistent))
+ << Context.ToCtx.getTypeDeclType(D2)
+ << (&Context.FromCtx != &Context.ToCtx);
+ Context.Diag2(D2->getLocation(),
+diag::note_odr_incompatible_fixed_underlying_type)
+ << D2 << D2->getIntegerType() << D1->getIntegerType();
+}
+return false;
+ }
+}
+ }
+
llvm::SmallVector D1Enums, D2Enums;
auto CopyEnumerators =
[](auto &&Range, llvm::SmallVectorImpl &Cont) {
diff --git a/clang/test/ASTMerge/enum/Inputs/enum3.c
b/clang/test/ASTMerge/enum/Inputs/enum3.c
new file mode 100644
index 0..32ad5366434ac
--- /dev/null
+++ b/clang/test/ASTMerge/enum/Inputs/enum3.c
@@ -0,0 +1,14 @@
+// [C23] missing underlying types
+enum E1 : int {
+ E1Enumerator1
+};
+
+enum E2 {
+ E2Enumerator1
+};
+
+// [C23] Incompatible underlying types
+enum E3 : long {
+ E3Enumerator1
+};
+
diff --git a/clang/test/ASTMerge/enum/Inputs/enum4.c
b/clang/test/ASTMerge/enum/Inputs/enum4.c
new file mode 100644
index 0..15f5c603c7abb
--- /dev/null
+++ b/clang/test/ASTMerge/enum/Inputs/enum4.c
@@ -0,0 +1,14 @@
+// [C23] missing underlying types
+enum E1 {
+ E1Enumerator1
+};
+
+enum E2 : int {
+ E2Enumerator1
+};
+
+// [C23] Incompatible underlying types
+enum E3 : short {
+ E3Enumerator1
+};
+
diff --git a/clang/test/ASTMerge/enum/test2.c b/clang/test/ASTMerge/enum/test2.c
new file m
[llvm-branch-commits] [compiler-rt] release/21.x: [scudo] Make Ptr volatile so that the malloc and free calls are not optimized out (#149944) (PR #151201)
llvmbot wrote:
@llvm/pr-subscribers-compiler-rt-sanitizer
Author: None (llvmbot)
Changes
Backport fcdcc4ea7ac960c79246b3bd428f14ea350e63e2
Requested by: @mgorny
---
Full diff: https://github.com/llvm/llvm-project/pull/151201.diff
1 Files Affected:
- (modified) compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp (+2-1)
``diff
diff --git a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
index 05065444a70c5..612317b3c3293 100644
--- a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
@@ -183,7 +183,8 @@ TEST_F(ScudoWrappersCDeathTest, Malloc) {
// process doing free(P) is not a double free.
EXPECT_DEATH(
{
-void *Ptr = malloc(Size);
+// Note: volatile here prevents the calls from being optimized out.
+void *volatile Ptr = malloc(Size);
free(Ptr);
free(Ptr);
},
``
https://github.com/llvm/llvm-project/pull/151201
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] release/21.x: [scudo] Make Ptr volatile so that the malloc and free calls are not optimized out (#149944) (PR #151201)
https://github.com/llvmbot created
https://github.com/llvm/llvm-project/pull/151201
Backport fcdcc4ea7ac960c79246b3bd428f14ea350e63e2
Requested by: @mgorny
>From 402baf292c61c3a8f2916ac6abc4b3b93597c640 Mon Sep 17 00:00:00 2001
From: Fabio D'Urso
Date: Tue, 22 Jul 2025 03:31:35 +0200
Subject: [PATCH] [scudo] Make Ptr volatile so that the malloc and free calls
are not optimized out (#149944)
This fixes the test failure seen in the discussion about
https://github.com/llvm/llvm-project/pull/148066.
(cherry picked from commit fcdcc4ea7ac960c79246b3bd428f14ea350e63e2)
---
compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
index 05065444a70c5..612317b3c3293 100644
--- a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
@@ -183,7 +183,8 @@ TEST_F(ScudoWrappersCDeathTest, Malloc) {
// process doing free(P) is not a double free.
EXPECT_DEATH(
{
-void *Ptr = malloc(Size);
+// Note: volatile here prevents the calls from being optimized out.
+void *volatile Ptr = malloc(Size);
free(Ptr);
free(Ptr);
},
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] release/21.x: [scudo] Make Ptr volatile so that the malloc and free calls are not optimized out (#149944) (PR #151201)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/151201 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] release/21.x: [scudo] Make Ptr volatile so that the malloc and free calls are not optimized out (#149944) (PR #151201)
llvmbot wrote: @cferris1000 What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/151201 ___ llvm-branch-commits mailing list [email protected] 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)
https://github.com/bassiounix updated
https://github.com/llvm/llvm-project/pull/150854
>From 3930b0f9886d2ec449e6f2126120f5ba3e7e48f7 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 atan2f128 implementation to header-only in src/__support/math folder. (PR #151012)
https://github.com/bassiounix updated
https://github.com/llvm/llvm-project/pull/151012
>From fa5283fdad6b26748a27ab6aa39b7e6c2a3d179d Mon Sep 17 00:00:00 2001
From: bassiounix
Date: Mon, 28 Jul 2025 21:14:48 +0300
Subject: [PATCH 1/2] [libc][math] Refactor atan2f128 implementation to
header-only in src/__support/math folder.
---
libc/shared/math.h| 1 +
libc/shared/math/atan2f128.h | 29 +++
libc/src/__support/math/CMakeLists.txt| 15 ++
libc/src/__support/math/atan2f128.h | 212 ++
libc/src/math/generic/CMakeLists.txt | 10 +-
libc/src/math/generic/atan2f128.cpp | 190 +---
libc/test/shared/shared_math_test.cpp | 2 +
.../llvm-project-overlay/libc/BUILD.bazel | 24 +-
8 files changed, 284 insertions(+), 199 deletions(-)
create mode 100644 libc/shared/math/atan2f128.h
create mode 100644 libc/src/__support/math/atan2f128.h
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 527bb8d6214ae..6cb583c08dedd 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -25,6 +25,7 @@
#include "math/atan.h"
#include "math/atan2.h"
#include "math/atan2f.h"
+#include "math/atan2f128.h"
#include "math/atanf.h"
#include "math/atanf16.h"
#include "math/erff.h"
diff --git a/libc/shared/math/atan2f128.h b/libc/shared/math/atan2f128.h
new file mode 100644
index 0..d7aee40c69527
--- /dev/null
+++ b/libc/shared/math/atan2f128.h
@@ -0,0 +1,29 @@
+//===-- Shared atan2f128 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_ATAN2F128_H
+#define LLVM_LIBC_SHARED_MATH_ATAN2F128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/atan2f128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::atan2f128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_ATAN2F128_H
diff --git a/libc/src/__support/math/CMakeLists.txt
b/libc/src/__support/math/CMakeLists.txt
index c197b19ed29de..caafdc2cbf1d6 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -230,6 +230,21 @@ add_header_library(
libc.src.__support.macros.optimization
)
+add_header_library(
+ atan2f128
+ HDRS
+atan2f128.h
+ DEPENDS
+.atan_utils
+libc.src.__support.integer_literals
+libc.src.__support.uint128
+libc.src.__support.FPUtil.dyadic_float
+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(
atanf
HDRS
diff --git a/libc/src/__support/math/atan2f128.h
b/libc/src/__support/math/atan2f128.h
new file mode 100644
index 0..89efaf1fd72a0
--- /dev/null
+++ b/libc/src/__support/math/atan2f128.h
@@ -0,0 +1,212 @@
+//===-- Implementation header for atan2f128 -*- 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_ATAN2F128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ATAN2F128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "atan_utils.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/dyadic_float.h"
+#include "src/__support/FPUtil/nearest_integer.h"
+#include "src/__support/integer_literals.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
+#include "src/__support/uint128.h"
+
+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)
+// = atan( y/x ) if x >= 0 and y < 0 (IV-quadrant)
+// Since atan function is odd, we can use the formula:
+// atan(-u) = -atan(u)
+// to adjust the a
[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atan2f implementation to header-only in src/__support/math folder. (PR #150993)
https://github.com/bassiounix updated
https://github.com/llvm/llvm-project/pull/150993
>From a2300a69d17e0299bda72813c95b3eb5c8d7d883 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);
+// b = round(atan(i/16) - a, D, RN);
+// print("{", b, ",", a, "},");
+// };
+static constexpr fputil::DoubleDouble ATAN_I[17] = {
+{0.0, 0.0},
+{-0x1.c934d86d23
[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atanf16 implementation to header-only in src/__support/math folder. (PR #150868)
https://github.com/bassiounix updated
https://github.com/llvm/llvm-project/pull/150868
>From a4910961081ff7a6cc9aa0ea43aca57db23942c3 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)
https://github.com/bassiounix updated
https://github.com/llvm/llvm-project/pull/150968
>From d411e7849f1cf9d0b1f31def4bdd2b126363bd6a 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)
https://github.com/bassiounix updated
https://github.com/llvm/llvm-project/pull/150993
>From a2300a69d17e0299bda72813c95b3eb5c8d7d883 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);
+// b = round(atan(i/16) - a, D, RN);
+// print("{", b, ",", a, "},");
+// };
+static constexpr fputil::DoubleDouble ATAN_I[17] = {
+{0.0, 0.0},
+{-0x1.c934d86d23
[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atanf16 implementation to header-only in src/__support/math folder. (PR #150868)
https://github.com/bassiounix updated
https://github.com/llvm/llvm-project/pull/150868
>From a4910961081ff7a6cc9aa0ea43aca57db23942c3 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 atan2f128 implementation to header-only in src/__support/math folder. (PR #151012)
https://github.com/bassiounix updated
https://github.com/llvm/llvm-project/pull/151012
>From fa5283fdad6b26748a27ab6aa39b7e6c2a3d179d Mon Sep 17 00:00:00 2001
From: bassiounix
Date: Mon, 28 Jul 2025 21:14:48 +0300
Subject: [PATCH 1/2] [libc][math] Refactor atan2f128 implementation to
header-only in src/__support/math folder.
---
libc/shared/math.h| 1 +
libc/shared/math/atan2f128.h | 29 +++
libc/src/__support/math/CMakeLists.txt| 15 ++
libc/src/__support/math/atan2f128.h | 212 ++
libc/src/math/generic/CMakeLists.txt | 10 +-
libc/src/math/generic/atan2f128.cpp | 190 +---
libc/test/shared/shared_math_test.cpp | 2 +
.../llvm-project-overlay/libc/BUILD.bazel | 24 +-
8 files changed, 284 insertions(+), 199 deletions(-)
create mode 100644 libc/shared/math/atan2f128.h
create mode 100644 libc/src/__support/math/atan2f128.h
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 527bb8d6214ae..6cb583c08dedd 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -25,6 +25,7 @@
#include "math/atan.h"
#include "math/atan2.h"
#include "math/atan2f.h"
+#include "math/atan2f128.h"
#include "math/atanf.h"
#include "math/atanf16.h"
#include "math/erff.h"
diff --git a/libc/shared/math/atan2f128.h b/libc/shared/math/atan2f128.h
new file mode 100644
index 0..d7aee40c69527
--- /dev/null
+++ b/libc/shared/math/atan2f128.h
@@ -0,0 +1,29 @@
+//===-- Shared atan2f128 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_ATAN2F128_H
+#define LLVM_LIBC_SHARED_MATH_ATAN2F128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/atan2f128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::atan2f128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_ATAN2F128_H
diff --git a/libc/src/__support/math/CMakeLists.txt
b/libc/src/__support/math/CMakeLists.txt
index c197b19ed29de..caafdc2cbf1d6 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -230,6 +230,21 @@ add_header_library(
libc.src.__support.macros.optimization
)
+add_header_library(
+ atan2f128
+ HDRS
+atan2f128.h
+ DEPENDS
+.atan_utils
+libc.src.__support.integer_literals
+libc.src.__support.uint128
+libc.src.__support.FPUtil.dyadic_float
+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(
atanf
HDRS
diff --git a/libc/src/__support/math/atan2f128.h
b/libc/src/__support/math/atan2f128.h
new file mode 100644
index 0..89efaf1fd72a0
--- /dev/null
+++ b/libc/src/__support/math/atan2f128.h
@@ -0,0 +1,212 @@
+//===-- Implementation header for atan2f128 -*- 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_ATAN2F128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ATAN2F128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "atan_utils.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/dyadic_float.h"
+#include "src/__support/FPUtil/nearest_integer.h"
+#include "src/__support/integer_literals.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
+#include "src/__support/uint128.h"
+
+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)
+// = atan( y/x ) if x >= 0 and y < 0 (IV-quadrant)
+// Since atan function is odd, we can use the formula:
+// atan(-u) = -atan(u)
+// to adjust the a
[llvm-branch-commits] [libc] [llvm] [libc][math] Refactor atan2 implementation to header-only in src/__support/math folder. (PR #150968)
https://github.com/bassiounix updated
https://github.com/llvm/llvm-project/pull/150968
>From d411e7849f1cf9d0b1f31def4bdd2b126363bd6a 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)
https://github.com/bassiounix updated
https://github.com/llvm/llvm-project/pull/150854
>From 3930b0f9886d2ec449e6f2126120f5ba3e7e48f7 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] [clang] [C23] More improved type compatibility for enumerations (PR #151199)
https://github.com/AaronBallman created
https://github.com/llvm/llvm-project/pull/151199
The structural equivalence checker was not paying attention to whether
enumerations had compatible fixed underlying types or not.
Fixes #150594
>From 47f3ab2fc30f8587226e3d89e2646fd4e029cdf6 Mon Sep 17 00:00:00 2001
From: Aaron Ballman
Date: Tue, 29 Jul 2025 13:30:52 -0400
Subject: [PATCH] [C23] More improved type compatibility for enumerations
(#150946)
The structural equivalence checker was not paying attention to whether
enumerations had compatible fixed underlying types or not.
Fixes #150594
---
.../include/clang/Basic/DiagnosticASTKinds.td | 8 ++
clang/lib/AST/ASTStructuralEquivalence.cpp| 42 +++
clang/test/ASTMerge/enum/Inputs/enum3.c | 14
clang/test/ASTMerge/enum/Inputs/enum4.c | 14
clang/test/ASTMerge/enum/test2.c | 16
clang/test/C/C23/n3037.c | 74 +++
6 files changed, 168 insertions(+)
create mode 100644 clang/test/ASTMerge/enum/Inputs/enum3.c
create mode 100644 clang/test/ASTMerge/enum/Inputs/enum4.c
create mode 100644 clang/test/ASTMerge/enum/test2.c
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index a67b9995d3b54..4c7219c78c8bc 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -507,6 +507,14 @@ def note_odr_number_of_bases : Note<
"class has %0 base %plural{1:class|:classes}0">;
def note_odr_enumerator : Note<"enumerator %0 with value %1 here">;
def note_odr_missing_enumerator : Note<"no corresponding enumerator here">;
+def note_odr_incompatible_fixed_underlying_type : Note<
+ "enumeration %0 declared with incompatible fixed underlying types (%1 vs. "
+ "%2)">;
+def note_odr_fixed_underlying_type : Note<
+ "enumeration %0 has fixed underlying type here">;
+def note_odr_missing_fixed_underlying_type : Note<
+ "enumeration %0 missing fixed underlying type here">;
+
def err_odr_field_type_inconsistent : Error<
"field %0 declared with incompatible types in different "
"translation units (%1 vs. %2)">;
diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 3aa6b37844103..e26b3eaa81969 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -2067,6 +2067,48 @@ static bool
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
!CheckStructurallyEquivalentAttributes(Context, D1, D2))
return false;
+ // In C23, if one enumeration has a fixed underlying type, the other shall
+ // have a compatible fixed underlying type (6.2.7).
+ if (Context.LangOpts.C23) {
+if (D1->isFixed() != D2->isFixed()) {
+ if (Context.Complain) {
+Context.Diag2(D2->getLocation(),
+ Context.getApplicableDiagnostic(
+ diag::err_odr_tag_type_inconsistent))
+<< Context.ToCtx.getTypeDeclType(D2)
+<< (&Context.FromCtx != &Context.ToCtx);
+Context.Diag1(D1->getLocation(),
+ D1->isFixed()
+ ? diag::note_odr_fixed_underlying_type
+ : diag::note_odr_missing_fixed_underlying_type)
+<< D1;
+Context.Diag2(D2->getLocation(),
+ D2->isFixed()
+ ? diag::note_odr_fixed_underlying_type
+ : diag::note_odr_missing_fixed_underlying_type)
+<< D2;
+ }
+ return false;
+}
+if (D1->isFixed()) {
+ assert(D2->isFixed() && "enums expected to have fixed underlying types");
+ if (!IsStructurallyEquivalent(Context, D1->getIntegerType(),
+D2->getIntegerType())) {
+if (Context.Complain) {
+ Context.Diag2(D2->getLocation(),
+Context.getApplicableDiagnostic(
+diag::err_odr_tag_type_inconsistent))
+ << Context.ToCtx.getTypeDeclType(D2)
+ << (&Context.FromCtx != &Context.ToCtx);
+ Context.Diag2(D2->getLocation(),
+diag::note_odr_incompatible_fixed_underlying_type)
+ << D2 << D2->getIntegerType() << D1->getIntegerType();
+}
+return false;
+ }
+}
+ }
+
llvm::SmallVector D1Enums, D2Enums;
auto CopyEnumerators =
[](auto &&Range, llvm::SmallVectorImpl &Cont) {
diff --git a/clang/test/ASTMerge/enum/Inputs/enum3.c
b/clang/test/ASTMerge/enum/Inputs/enum3.c
new file mode 100644
index 0..32ad5366434ac
--- /dev/null
+++ b/clang/test/ASTMerge/enum/Inputs/enum3.c
@@ -0,0 +1,14 @@
+// [C23] missing underlying types
+enum E1 : int {
+ E1Enumerator1
+};
+
+enum E2 {
+ E2Enumerator1
+};
+
+// [C23] Incompatible underlying types
+enum E3 : long {
+ E3Enumerator1
+};
+
diff --git a/clang/test/
[llvm-branch-commits] [clang] [C23] More improved type compatibility for enumerations (PR #151199)
https://github.com/AaronBallman milestoned https://github.com/llvm/llvm-project/pull/151199 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] AMDGPU: Figure out required AGPR count for inline asm (PR #150910)
@@ -1200,16 +1200,61 @@ AAAMDWavesPerEU
&AAAMDWavesPerEU::createForPosition(const IRPosition &IRP,
llvm_unreachable("AAAMDWavesPerEU is only valid for function position");
}
-static bool inlineAsmUsesAGPRs(const InlineAsm *IA) {
- for (const auto &CI : IA->ParseConstraints()) {
+/// Compute the minimum number of AGPRs required to allocate the inline asm.
+static unsigned inlineAsmGetNumRequiredAGPRs(const InlineAsm *IA,
+ const CallBase &Call) {
+ unsigned ArgNo = 0;
+ unsigned ResNo = 0;
+ unsigned AGPRDefCount = 0;
+ unsigned AGPRUseCount = 0;
+ unsigned MaxPhysReg = 0;
+ const DataLayout &DL = Call.getFunction()->getParent()->getDataLayout();
+
+ for (const InlineAsm::ConstraintInfo &CI : IA->ParseConstraints()) {
+Type *Ty = nullptr;
+switch (CI.Type) {
+case InlineAsm::isOutput: {
+ Ty = Call.getType();
+ if (auto *STy = dyn_cast(Ty))
+Ty = STy->getElementType(ResNo);
+ ++ResNo;
+ break;
+}
+case InlineAsm::isInput: {
+ Ty = Call.getArgOperand(ArgNo++)->getType();
+ break;
+}
+case InlineAsm::isLabel:
+ continue;
+case InlineAsm::isClobber:
+ // Parse the physical register reference.
+ break;
+}
+
for (StringRef Code : CI.Codes) {
- Code.consume_front("{");
- if (Code.starts_with("a"))
-return true;
+ if (Code.starts_with("a")) {
+// Virtual register, compute number of registers based on the type.
+//
+// We ought to be going through TargetLowering to get the number of
+// registers, but we should avoid the dependence on CodeGen here.
+unsigned RegCount = divideCeil(DL.getTypeSizeInBits(Ty), 32);
+if (CI.Type == InlineAsm::isOutput) {
+ AGPRDefCount += RegCount;
+ if (CI.isEarlyClobber)
+AGPRUseCount += RegCount;
+} else
+ AGPRUseCount += RegCount;
+ } else {
+// Physical register reference
+auto [Kind, RegIdx, NumRegs] = AMDGPU::parseAsmConstraintPhysReg(Code);
+if (Kind == 'a')
+ MaxPhysReg = std::max(MaxPhysReg, std::min(RegIdx + NumRegs, 256u));
+ }
}
}
- return false;
+ unsigned MaxVirtReg = std::max(AGPRUseCount, AGPRDefCount);
+ return std::min(MaxVirtReg + MaxPhysReg, 256u);
ritter-x2a wrote:
Is it intended that this overestimates the AGPR requirement if a physical
register and a number of virtual registers that would fit into the register
file before the physical register are requested?
For example `{a[31]}` and up to 31 `a` constraints for virtual registers: This
would report 63 registers, but 32 (`a0` through `a31`) should be enough, right?
https://github.com/llvm/llvm-project/pull/150910
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/21.x: [llvm][release] Add links to commonly used release packages (#147719) (PR #151129)
llvmbot wrote:
@llvm/pr-subscribers-github-workflow
Author: None (llvmbot)
Changes
Backport e8b7183d866f9d51511d5570f5f1f632046ef983
Requested by: @DavidSpickett
---
Full diff: https://github.com/llvm/llvm-project/pull/151129.diff
2 Files Affected:
- (modified) .github/workflows/release-tasks.yml (+28)
- (modified) llvm/utils/release/github-upload-release.py (+55-7)
``diff
diff --git a/.github/workflows/release-tasks.yml
b/.github/workflows/release-tasks.yml
index d55098345d89e..c9ae7e1ce97c3 100644
--- a/.github/workflows/release-tasks.yml
+++ b/.github/workflows/release-tasks.yml
@@ -111,3 +111,31 @@ jobs:
# Called workflows don't have access to secrets by default, so we need to
explicitly pass secrets that we use.
secrets:
RELEASE_TASKS_USER_TOKEN: ${{ secrets.RELEASE_TASKS_USER_TOKEN }}
+
+ uncomment-download-links:
+name: Uncomment download links
+runs-on: ubuntu-24.04
+permissions:
+ contents: write # For updating the release message.
+needs:
+ - validate-tag
+ - release-create
+ - release-binaries
+
+steps:
+ - name: Install Dependencies
+run: |
+ sudo apt-get update
+ sudo apt-get install python3-github
+
+ - name: Checkout LLVM
+uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 #
v4.1.1
+with:
+ sparse-checkout: llvm/utils/release/github-upload-release.py
+ sparse-checkout-cone-mode: false
+
+ - name: Uncomment Download Links
+env:
+ GITHUB_TOKEN: ${{ github.token }}
+run: |
+ ./llvm/utils/release/./github-upload-release.py --token
"$GITHUB_TOKEN" --release ${{ needs.validate-tag.outputs.release-version }}
uncomment_download_links
diff --git a/llvm/utils/release/github-upload-release.py
b/llvm/utils/release/github-upload-release.py
index 90c222d1175c7..5ed037ee9522a 100755
--- a/llvm/utils/release/github-upload-release.py
+++ b/llvm/utils/release/github-upload-release.py
@@ -45,19 +45,39 @@ def create_release(repo, release, tag=None, name=None,
message=None):
# Note that these lines are not length limited because if we do so,
GitHub
# assumes that should be how it is laid out on the page. We want
GitHub to
# do the reflowing for us instead.
+#
+# Once all the atuomatic binary builds have completed, the HTML
comments
+# with UPPERCASE markers in them will be removed to reveal the download
+# links later. Other lines are surrounded in for release
uploaders
+# to manually uncomment when they upload that package.
message = dedent(
"""\
-LLVM {release} Release
+## LLVM {release} Release
-## Package Types
+
+
-Each platform has one binary release package. The file name starts with either
`LLVM-` or `clang+llvm-` and ends with the platform's name. For example,
`LLVM-{release}-Linux-ARM64.tar.xz` contains LLVM binaries for Arm64 Linux.
+
+
+
+
+
-Except for Windows. Where `LLVM-*.exe` is an installer intended for using LLVM
as a toolchain and `clang+llvm-` contains the contents of the installer, plus
libraries and tools not normally used in a toolchain. You most likely want the
`LLVM-` installer, unless you are developing software which itself uses LLVM,
in which case choose `clang+llvm-`.
+Download links will appear here once builds have completed.
+
+For any other variants of platform and architecture, check the full list of
release packages at the bottom of this release page. If you do not find a
release package for your platform, you may be able to find a community built
package on the LLVM Discourse forum thread for this release. Remember that
these are built by volunteers and may not always be available. If you rely on a
platform or configuration that is not one of the defaults, we suggest you use
the binaries that your platform provides, or build your own release packages.
+
+## Package Types
-If you do not find a release package for your platform, you may be able to
find a community built package on the LLVM Discourse forum thread for this
release. Remember that these are built by volunteers and may not always be
available.
+Each platform has one binary release package. The file name starts with either
`LLVM-` or `clang+llvm-` and ends with the platform's name. For example,
`LLVM-{release}-Linux-ARM64.tar.xz` contains LLVM binaries for Arm64 Linux.
-If you rely on a platform or configuration that is not one of the defaults, we
suggest you use the binaries that your platform provides, or build your own
release packages.
+Except for Windows. Where `LLVM-*.exe` is an installer intended for using LLVM
as a toolchain and the archive `clang+llvm-` contains the contents of the
installer, plus libraries and tools not normally used in a toolchain. You most
likely want the `LLVM-` installer, unless you are developing software which
itself uses LLVM, in which case choose `
[llvm-branch-commits] [llvm] release/21.x: [llvm][release] Add links to commonly used release packages (#147719) (PR #151129)
https://github.com/llvmbot created
https://github.com/llvm/llvm-project/pull/151129
Backport e8b7183d866f9d51511d5570f5f1f632046ef983
Requested by: @DavidSpickett
>From 4d490b23f8fe4b20833de479456a1b0032d0b28d Mon Sep 17 00:00:00 2001
From: David Spickett
Date: Tue, 29 Jul 2025 12:35:15 +0100
Subject: [PATCH] [llvm][release] Add links to commonly used release packages
(#147719)
This adds download links to the GitHub release pages for common
platforms. The automatically built packages' links are automatically
revealed once the builds are complete. For packages built by hand,
hidden links are included in the text for release uploaders to reveal
later.
The approach taken:
* "LLVM x.y.z Release" becomes the title for this links section.
* Automatically built packages are commented out with special markers so
we can find them to uncomment them later.
* There is placeholder text for the time between release creation and
release tasks finishing.
* Hand built packages have release links but these will need to be
un-commented by release uploaders.
* I have used vendor names for the architectures, that casual users
would recognise.
* Their signature file is linked as well. I expect most will ignore this
but better to show it to remind people it exists.
* I called it "signature" as a generic term to cover the .jsonl and .sig
files. Instructions to use these were added to the text in a previous
change.
(cherry picked from commit e8b7183d866f9d51511d5570f5f1f632046ef983)
---
.github/workflows/release-tasks.yml | 28 ++
llvm/utils/release/github-upload-release.py | 62 ++---
2 files changed, 83 insertions(+), 7 deletions(-)
diff --git a/.github/workflows/release-tasks.yml
b/.github/workflows/release-tasks.yml
index d55098345d89e..c9ae7e1ce97c3 100644
--- a/.github/workflows/release-tasks.yml
+++ b/.github/workflows/release-tasks.yml
@@ -111,3 +111,31 @@ jobs:
# Called workflows don't have access to secrets by default, so we need to
explicitly pass secrets that we use.
secrets:
RELEASE_TASKS_USER_TOKEN: ${{ secrets.RELEASE_TASKS_USER_TOKEN }}
+
+ uncomment-download-links:
+name: Uncomment download links
+runs-on: ubuntu-24.04
+permissions:
+ contents: write # For updating the release message.
+needs:
+ - validate-tag
+ - release-create
+ - release-binaries
+
+steps:
+ - name: Install Dependencies
+run: |
+ sudo apt-get update
+ sudo apt-get install python3-github
+
+ - name: Checkout LLVM
+uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 #
v4.1.1
+with:
+ sparse-checkout: llvm/utils/release/github-upload-release.py
+ sparse-checkout-cone-mode: false
+
+ - name: Uncomment Download Links
+env:
+ GITHUB_TOKEN: ${{ github.token }}
+run: |
+ ./llvm/utils/release/./github-upload-release.py --token
"$GITHUB_TOKEN" --release ${{ needs.validate-tag.outputs.release-version }}
uncomment_download_links
diff --git a/llvm/utils/release/github-upload-release.py
b/llvm/utils/release/github-upload-release.py
index 90c222d1175c7..5ed037ee9522a 100755
--- a/llvm/utils/release/github-upload-release.py
+++ b/llvm/utils/release/github-upload-release.py
@@ -45,19 +45,39 @@ def create_release(repo, release, tag=None, name=None,
message=None):
# Note that these lines are not length limited because if we do so,
GitHub
# assumes that should be how it is laid out on the page. We want
GitHub to
# do the reflowing for us instead.
+#
+# Once all the atuomatic binary builds have completed, the HTML
comments
+# with UPPERCASE markers in them will be removed to reveal the download
+# links later. Other lines are surrounded in for release
uploaders
+# to manually uncomment when they upload that package.
message = dedent(
"""\
-LLVM {release} Release
+## LLVM {release} Release
-## Package Types
+
+
-Each platform has one binary release package. The file name starts with either
`LLVM-` or `clang+llvm-` and ends with the platform's name. For example,
`LLVM-{release}-Linux-ARM64.tar.xz` contains LLVM binaries for Arm64 Linux.
+
+
+
+
+
-Except for Windows. Where `LLVM-*.exe` is an installer intended for using LLVM
as a toolchain and `clang+llvm-` contains the contents of the installer, plus
libraries and tools not normally used in a toolchain. You most likely want the
`LLVM-` installer, unless you are developing software which itself uses LLVM,
in which case choose `clang+llvm-`.
+Download links will appear here once builds have completed.
+
+For any other variants of platform and architecture, check the full list of
release packages at the bottom of this release page. If you do not find a
release package for your platform, you may be able to find a community built
package on the LLVM Discourse forum thread for this releas
[llvm-branch-commits] [llvm] release/21.x: [llvm][release] Add links to commonly used release packages (#147719) (PR #151129)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/151129 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/21.x: [llvm][release] Add links to commonly used release packages (#147719) (PR #151129)
llvmbot wrote: @tru What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/151129 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] release/21.x: [PAC][compiler-rt] Fix init/fini array signing schema (#150691) (PR #151096)
https://github.com/atrosinenko approved this pull request. https://github.com/llvm/llvm-project/pull/151096 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [GISel] Combine compare of bitfield extracts or'd together. (PR #146055)
https://github.com/Pierre-vh updated
https://github.com/llvm/llvm-project/pull/146055
>From 07869b22ba80f09475faf73b18eb49bdd03bc9b5 Mon Sep 17 00:00:00 2001
From: pvanhout
Date: Fri, 27 Jun 2025 12:04:53 +0200
Subject: [PATCH] [GISel] Combine compare of bitfield extracts or'd together.
Equivalent of the previous DAG patch for GISel.
The shifts are BFXs in GISel, so the canonical form of the entire expression
is different than in the DAG. The mask is not at the root of the expression, it
remains on the leaves instead.
See #136727
---
.../llvm/CodeGen/GlobalISel/CombinerHelper.h | 2 +
.../include/llvm/Target/GlobalISel/Combine.td | 11 +-
.../GlobalISel/CombinerHelperCompares.cpp | 89 +
.../GlobalISel/combine-cmp-merged-bfx.mir | 326 ++
.../CodeGen/AMDGPU/workitem-intrinsic-opts.ll | 194 +++
5 files changed, 483 insertions(+), 139 deletions(-)
create mode 100644
llvm/test/CodeGen/AMDGPU/GlobalISel/combine-cmp-merged-bfx.mir
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h
b/llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h
index da829046cc421..3f1764b48b868 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h
@@ -645,6 +645,8 @@ class CombinerHelper {
/// KnownBits information.
bool matchICmpToLHSKnownBits(MachineInstr &MI, BuildFnTy &MatchInfo) const;
+ bool combineMergedBFXCompare(MachineInstr &MI) const;
+
/// \returns true if (and (or x, c1), c2) can be replaced with (and x, c2)
bool matchAndOrDisjointMask(MachineInstr &MI, BuildFnTy &MatchInfo) const;
diff --git a/llvm/include/llvm/Target/GlobalISel/Combine.td
b/llvm/include/llvm/Target/GlobalISel/Combine.td
index fc81ab76dc72d..c5f13108cd35f 100644
--- a/llvm/include/llvm/Target/GlobalISel/Combine.td
+++ b/llvm/include/llvm/Target/GlobalISel/Combine.td
@@ -1085,6 +1085,14 @@ def double_icmp_zero_or_combine: GICombineRule<
(G_ICMP $root, $p, $ordst, 0))
>;
+// Transform ((X | (G_UBFX X, ...) | ...) == 0) (or != 0)
+// into a compare of a extract/mask of X
+def icmp_merged_bfx_combine: GICombineRule<
+ (defs root:$root),
+ (combine (G_ICMP $dst, $p, $src, 0):$root,
+ [{ return Helper.combineMergedBFXCompare(*${root}); }])
+>;
+
def and_or_disjoint_mask : GICombineRule<
(defs root:$root, build_fn_matchinfo:$info),
(match (wip_match_opcode G_AND):$root,
@@ -2066,7 +2074,8 @@ def all_combines :
GICombineGroup<[integer_reassoc_combines, trivial_combines,
fsub_to_fneg, commute_constant_to_rhs, match_ands, match_ors,
simplify_neg_minmax, combine_concat_vector,
sext_trunc, zext_trunc, prefer_sign_combines, shuffle_combines,
-combine_use_vector_truncate, merge_combines, overflow_combines]>;
+combine_use_vector_truncate, merge_combines, overflow_combines,
+icmp_merged_bfx_combine]>;
// A combine group used to for prelegalizer combiners at -O0. The combines in
// this group have been selected based on experiments to balance code size and
diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelperCompares.cpp
b/llvm/lib/CodeGen/GlobalISel/CombinerHelperCompares.cpp
index fc40533cf3dc9..e1d43f37bac13 100644
--- a/llvm/lib/CodeGen/GlobalISel/CombinerHelperCompares.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelperCompares.cpp
@@ -140,3 +140,92 @@ bool CombinerHelper::matchCanonicalizeFCmp(const
MachineInstr &MI,
return false;
}
+
+bool CombinerHelper::combineMergedBFXCompare(MachineInstr &MI) const {
+ const GICmp *Cmp = cast(&MI);
+
+ ICmpInst::Predicate CC = Cmp->getCond();
+ if (CC != CmpInst::ICMP_EQ && CC != CmpInst::ICMP_NE)
+return false;
+
+ Register CmpLHS = Cmp->getLHSReg();
+ Register CmpRHS = Cmp->getRHSReg();
+
+ LLT OpTy = MRI.getType(CmpLHS);
+ if (!OpTy.isScalar() || OpTy.isPointer())
+return false;
+
+ assert(isZeroOrZeroSplat(CmpRHS, /*AllowUndefs=*/false));
+
+ Register Src;
+ const auto IsSrc = [&](Register R) {
+if (!Src) {
+ Src = R;
+ return true;
+}
+
+return Src == R;
+ };
+
+ MachineInstr *CmpLHSDef = MRI.getVRegDef(CmpLHS);
+ if (CmpLHSDef->getOpcode() != TargetOpcode::G_OR)
+return false;
+
+ APInt PartsMask(OpTy.getSizeInBits(), 0);
+ SmallVector Worklist = {CmpLHSDef};
+ while (!Worklist.empty()) {
+MachineInstr *Cur = Worklist.pop_back_val();
+
+Register Dst = Cur->getOperand(0).getReg();
+if (!MRI.hasOneUse(Dst) && Dst != Src)
+ return false;
+
+if (Cur->getOpcode() == TargetOpcode::G_OR) {
+ Worklist.push_back(MRI.getVRegDef(Cur->getOperand(1).getReg()));
+ Worklist.push_back(MRI.getVRegDef(Cur->getOperand(2).getReg()));
+ continue;
+}
+
+if (Cur->getOpcode() == TargetOpcode::G_UBFX) {
+ Register Op = Cur->getOperand(1).getReg();
+ Register Width = Cur->getOperand(2).getReg();
+ Register Off = Cur->getOperand(3).getReg();
+
+ auto WidthCst = getIConstantVRegVal(Width, MRI);
+ auto
