[llvm-branch-commits] [clang] [llvm] [AArch64][llvm] Add instructions for FEAT_MOPS_GO (PR #164913)
@@ -0,0 +1,89 @@ +// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+mops-go,+mte < %s \ +// RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST +// RUN: not llvm-mc -triple=aarch64 -show-encoding < %s 2>&1 \ +// RUN:| FileCheck %s --check-prefix=CHECK-ERROR +// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+all < %s \ jthackray wrote: Thanks, done. https://github.com/llvm/llvm-project/pull/164913 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [AArch64][llvm] Add instructions for FEAT_MOPS_GO (PR #164913)
@@ -6073,6 +6074,33 @@ bool AArch64AsmParser::validateInstruction(MCInst &Inst,
SMLoc &IDLoc,
" registers are the same");
break;
}
+ case AArch64::SETGOP:
+ case AArch64::SETGOPT:
+ case AArch64::SETGOPN:
+ case AArch64::SETGOPTN:
+ case AArch64::SETGOM:
+ case AArch64::SETGOMT:
+ case AArch64::SETGOMN:
+ case AArch64::SETGOMTN:
+ case AArch64::SETGOE:
+ case AArch64::SETGOET:
+ case AArch64::SETGOEN:
+ case AArch64::SETGOETN: {
+MCRegister Xd_wb = Inst.getOperand(0).getReg();
+MCRegister Xn_wb = Inst.getOperand(1).getReg();
+MCRegister Xd = Inst.getOperand(2).getReg();
+MCRegister Xn = Inst.getOperand(3).getReg();
+if (Xd_wb != Xd)
+ return Error(Loc[0],
+ "invalid SET instruction, Xd_wb and Xd do not match");
+if (Xn_wb != Xn)
+ return Error(Loc[0],
+ "invalid SET instruction, Xn_wb and Xn do not match");
jthackray wrote:
I could change to:
```
[[maybe_unused]] MCRegister Xd_wb = Inst.getOperand(0).getReg();
[[maybe_unused]] MCRegister Xn_wb = Inst.getOperand(1).getReg();
assert(Xd_wb == Xd && "Xd_wb and Xd do not match");
assert(Xn_wb == Xn && "Xn_wb and Xn do not match");
```
(need the `[[maybe_unused]]` to avoid `warning: unused variable 'Xd_wb'` from
the compiler)
https://github.com/llvm/llvm-project/pull/164913
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] DAG: exp opcodes cannotBeOrderedNegativeFP (PR #167604)
https://github.com/RKSimon approved this pull request. https://github.com/llvm/llvm-project/pull/167604 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [AMDGPU] Remove named-barrier LDS lowering logic from amdgpu-lower-module-lds (PR #166731)
skc7 wrote: This PR is closed and all commits here C-P'd to https://github.com/llvm/llvm-project/pull/165692 https://github.com/llvm/llvm-project/pull/166731 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT][PAC] Warn about synchronous unwind tables (PR #165227)
https://github.com/bgergely0 updated
https://github.com/llvm/llvm-project/pull/165227
From 9ec54b50e28f9688a5879f2bd15aad0e16d693aa Mon Sep 17 00:00:00 2001
From: Gergely Balint
Date: Mon, 27 Oct 2025 09:29:54 +
Subject: [PATCH 1/4] [BOLT][PAC] Warn about synchronous unwind tables
BOLT currently ignores functions with synchronous PAuth DWARF info.
When more than 10% of functions get ignored for inconsistencies, we
should emit a warning to only use asynchronous unwind tables.
See also: #165215
---
bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp| 9 -
.../AArch64/pacret-synchronous-unwind.cpp | 33 +++
2 files changed, 41 insertions(+), 1 deletion(-)
create mode 100644 bolt/test/runtime/AArch64/pacret-synchronous-unwind.cpp
diff --git a/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp
b/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp
index 91030544d2b88..01af88818a21d 100644
--- a/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp
+++ b/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp
@@ -133,11 +133,18 @@ Error
PointerAuthCFIAnalyzer::runOnFunctions(BinaryContext &BC) {
ParallelUtilities::runOnEachFunction(
BC, ParallelUtilities::SchedulingPolicy::SP_INST_LINEAR, WorkFun,
SkipPredicate, "PointerAuthCFIAnalyzer");
+
+ float IgnoredPercent = (100.0 * FunctionsIgnored) / Total;
BC.outs() << "BOLT-INFO: PointerAuthCFIAnalyzer ran on " << Total
<< " functions. Ignored " << FunctionsIgnored << " functions "
-<< format("(%.2lf%%)", (100.0 * FunctionsIgnored) / Total)
+<< format("(%.2lf%%)", IgnoredPercent)
<< " because of CFI inconsistencies\n";
+ if (IgnoredPercent >= 10.0)
+BC.outs() << "BOLT-WARNING: PointerAuthCFIAnalyzer only supports "
+ "asynchronous unwind tables. For C compilers, see "
+ "-fasynchronous-unwind-tables.\n";
+
return Error::success();
}
diff --git a/bolt/test/runtime/AArch64/pacret-synchronous-unwind.cpp
b/bolt/test/runtime/AArch64/pacret-synchronous-unwind.cpp
new file mode 100644
index 0..1bfeeaed3715a
--- /dev/null
+++ b/bolt/test/runtime/AArch64/pacret-synchronous-unwind.cpp
@@ -0,0 +1,33 @@
+// Test to demonstrate that functions compiled with synchronous unwind tables
+// are ignored by the PointerAuthCFIAnalyzer.
+// Exception handling is needed to have _any_ unwind tables, otherwise the
+// PointerAuthCFIAnalyzer does not run on these functions, so it does not
ignore
+// any function.
+//
+// REQUIRES: system-linux,bolt-runtime
+//
+// RUN: %clangxx --target=aarch64-unknown-linux-gnu \
+// RUN: -mbranch-protection=pac-ret \
+// RUN: -fno-asynchronous-unwind-tables \
+// RUN: %s -o %t.exe -Wl,-q
+// RUN: llvm-bolt %t.exe -o %t.bolt | FileCheck %s --check-prefix=CHECK
+//
+// CHECK: PointerAuthCFIAnalyzer ran on 3 functions. Ignored
+// CHECK-NOT: 0 functions (0.00%) because of CFI inconsistencies
+// CHECK-SAME: 1 functions (33.33%) because of CFI inconsistencies
+// CHECK-NEXT: BOLT-WARNING: PointerAuthCFIAnalyzer only supports asynchronous
+// CHECK-SAME: unwind tables. For C compilers, see
-fasynchronous-unwind-tables.
+
+#include
+#include
+
+void foo() { throw std::runtime_error("Exception from foo()."); }
+
+int main() {
+ try {
+foo();
+ } catch (const std::exception &e) {
+printf("Exception caught: %s\n", e.what());
+ }
+ return 0;
+}
From ec84bd994516eaae8fea24d3c0c2202a10cc7cee Mon Sep 17 00:00:00 2001
From: Gergely Balint
Date: Tue, 28 Oct 2025 09:23:08 +
Subject: [PATCH 2/4] [BOLT] Use opts::Verbosity in PointerAuthCFIAnalyzer
---
bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp| 27 ---
bolt/test/AArch64/negate-ra-state-incorrect.s | 2 +-
2 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp
b/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp
index 01af88818a21d..5979d5fb01818 100644
--- a/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp
+++ b/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp
@@ -28,6 +28,10 @@
using namespace llvm;
+namespace opts {
+extern llvm::cl::opt Verbosity;
+} // namespace opts
+
namespace llvm {
namespace bolt {
@@ -43,9 +47,10 @@ bool PointerAuthCFIAnalyzer::runOnFunction(BinaryFunction
&BF) {
// Not all functions have .cfi_negate_ra_state in them. But if one
does,
// we expect psign/pauth instructions to have the hasNegateRAState
// annotation.
-BC.outs() << "BOLT-INFO: inconsistent RAStates in function "
- << BF.getPrintName()
- << ": ptr sign/auth inst without .cfi_negate_ra_state\n";
+if (opts::Verbosity >= 1)
+ BC.outs() << "BOLT-INFO: inconsistent RAStates in function "
+<< BF.getPrintName()
+<< ": ptr sign/auth inst without .cfi_negate_ra_state\n";
std::lock_guard Lock(IgnoreMutex);
BF.setIgnored();
return false;
@@ -65,9 +70,10 @@ bool PointerAuthCFIAnalyzer::run
[llvm-branch-commits] [llvm] [BOLT][NFC] Rename Pointer Auth DWARF rewriter passes (PR #164622)
https://github.com/bgergely0 updated
https://github.com/llvm/llvm-project/pull/164622
From c9d81e94a7394ed1ceda79e27df67e03c5aaf3ec Mon Sep 17 00:00:00 2001
From: Gergely Balint
Date: Wed, 22 Oct 2025 12:44:37 +
Subject: [PATCH 1/3] [BOLT][NFC] Rename Pointer Auth DWARF rewriter passes
Original names were "working titles". After initial patches are merged,
I'd like to rename these passes to names that reflect their intent
better and show their relationship to each other:
InsertNegateRAStatePass renamed to PointerAuthCFIFixup,
MarkRAStates renamed to PointerAuthCFIAnalyzer.
---
bolt/docs/PacRetDesign.md | 23 ++---
...arkRAStates.h => PointerAuthCFIAnalyzer.h} | 14
...ateRAStatePass.h => PointerAuthCFIFixup.h} | 14
bolt/lib/Core/Exceptions.cpp | 8 ++---
bolt/lib/Passes/CMakeLists.txt| 4 +--
...AStates.cpp => PointerAuthCFIAnalyzer.cpp} | 16 +-
...AStatePass.cpp => PointerAuthCFIFixup.cpp} | 32 +--
bolt/lib/Rewrite/BinaryPassManager.cpp| 8 ++---
bolt/test/AArch64/negate-ra-state-incorrect.s | 2 +-
bolt/test/AArch64/negate-ra-state.s | 8 ++---
bolt/test/AArch64/pacret-split-funcs.s| 4 +--
bolt/unittests/Passes/CMakeLists.txt | 2 +-
...ateRAState.cpp => PointerAuthCFIFixup.cpp} | 6 ++--
.../gn/secondary/bolt/lib/Passes/BUILD.gn | 4 +--
14 files changed, 73 insertions(+), 72 deletions(-)
rename bolt/include/bolt/Passes/{MarkRAStates.h => PointerAuthCFIAnalyzer.h}
(63%)
rename bolt/include/bolt/Passes/{InsertNegateRAStatePass.h =>
PointerAuthCFIFixup.h} (87%)
rename bolt/lib/Passes/{MarkRAStates.cpp => PointerAuthCFIAnalyzer.cpp} (91%)
rename bolt/lib/Passes/{InsertNegateRAStatePass.cpp =>
PointerAuthCFIFixup.cpp} (91%)
rename bolt/unittests/Passes/{InsertNegateRAState.cpp =>
PointerAuthCFIFixup.cpp} (97%)
diff --git a/bolt/docs/PacRetDesign.md b/bolt/docs/PacRetDesign.md
index c7c76cac3a100..0de2da50f8fd6 100644
--- a/bolt/docs/PacRetDesign.md
+++ b/bolt/docs/PacRetDesign.md
@@ -104,9 +104,9 @@ negate-ra-state CFIs will become invalid during BasicBlock
reordering.
## Solution design
The implementation introduces two new passes:
-1. `MarkRAStatesPass`: assigns the RA state to each instruction based on the
CFIs
-in the input binary
-2. `InsertNegateRAStatePass`: reads those assigned instruction RA states after
+1. `PointerAuthCFIAnalyzer`: assigns the RA state to each instruction based on
+the CFI in the input binary
+2. `PointerAuthCFIFixup`: reads those assigned instruction RA states after
optimizations, and emits `DW_CFA_AARCH64_negate_ra_state` CFIs at the
correct
places: wherever there is a state change between two consecutive
instructions
in the layout order.
@@ -129,7 +129,7 @@ instruction.
This special case is handled by adding an `initialRAState` bool to each
BinaryFunction.
If the `Offset` the CFI refers to is zero, we don't store an annotation, but
set
the `initialRAState` in `FillCFIInfoFor`. This information is then used in
-`MarkRAStates`.
+`PointerAuthCFIAnalyzer`.
### Binaries without DWARF info
@@ -146,7 +146,7 @@ In summary:
- pointer auth is used, and we have DWARF CFIs: passes run, and rewrite the
negate-ra-state CFI.
-### MarkRAStates pass
+### PointerAuthCFIAnalyzer pass
This pass runs before optimizations reorder anything.
@@ -173,9 +173,9 @@ what we have before the pass, and after it.
| autiasp | negate-ra-state | signed |
| ret | | unsigned |
-# Error handling in MarkRAState Pass:
+# Error handling in PointerAuthCFIAnalyzer pass:
-Whenever the MarkRAStates pass finds inconsistencies in the current
+Whenever the PointerAuthCFIAnalyzer pass finds inconsistencies in the current
BinaryFunction, it marks the function as ignored using `BF.setIgnored()`. BOLT
will not optimize this function but will emit it unchanged in the original
section
(`.bolt.org.text`).
@@ -188,16 +188,17 @@ The inconsistencies are as follows:
Users will be informed about the number of ignored functions in the pass, the
exact functions ignored, and the found inconsistency.
-### InsertNegateRAStatePass
+### PointerAuthCFIFixup
-This pass runs after optimizations. It performns the _inverse_ of MarkRAState
pa s:
+This pass runs after optimizations. It performns the _inverse_ of
PointerAuthCFIAnalyzer
+pass:
1. it reads the RA state annotations attached to the instructions, and
2. whenever the state changes, it adds a PseudoInstruction that holds an
OpNegateRAState CFI.
# Covering newly generated instructions:
-Some BOLT passes can add new Instructions. In InsertNegateRAStatePass, we have
+Some BOLT passes can add new Instructions. In PointerAuthCFIFixup, we have
to know what RA state these have.
> [!important]
@@ -230,7 +231,7 @@ freely. The only special case is function splitting. W
[llvm-branch-commits] [llvm] [BOLT][NFC] Rename Pointer Auth DWARF rewriter passes (PR #164622)
https://github.com/bgergely0 updated
https://github.com/llvm/llvm-project/pull/164622
Unicorn! · GitHub
body {
background-color: #f1f1f1;
margin: 0;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.container { margin: 50px auto 40px auto; width: 600px; text-align:
center; }
a { color: #4183c4; text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { letter-spacing: -1px; line-height: 60px; font-size: 60px;
font-weight: 100; margin: 0px; text-shadow: 0 1px 0 #fff; }
p { color: rgba(0, 0, 0, 0.5); margin: 10px 0 10px; font-size: 18px;
font-weight: 200; line-height: 1.6em;}
ul { list-style: none; margin: 25px 0; padding: 0; }
li { display: table-cell; font-weight: bold; width: 1%; }
.logo { display: inline-block; margin-top: 35px; }
.logo-img-2x { display: none; }
@media
only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and ( min--moz-device-pixel-ratio: 2),
only screen and ( -o-min-device-pixel-ratio: 2/1),
only screen and (min-device-pixel-ratio: 2),
only screen and (min-resolution: 192dpi),
only screen and (min-resolution: 2dppx) {
.logo-img-1x { display: none; }
.logo-img-2x { display: inline-block; }
}
#suggestions {
margin-top: 35px;
color: #ccc;
}
#suggestions a {
color: #66;
font-weight: 200;
font-size: 14px;
margin: 0 10px;
}
No server is currently available to service your
request.
Sorry about that. Please try refreshing and contact us if the problem
persists.
https://github.com/contact";>Contact Support —
https://www.githubstatus.com";>GitHub Status —
https://twitter.com/githubstatus";>@githubstatus
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT][PAC] Warn about synchronous unwind tables (PR #165227)
https://github.com/bgergely0 updated
https://github.com/llvm/llvm-project/pull/165227
From 9ec54b50e28f9688a5879f2bd15aad0e16d693aa Mon Sep 17 00:00:00 2001
From: Gergely Balint
Date: Mon, 27 Oct 2025 09:29:54 +
Subject: [PATCH 1/4] [BOLT][PAC] Warn about synchronous unwind tables
BOLT currently ignores functions with synchronous PAuth DWARF info.
When more than 10% of functions get ignored for inconsistencies, we
should emit a warning to only use asynchronous unwind tables.
See also: #165215
---
bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp| 9 -
.../AArch64/pacret-synchronous-unwind.cpp | 33 +++
2 files changed, 41 insertions(+), 1 deletion(-)
create mode 100644 bolt/test/runtime/AArch64/pacret-synchronous-unwind.cpp
diff --git a/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp
b/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp
index 91030544d2b88..01af88818a21d 100644
--- a/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp
+++ b/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp
@@ -133,11 +133,18 @@ Error
PointerAuthCFIAnalyzer::runOnFunctions(BinaryContext &BC) {
ParallelUtilities::runOnEachFunction(
BC, ParallelUtilities::SchedulingPolicy::SP_INST_LINEAR, WorkFun,
SkipPredicate, "PointerAuthCFIAnalyzer");
+
+ float IgnoredPercent = (100.0 * FunctionsIgnored) / Total;
BC.outs() << "BOLT-INFO: PointerAuthCFIAnalyzer ran on " << Total
<< " functions. Ignored " << FunctionsIgnored << " functions "
-<< format("(%.2lf%%)", (100.0 * FunctionsIgnored) / Total)
+<< format("(%.2lf%%)", IgnoredPercent)
<< " because of CFI inconsistencies\n";
+ if (IgnoredPercent >= 10.0)
+BC.outs() << "BOLT-WARNING: PointerAuthCFIAnalyzer only supports "
+ "asynchronous unwind tables. For C compilers, see "
+ "-fasynchronous-unwind-tables.\n";
+
return Error::success();
}
diff --git a/bolt/test/runtime/AArch64/pacret-synchronous-unwind.cpp
b/bolt/test/runtime/AArch64/pacret-synchronous-unwind.cpp
new file mode 100644
index 0..1bfeeaed3715a
--- /dev/null
+++ b/bolt/test/runtime/AArch64/pacret-synchronous-unwind.cpp
@@ -0,0 +1,33 @@
+// Test to demonstrate that functions compiled with synchronous unwind tables
+// are ignored by the PointerAuthCFIAnalyzer.
+// Exception handling is needed to have _any_ unwind tables, otherwise the
+// PointerAuthCFIAnalyzer does not run on these functions, so it does not
ignore
+// any function.
+//
+// REQUIRES: system-linux,bolt-runtime
+//
+// RUN: %clangxx --target=aarch64-unknown-linux-gnu \
+// RUN: -mbranch-protection=pac-ret \
+// RUN: -fno-asynchronous-unwind-tables \
+// RUN: %s -o %t.exe -Wl,-q
+// RUN: llvm-bolt %t.exe -o %t.bolt | FileCheck %s --check-prefix=CHECK
+//
+// CHECK: PointerAuthCFIAnalyzer ran on 3 functions. Ignored
+// CHECK-NOT: 0 functions (0.00%) because of CFI inconsistencies
+// CHECK-SAME: 1 functions (33.33%) because of CFI inconsistencies
+// CHECK-NEXT: BOLT-WARNING: PointerAuthCFIAnalyzer only supports asynchronous
+// CHECK-SAME: unwind tables. For C compilers, see
-fasynchronous-unwind-tables.
+
+#include
+#include
+
+void foo() { throw std::runtime_error("Exception from foo()."); }
+
+int main() {
+ try {
+foo();
+ } catch (const std::exception &e) {
+printf("Exception caught: %s\n", e.what());
+ }
+ return 0;
+}
From ec84bd994516eaae8fea24d3c0c2202a10cc7cee Mon Sep 17 00:00:00 2001
From: Gergely Balint
Date: Tue, 28 Oct 2025 09:23:08 +
Subject: [PATCH 2/4] [BOLT] Use opts::Verbosity in PointerAuthCFIAnalyzer
---
bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp| 27 ---
bolt/test/AArch64/negate-ra-state-incorrect.s | 2 +-
2 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp
b/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp
index 01af88818a21d..5979d5fb01818 100644
--- a/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp
+++ b/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp
@@ -28,6 +28,10 @@
using namespace llvm;
+namespace opts {
+extern llvm::cl::opt Verbosity;
+} // namespace opts
+
namespace llvm {
namespace bolt {
@@ -43,9 +47,10 @@ bool PointerAuthCFIAnalyzer::runOnFunction(BinaryFunction
&BF) {
// Not all functions have .cfi_negate_ra_state in them. But if one
does,
// we expect psign/pauth instructions to have the hasNegateRAState
// annotation.
-BC.outs() << "BOLT-INFO: inconsistent RAStates in function "
- << BF.getPrintName()
- << ": ptr sign/auth inst without .cfi_negate_ra_state\n";
+if (opts::Verbosity >= 1)
+ BC.outs() << "BOLT-INFO: inconsistent RAStates in function "
+<< BF.getPrintName()
+<< ": ptr sign/auth inst without .cfi_negate_ra_state\n";
std::lock_guard Lock(IgnoreMutex);
BF.setIgnored();
return false;
@@ -65,9 +70,10 @@ bool PointerAuthCFIAnalyzer::run
[llvm-branch-commits] [clang] [llvm] [AArch64][llvm] Add instructions for FEAT_MOPS_GO (PR #164913)
https://github.com/CarolineConcatto edited https://github.com/llvm/llvm-project/pull/164913 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [DAGCombiner] Relax nsz constraint for more FP optimizations (PR #165011)
https://github.com/guy-david edited https://github.com/llvm/llvm-project/pull/165011 ___ 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: [LoongArch] Add `isSafeToMove` hook to prevent unsafe instruction motion (#163725) (PR #166936)
https://github.com/dyung updated
https://github.com/llvm/llvm-project/pull/166936
>From a973c36b5aa87d13b540531f4053d05bd5275dd8 Mon Sep 17 00:00:00 2001
From: hev
Date: Wed, 12 Nov 2025 08:51:08 +0800
Subject: [PATCH] Reland "[LoongArch] Add `isSafeToMove` hook to prevent unsafe
instruction motion" (#167465)
This patch introduces a new virtual method
`TargetInstrInfo::isSafeToMove()` to allow backends to control whether a
machine instruction can be safely moved by optimization passes.
The `BranchFolder` pass now respects this hook when hoisting common
code. By default, all instructions are considered safe to to move.
For LoongArch, `isSafeToMove()` is overridden to prevent
relocation-related instruction sequences (e.g. PC-relative addressing
and calls) from being broken by instruction motion. Correspondingly,
`isSchedulingBoundary()` is updated to reuse this logic for consistency.
Relands #163725
(cherry picked from commit ea10026b64f66b3b69c0545db20f9daa8579f5cb)
---
llvm/include/llvm/CodeGen/TargetInstrInfo.h | 11
llvm/lib/CodeGen/BranchFolding.cpp| 5 ++
.../Target/LoongArch/LoongArchInstrInfo.cpp | 45 +--
.../lib/Target/LoongArch/LoongArchInstrInfo.h | 3 +
llvm/test/CodeGen/LoongArch/issue163681.ll| 56 +++
5 files changed, 102 insertions(+), 18 deletions(-)
create mode 100644 llvm/test/CodeGen/LoongArch/issue163681.ll
diff --git a/llvm/include/llvm/CodeGen/TargetInstrInfo.h
b/llvm/include/llvm/CodeGen/TargetInstrInfo.h
index b5b83c7ff1164..4d6e34bf4e3a1 100644
--- a/llvm/include/llvm/CodeGen/TargetInstrInfo.h
+++ b/llvm/include/llvm/CodeGen/TargetInstrInfo.h
@@ -1730,6 +1730,17 @@ class LLVM_ABI TargetInstrInfo : public MCInstrInfo {
return true;
}
+ /// Return true if it's safe to move a machine instruction.
+ /// This allows the backend to prevent certain special instruction
+ /// sequences from being broken by instruction motion in optimization
+ /// passes.
+ /// By default, this returns true for every instruction.
+ virtual bool isSafeToMove(const MachineInstr &MI,
+const MachineBasicBlock *MBB,
+const MachineFunction &MF) const {
+return true;
+ }
+
/// Test if the given instruction should be considered a scheduling boundary.
/// This primarily includes labels and terminators.
virtual bool isSchedulingBoundary(const MachineInstr &MI,
diff --git a/llvm/lib/CodeGen/BranchFolding.cpp
b/llvm/lib/CodeGen/BranchFolding.cpp
index 3b3e7a418feb5..f32a18833d162 100644
--- a/llvm/lib/CodeGen/BranchFolding.cpp
+++ b/llvm/lib/CodeGen/BranchFolding.cpp
@@ -1971,6 +1971,7 @@ bool
BranchFolder::HoistCommonCodeInSuccs(MachineBasicBlock *MBB) {
MachineBasicBlock::iterator FIB = FBB->begin();
MachineBasicBlock::iterator TIE = TBB->end();
MachineBasicBlock::iterator FIE = FBB->end();
+ MachineFunction &MF = *TBB->getParent();
while (TIB != TIE && FIB != FIE) {
// Skip dbg_value instructions. These do not count.
TIB = skipDebugInstructionsForward(TIB, TIE, false);
@@ -1985,6 +1986,10 @@ bool
BranchFolder::HoistCommonCodeInSuccs(MachineBasicBlock *MBB) {
// Hard to reason about register liveness with predicated instruction.
break;
+if (!TII->isSafeToMove(*TIB, TBB, MF))
+ // Don't hoist the instruction if it isn't safe to move.
+ break;
+
bool IsSafe = true;
for (MachineOperand &MO : TIB->operands()) {
// Don't attempt to hoist instructions with register masks.
diff --git a/llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
b/llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
index 26d36f1c5058f..75a230268bf58 100644
--- a/llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
@@ -378,12 +378,9 @@ bool LoongArchInstrInfo::isBranchOffsetInRange(unsigned
BranchOp,
}
}
-bool LoongArchInstrInfo::isSchedulingBoundary(const MachineInstr &MI,
- const MachineBasicBlock *MBB,
- const MachineFunction &MF) const
{
- if (TargetInstrInfo::isSchedulingBoundary(MI, MBB, MF))
-return true;
-
+bool LoongArchInstrInfo::isSafeToMove(const MachineInstr &MI,
+ const MachineBasicBlock *MBB,
+ const MachineFunction &MF) const {
auto MII = MI.getIterator();
auto MIE = MBB->end();
@@ -429,25 +426,25 @@ bool LoongArchInstrInfo::isSchedulingBoundary(const
MachineInstr &MI,
auto MO2 = Lu32I->getOperand(2).getTargetFlags();
if (MO0 == LoongArchII::MO_PCREL_HI && MO1 == LoongArchII::MO_PCREL_LO &&
MO2 == LoongArchII::MO_PCREL64_LO)
- return true;
+ return false;
if ((MO0 == LoongArchII::MO_GOT_PC_HI || MO0 == LoongArchII::MO_LD_PC_HI ||
MO0 == LoongArchII::MO_GD_PC_HI) &&
MO1 == LoongArchII::MO_GOT_PC_LO && MO2 == LoongArchII::MO_GOT_PC64_
[llvm-branch-commits] [clang] release/21.x: [CMake][Release] Stop linking against stage1 runtimes (#164017) (PR #167653)
llvmbot wrote:
@llvm/pr-subscribers-clang
Author: None (llvmbot)
Changes
Backport 1906c3e1e30759d2eb85b2833e8c5ff64128bfba
Requested by: @tstellar
---
Full diff: https://github.com/llvm/llvm-project/pull/167653.diff
1 Files Affected:
- (modified) clang/cmake/caches/Release.cmake (+30-9)
``diff
diff --git a/clang/cmake/caches/Release.cmake b/clang/cmake/caches/Release.cmake
index fb12dfcdcb5a5..9f7e906241106 100644
--- a/clang/cmake/caches/Release.cmake
+++ b/clang/cmake/caches/Release.cmake
@@ -44,6 +44,19 @@ set(LLVM_RELEASE_ENABLE_LTO THIN CACHE STRING "")
set(LLVM_RELEASE_ENABLE_PGO ON CACHE BOOL "")
set(LLVM_RELEASE_ENABLE_RUNTIMES ${DEFAULT_RUNTIMES} CACHE STRING "")
set(LLVM_RELEASE_ENABLE_PROJECTS ${DEFAULT_PROJECTS} CACHE STRING "")
+
+# This option enables linking stage2 clang statically with the runtimes
+# (libc++ and compiler-rt) from stage1. In theory this will give the
+# binaries better performance and make them more portable. However,
+# this configuration is not well tested and causes build failures with
+# the flang-rt tests cases, since the -stclib=libc++ flag does not
+# get propagated to the runtimes build. There is also a separate
+# issue on Darwin where clang will use the local libc++ headers, but
+# link with system libc++ which can cause some incompatibilities.
+# See https://github.com/llvm/llvm-project/issues/77653
+# Because of these problems, this option will default to OFF.
+set(LLVM_RELEASE_ENABLE_LINK_LOCAL_RUNTIMES OFF CACHE BOOL "")
+
# Note we don't need to add install here, since it is one of the pre-defined
# steps.
set(LLVM_RELEASE_FINAL_STAGE_TARGETS
"clang;package;check-all;check-llvm;check-clang" CACHE STRING "")
@@ -55,8 +68,12 @@ set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
set(STAGE1_PROJECTS "clang")
+# Need to build compiler-rt in order to use PGO for later stages.
+set(STAGE1_RUNTIMES "compiler-rt")
# Build all runtimes so we can statically link them into the stage2 compiler.
-set(STAGE1_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind")
+if(LLVM_RELEASE_ENABLE_LINK_LOCAL_RUNTIMES)
+ list(APPEND STAGE1_RUNTIMES "libcxx;libcxxabi;libunwind")
+endif()
if (LLVM_RELEASE_ENABLE_PGO)
list(APPEND STAGE1_PROJECTS "lld")
@@ -118,11 +135,13 @@ set_instrument_and_final_stage_var(LLVM_ENABLE_LTO
"${LLVM_RELEASE_ENABLE_LTO}"
if (LLVM_RELEASE_ENABLE_LTO)
set_instrument_and_final_stage_var(LLVM_ENABLE_LLD "ON" BOOL)
endif()
-set_instrument_and_final_stage_var(LLVM_ENABLE_LIBCXX "ON" BOOL)
-set_instrument_and_final_stage_var(LLVM_STATIC_LINK_CXX_STDLIB "ON" BOOL)
-set(RELEASE_LINKER_FLAGS "-rtlib=compiler-rt --unwindlib=libunwind")
-if(NOT ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
- set(RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -static-libgcc")
+if(LLVM_RELEASE_ENABLE_LINK_LOCAL_RUNTIMES)
+ set_instrument_and_final_stage_var(LLVM_ENABLE_LIBCXX "ON" BOOL)
+ set_instrument_and_final_stage_var(LLVM_STATIC_LINK_CXX_STDLIB "ON" BOOL)
+ set(RELEASE_LINKER_FLAGS "-rtlib=compiler-rt --unwindlib=libunwind")
+ if(NOT ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
+set(RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -static-libgcc")
+ endif()
endif()
# Set flags for bolt
@@ -130,9 +149,11 @@ if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
set(RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -Wl,--emit-relocs,-znow")
endif()
-set_instrument_and_final_stage_var(CMAKE_EXE_LINKER_FLAGS
${RELEASE_LINKER_FLAGS} STRING)
-set_instrument_and_final_stage_var(CMAKE_SHARED_LINKER_FLAGS
${RELEASE_LINKER_FLAGS} STRING)
-set_instrument_and_final_stage_var(CMAKE_MODULE_LINKER_FLAGS
${RELEASE_LINKER_FLAGS} STRING)
+if (RELEASE_LINKER_FLAGS)
+ set_instrument_and_final_stage_var(CMAKE_EXE_LINKER_FLAGS
${RELEASE_LINKER_FLAGS} STRING)
+ set_instrument_and_final_stage_var(CMAKE_SHARED_LINKER_FLAGS
${RELEASE_LINKER_FLAGS} STRING)
+ set_instrument_and_final_stage_var(CMAKE_MODULE_LINKER_FLAGS
${RELEASE_LINKER_FLAGS} STRING)
+endif()
# Final Stage Config (stage2)
set_final_stage_var(LLVM_ENABLE_RUNTIMES "${LLVM_RELEASE_ENABLE_RUNTIMES}"
STRING)
``
https://github.com/llvm/llvm-project/pull/167653
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [DAGCombiner] Relax nsz constraint for more FP optimizations (PR #165011)
https://github.com/guy-david edited https://github.com/llvm/llvm-project/pull/165011 ___ 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: [MachineCopyPropagation] Remove logic to recognise and delete no-op moves produced after forwarded uses (#167336) (PR #167526)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/167526 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
