[llvm] [clang] [AArch64] Disable large global group relocation (PR #75445)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 14 00:58:18 PST 2023
https://github.com/wc00862805aj created https://github.com/llvm/llvm-project/pull/75445
None
>From b1109d297690b3b162eab21dfc41ce03a898a908 Mon Sep 17 00:00:00 2001
From: wcleungaj <leung.wing.chung at huawei.com>
Date: Thu, 14 Dec 2023 16:54:37 +0800
Subject: [PATCH] [AArch64] Disable large global group relocation
---
clang/include/clang/Driver/Options.td | 3 +++
clang/lib/Driver/ToolChains/Clang.cpp | 5 +++++
.../AArch64/GISel/AArch64InstructionSelector.cpp | 5 +++++
.../AArch64/GlobalISel/select-blockaddress.mir | 11 +++++++++++
4 files changed, 24 insertions(+)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 1b02087425b751..827e14a071f436 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4663,6 +4663,9 @@ def mno_fix_cortex_a53_835769 : Flag<["-"], "mno-fix-cortex-a53-835769">,
def mmark_bti_property : Flag<["-"], "mmark-bti-property">,
Group<m_aarch64_Features_Group>,
HelpText<"Add .note.gnu.property with BTI to assembly files (AArch64 only)">;
+def mno_large_group_reloc: Flag<["-"], "mno-large-global-group-reloc">,
+ Group<m_aarch64_Features_Group>,
+ HelpText<"Disable group relocation type for global value and symbol when code model is large">;
def mno_bti_at_return_twice : Flag<["-"], "mno-bti-at-return-twice">,
Group<m_arm_Features_Group>,
HelpText<"Do not add a BTI instruction after a setjmp or other"
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index de9fd5eaa1e020..8edfe00358a066 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4977,6 +4977,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (Args.getLastArg(options::OPT_save_temps_EQ))
Args.AddLastArg(CmdArgs, options::OPT_save_temps_EQ);
+ if (Args.getLastArg(options::OPT_mno_large_global_group_reloc)){
+ CmdArgs.push_back("-mllvm");
+ CmdArgs.push_back("-mno-large-global-group-reloc");
+ }
+
auto *MemProfArg = Args.getLastArg(options::OPT_fmemory_profile,
options::OPT_fmemory_profile_EQ,
options::OPT_fno_memory_profile);
diff --git a/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp b/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
index bdaae4dd724d53..95669104739db4 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
@@ -66,6 +66,10 @@ namespace {
#include "AArch64GenGlobalISel.inc"
#undef GET_GLOBALISEL_PREDICATE_BITSET
+static cl::opt<bool> DisableLargeGlobalGroupReloc(
+ "mno-large-global-group-reloc",
+ cl::desc("Disable group relocation type for global value and symbol when code model is large"),
+ cl::init(false));
class AArch64InstructionSelector : public InstructionSelector {
public:
@@ -2850,6 +2854,7 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {
I.setDesc(TII.get(AArch64::LOADgot));
I.getOperand(1).setTargetFlags(OpFlags);
} else if (TM.getCodeModel() == CodeModel::Large &&
+ !DisableLargeGlobalGroupReloc &&
!TM.isPositionIndependent()) {
// Materialize the global using movz/movk instructions.
materializeLargeCMVal(I, GV, OpFlags);
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/select-blockaddress.mir b/llvm/test/CodeGen/AArch64/GlobalISel/select-blockaddress.mir
index 28d279d7421642..dadde2d8f33426 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/select-blockaddress.mir
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/select-blockaddress.mir
@@ -2,6 +2,7 @@
# RUN: llc -mtriple=aarch64-unknown-unknown -o - -verify-machineinstrs -run-pass=instruction-select %s | FileCheck %s
# RUN: llc -mtriple=aarch64-unknown-unknown -o - -verify-machineinstrs -run-pass=instruction-select -code-model=large %s | FileCheck %s --check-prefix=LARGE
# RUN: llc -mtriple=aarch64-unknown-unknown -o - -verify-machineinstrs -run-pass=instruction-select -code-model=large -relocation-model=pic %s | FileCheck %s --check-prefix=LARGE-PIC
+# RUN: llc -mtriple=aarch64-unknown-unknown -o - -verify-machineinstrs -run-pass=instruction-select -code-model=large -mno-large-global-group-reloc %s | FileCheck %s --check-prefix=NO-LARGE-GLOBAL-GROUP-RELOC
--- |
source_filename = "blockaddress.ll"
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
@@ -62,6 +63,16 @@ body: |
; LARGE-PIC-NEXT: BR [[MOVaddrBA]]
; LARGE-PIC-NEXT: {{ $}}
; LARGE-PIC-NEXT: bb.1.block (ir-block-address-taken %ir-block.block):
+ ; NO-LARGE-GLOBAL-GROUP-RELOC-LABEL: name: test_blockaddress
+ ; NO-LARGE-GLOBAL-GROUP-RELOC: bb.0 (%ir-block.0):
+ ; NO-LARGE-GLOBAL-GROUP-RELOC: [[MOVZXi:%[0-9]+]]:gpr64 = MOVZXi target-flags(aarch64-g0, aarch64-nc) blockaddress(@test_blockaddress, %ir-block.block), 0
+ ; NO-LARGE-GLOBAL-GROUP-RELOC: [[MOVKXi:%[0-9]+]]:gpr64 = MOVKXi [[MOVZXi]], target-flags(aarch64-g1, aarch64-nc) blockaddress(@test_blockaddress, %ir-block.block), 16
+ ; NO-LARGE-GLOBAL-GROUP-RELOC: [[MOVKXi1:%[0-9]+]]:gpr64 = MOVKXi [[MOVKXi]], target-flags(aarch64-g2, aarch64-nc) blockaddress(@test_blockaddress, %ir-block.block), 32
+ ; NO-LARGE-GLOBAL-GROUP-RELOC: [[MOVKXi2:%[0-9]+]]:gpr64 = MOVKXi [[MOVKXi1]], target-flags(aarch64-g3) blockaddress(@test_blockaddress, %ir-block.block), 48
+ ; NO-LARGE-GLOBAL-GROUP-RELOC: [[MOVaddr:%[0-9]+]]:gpr64common = MOVaddr target-flags(aarch64-page) @addr, target-flags(aarch64-pageoff, aarch64-nc) @addr
+ ; NO-LARGE-GLOBAL-GROUP-RELOC: STRXui [[MOVKXi2]], [[MOVaddr]], 0 :: (store (p0) into @addr)
+ ; NO-LARGE-GLOBAL-GROUP-RELOC: BR [[MOVKXi2]]
+ ; NO-LARGE-GLOBAL-GROUP-RELOC: bb.1.block (address-taken):
bb.1 (%ir-block.0):
%0:gpr(p0) = G_BLOCK_ADDR blockaddress(@test_blockaddress, %ir-block.block)
%1:gpr(p0) = G_GLOBAL_VALUE @addr
More information about the cfe-commits
mailing list