[llvm-branch-commits] [lld] [lld][LoongArch] Support relaxation during IE to LE conversion (PR #123702)
https://github.com/MaskRay approved this pull request. https://github.com/llvm/llvm-project/pull/123702 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld] [lld][LoongArch] Support relaxation during IE to LE conversion (PR #123702)
SixWeining wrote: cc @xen0n https://github.com/llvm/llvm-project/pull/123702 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld] [lld][LoongArch] Support relaxation during IE to LE conversion (PR #123702)
https://github.com/ylzsx edited https://github.com/llvm/llvm-project/pull/123702 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld] [lld][LoongArch] Support relaxation during IE to LE conversion. (PR #123702)
llvmbot wrote: @llvm/pr-subscribers-lld Author: Zhaoxin Yang (ylzsx) Changes Complement https://github.com/llvm/llvm-project/pull/123680. When relaxation enable, remove redundant NOPs. --- Full diff: https://github.com/llvm/llvm-project/pull/123702.diff 2 Files Affected: - (modified) lld/ELF/Arch/LoongArch.cpp (+11-2) - (modified) lld/test/ELF/loongarch-relax-tls-ie.s (+26-4) ``diff diff --git a/lld/ELF/Arch/LoongArch.cpp b/lld/ELF/Arch/LoongArch.cpp index dc98dbec872c0c..ef25e741901d93 100644 --- a/lld/ELF/Arch/LoongArch.cpp +++ b/lld/ELF/Arch/LoongArch.cpp @@ -975,6 +975,11 @@ static bool relax(Ctx &ctx, InputSection &sec) { if (relaxable(relocs, i)) relaxTlsLe(ctx, sec, i, loc, r, remove); break; +case R_LARCH_TLS_IE_PC_HI20: + if (relaxable(relocs, i) && r.expr == R_RELAX_TLS_IE_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 @@ -1049,7 +1054,7 @@ void LoongArch::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const { secAddr += s->outSecOff; else if (auto *ehIn = dyn_cast(&sec)) secAddr += ehIn->getParent()->outSecOff; - bool isExtreme = false; + bool isExtreme = false, isRelax = false; const MutableArrayRef relocs = sec.relocs(); for (size_t i = 0, size = relocs.size(); i != size; ++i) { Relocation &rel = relocs[i]; @@ -1077,8 +1082,12 @@ void LoongArch::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const { val = SignExtend64(sec.getRelocTargetVA(ctx, rel, secAddr + rel.offset), bits); relocateNoSym(loc, rel.type, val); - } else + } else { +isRelax = relaxable(relocs, i); +if (isRelax && rel.type == R_LARCH_TLS_IE_PC_HI20 && isUInt<12>(val)) + continue; tlsIeToLe(loc, rel, val); + } continue; default: break; diff --git a/lld/test/ELF/loongarch-relax-tls-ie.s b/lld/test/ELF/loongarch-relax-tls-ie.s index f5375ae3a3b400..2c95a342251f20 100644 --- a/lld/test/ELF/loongarch-relax-tls-ie.s +++ b/lld/test/ELF/loongarch-relax-tls-ie.s @@ -3,11 +3,10 @@ # RUN: llvm-mc --filetype=obj --triple=loongarch64 -mattr=+relax %s -o %t.o -## FIXME: IE relaxation has not yet been implemented. -## --relax/--no-relax has the same result. Also check --emit-relocs. -# RUN: ld.lld --emit-relocs %t.o -o %t +## Also check --emit-relocs. +# RUN: ld.lld --emit-relocs --relax %t.o -o %t # RUN: llvm-readelf -x .got %t 2>&1 | FileCheck --check-prefix=LE-GOT %s -# RUN: llvm-objdump -dr --no-show-raw-insn %t | FileCheck --check-prefixes=LE %s +# RUN: llvm-objdump -dr --no-show-raw-insn %t | FileCheck --check-prefixes=LER %s # RUN: ld.lld --emit-relocs --no-relax %t.o -o %t.norelax # RUN: llvm-readelf -x .got %t.norelax 2>&1 | FileCheck --check-prefix=LE-GOT %s @@ -42,6 +41,29 @@ # LE-NEXT:add.d $a2, $a2, $tp # LE-NEXT:add.d $a3, $a3, $tp +# LER: 20158: ori $a0, $zero, 4095 +# LER-NEXT: R_LARCH_TLS_IE_PC_HI20 a +# LER-NEXT: R_LARCH_RELAX *ABS* +# LER-NEXT: R_LARCH_TLS_IE_PC_LO12 a +# LER-NEXT: R_LARCH_RELAX *ABS* +# LER-NEXT:add.d $a0, $a0, $tp +# LER-NEXT: 20160: lu12i.w $a1, 1 +# LER-NEXT: R_LARCH_TLS_IE_PC_HI20 b +# LER-NEXT:ori $a1, $a1, 0 +# LER-NEXT: R_LARCH_TLS_IE_PC_LO12 b +# LER-NEXT:add.d $a1, $a1, $tp +# LER-NEXT: 2016c: lu12i.w $a3, 1 +# LER-NEXT: R_LARCH_TLS_IE_PC_HI20 a +# LER-NEXT: R_LARCH_RELAX *ABS* +# LER-NEXT: R_LARCH_TLS_IE_PC_HI20 b +# LER-NEXT: R_LARCH_RELAX *ABS* +# LER-NEXT:ori $a2, $zero, 4095 +# LER-NEXT: R_LARCH_TLS_IE_PC_LO12 a +# LER-NEXT:ori $a3, $a3, 0 +# LER-NEXT: R_LARCH_TLS_IE_PC_LO12 b +# LER-NEXT:add.d $a2, $a2, $tp +# LER-NEXT:add.d $a3, $a3, $tp + la.tls.ie $a0, a# relax add.d $a0, $a0, $tp `` https://github.com/llvm/llvm-project/pull/123702 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld] [lld][LoongArch] Support relaxation during IE to LE conversion. (PR #123702)
https://github.com/ylzsx created https://github.com/llvm/llvm-project/pull/123702 Complement https://github.com/llvm/llvm-project/pull/123680. When relaxation enable, remove redundant NOPs. >From 83d8b7e00b16c97b11f3c19ed45bb70eeae95428 Mon Sep 17 00:00:00 2001 From: yangzhaoxin Date: Fri, 3 Jan 2025 11:15:56 +0800 Subject: [PATCH 1/3] Support relaxation during IE to LE conversion. Complement https://. When relaxation enable, remove redundant NOPs. --- lld/ELF/Arch/LoongArch.cpp | 13 +++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lld/ELF/Arch/LoongArch.cpp b/lld/ELF/Arch/LoongArch.cpp index dc98dbec872c0c..ef25e741901d93 100644 --- a/lld/ELF/Arch/LoongArch.cpp +++ b/lld/ELF/Arch/LoongArch.cpp @@ -975,6 +975,11 @@ static bool relax(Ctx &ctx, InputSection &sec) { if (relaxable(relocs, i)) relaxTlsLe(ctx, sec, i, loc, r, remove); break; +case R_LARCH_TLS_IE_PC_HI20: + if (relaxable(relocs, i) && r.expr == R_RELAX_TLS_IE_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 @@ -1049,7 +1054,7 @@ void LoongArch::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const { secAddr += s->outSecOff; else if (auto *ehIn = dyn_cast(&sec)) secAddr += ehIn->getParent()->outSecOff; - bool isExtreme = false; + bool isExtreme = false, isRelax = false; const MutableArrayRef relocs = sec.relocs(); for (size_t i = 0, size = relocs.size(); i != size; ++i) { Relocation &rel = relocs[i]; @@ -1077,8 +1082,12 @@ void LoongArch::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const { val = SignExtend64(sec.getRelocTargetVA(ctx, rel, secAddr + rel.offset), bits); relocateNoSym(loc, rel.type, val); - } else + } else { +isRelax = relaxable(relocs, i); +if (isRelax && rel.type == R_LARCH_TLS_IE_PC_HI20 && isUInt<12>(val)) + continue; tlsIeToLe(loc, rel, val); + } continue; default: break; >From 6b79432dcb9172906deab445055d8197fdeed425 Mon Sep 17 00:00:00 2001 From: yangzhaoxin Date: Fri, 3 Jan 2025 11:20:10 +0800 Subject: [PATCH 2/3] Modify loongarch-relax-tls-ie.s when relaxation is enabled. --- lld/test/ELF/loongarch-relax-tls-ie.s | 28 --- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/lld/test/ELF/loongarch-relax-tls-ie.s b/lld/test/ELF/loongarch-relax-tls-ie.s index f5375ae3a3b400..be76263f2978e0 100644 --- a/lld/test/ELF/loongarch-relax-tls-ie.s +++ b/lld/test/ELF/loongarch-relax-tls-ie.s @@ -3,11 +3,10 @@ # RUN: llvm-mc --filetype=obj --triple=loongarch64 -mattr=+relax %s -o %t.o -## FIXME: IE relaxation has not yet been implemented. -## --relax/--no-relax has the same result. Also check --emit-relocs. +## Also check --emit-relocs. # RUN: ld.lld --emit-relocs %t.o -o %t # RUN: llvm-readelf -x .got %t 2>&1 | FileCheck --check-prefix=LE-GOT %s -# RUN: llvm-objdump -dr --no-show-raw-insn %t | FileCheck --check-prefixes=LE %s +# RUN: llvm-objdump -dr --no-show-raw-insn %t | FileCheck --check-prefixes=LER %s # RUN: ld.lld --emit-relocs --no-relax %t.o -o %t.norelax # RUN: llvm-readelf -x .got %t.norelax 2>&1 | FileCheck --check-prefix=LE-GOT %s @@ -42,6 +41,29 @@ # LE-NEXT:add.d $a2, $a2, $tp # LE-NEXT:add.d $a3, $a3, $tp +# LER: 20158: ori $a0, $zero, 4095 +# LER-NEXT: R_LARCH_TLS_IE_PC_HI20 a +# LER-NEXT: R_LARCH_RELAX *ABS* +# LER-NEXT: R_LARCH_TLS_IE_PC_LO12 a +# LER-NEXT: R_LARCH_RELAX *ABS* +# LER-NEXT:add.d $a0, $a0, $tp +# LER-NEXT: 20160: lu12i.w $a1, 1 +# LER-NEXT: R_LARCH_TLS_IE_PC_HI20 b +# LER-NEXT:ori $a1, $a1, 0 +# LER-NEXT: R_LARCH_TLS_IE_PC_LO12 b +# LER-NEXT:add.d $a1, $a1, $tp +# LER-NEXT: 2016c: lu12i.w $a3, 1 +# LER-NEXT: R_LARCH_TLS_IE_PC_HI20 a +# LER-NEXT: R_LARCH_RELAX *ABS* +# LER-NEXT: R_LARCH_TLS_IE_PC_HI20 b +# LER-NEXT: R_LARCH_RELAX *ABS* +# LER-NEXT:ori $a2, $zero, 4095 +# LER-NEXT: R_LARCH_TLS_IE_PC_LO12 a +# LER-NEXT:ori $a3, $a3, 0 +# LER-NEXT: R_LARCH_TLS_IE_PC_LO12 b +# LER-NEXT:add.d $a2, $a2, $tp +# LER-NEXT:add.d $a3, $a3, $tp + la.tls.ie $a0, a# relax add.d $a0, $a0, $tp >From 9d99de87229b84f65f392dc5eb73bf1aef16fa65 Mon Sep 17 00:00:00 2001 From: yangzhaoxin Date: Fri, 17 Jan 2025 09:00:44 +0800 Subject: [PATCH 3/3] Modify test. Add --relax option. --- lld/test/ELF/loongarch-relax-tls-ie.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lld/test/ELF/loongarch-relax-tls-ie.s b/lld/test/ELF/loongarch-relax-tls-ie.s index be76263f2978e0..2c95a342251f20 100644 --- a/lld/test/ELF/loongarch-relax-tls-ie.s +++ b/lld/test/ELF/loongarch-relax-tls-ie.s