[llvm] [BOLT][AArch64] Extend test coverage for TailDuplication in AArch64 (PR #191453)

Amina Chabane via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 14 03:05:27 PDT 2026


https://github.com/Amichaxx updated https://github.com/llvm/llvm-project/pull/191453

>From 980db08b01adac96116b32bcc1ee5354af4bbfe1 Mon Sep 17 00:00:00 2001
From: Amichaxx <amina.chabane at arm.com>
Date: Fri, 10 Apr 2026 15:59:25 +0000
Subject: [PATCH 1/4] [BOLT][AArch64] Extend test coverage for TailDuplication
 in AArch64

Adds tests for tail duplication in values moderate/aggressive/cache
for AArch64.
---
 bolt/test/AArch64/tail-duplication-cache.s | 59 ++++++++++++++++++++++
 bolt/test/AArch64/tail-duplication-pass.s  | 36 +++++++++++++
 2 files changed, 95 insertions(+)
 create mode 100644 bolt/test/AArch64/tail-duplication-cache.s
 create mode 100644 bolt/test/AArch64/tail-duplication-pass.s

diff --git a/bolt/test/AArch64/tail-duplication-cache.s b/bolt/test/AArch64/tail-duplication-cache.s
new file mode 100644
index 0000000000000..bc10438faca20
--- /dev/null
+++ b/bolt/test/AArch64/tail-duplication-cache.s
@@ -0,0 +1,59 @@
+# REQUIRES: system-linux
+
+# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
+# RUN: link_fdata %s %t.o %t.fdata
+# RUN: link_fdata %s %t.o %t.fdata2 "FDATA2"
+# RUN: %clang %cflags --target=aarch64-unknown-linux %t.o -o %t.exe -Wl,-q
+# RUN: llvm-bolt %t.exe --data %t.fdata --reorder-blocks=none \
+# RUN:    --print-finalized --tail-duplication=cache -o %t.out | FileCheck %s
+# RUN: llvm-bolt %t.exe --data %t.fdata2 --reorder-blocks=none \
+# RUN:    --print-finalized --tail-duplication=cache -o %t.out2 \
+# RUN:    | FileCheck %s --check-prefix="CHECK2"
+
+## A test where the tail is duplicated to eliminate an unconditional jump.
+# FDATA: 1 main #.BB0_br# 1 main #.BB4# 0 100
+# FDATA: 1 main #.BB0_br# 1 main #.BB1# 0 100
+# FDATA: 1 main #.BB1_br# 1 main #.BB3# 0 50
+# FDATA: 1 main #.BB1_br# 1 main #.BB2# 0 50
+# FDATA: 1 main #.BB3_br# 1 main #.BB2# 0 50
+# CHECK: BOLT-INFO: tail duplication modified 1 ({{.*}}%) functions; duplicated 1 blocks (20 bytes) responsible for 50 dynamic executions ({{.*}}% of all block executions)
+# CHECK: BB Layout   : .LBB00, .Ltmp0, .Ltmp1, .Ltmp2, .Ltmp3, .Ltmp4, .Ltmp5, .Ltail-dup0, .Ltmp6
+
+## A test where the tail is not duplicated due to the cache score.
+# FDATA2: 1 main #.BB0_br# 1 main #.BB4# 0 100
+# FDATA2: 1 main #.BB0_br# 1 main #.BB1# 0 2
+# FDATA2: 1 main #.BB1_br# 1 main #.BB3# 0 1
+# FDATA2: 1 main #.BB1_br# 1 main #.BB2# 0 1
+# FDATA2: 1 main #.BB3_br# 1 main #.BB2# 0 1
+# CHECK2: BOLT-INFO: tail duplication modified 0 (0.00%) functions; duplicated 0 blocks (0 bytes) responsible for 0 dynamic executions (0.00% of all block executions)
+# CHECK2: BB Layout   : .LBB00, .Ltmp0, .Ltmp1, .Ltmp2, .Ltmp3, .Ltmp4, .Ltmp5, .Ltmp6
+
+    .text
+    .globl main
+    .type main, %function
+    .size main, .Lend-main
+main:
+.BB0:
+    eor w0, w0, w0
+.BB0_br:
+    cbz w0, .BB4
+.BB1:
+    add x0, x0, #1
+.BB1_br:
+    cbz w0, .BB3
+.BB2:
+    add x0, x0, #1
+    add x0, x0, #1
+    add x0, x0, #1
+    add x0, x0, #1
+    ret
+.BB3:
+    add x0, x0, #1
+.BB3_br:
+    b .BB2
+.BB4:
+    ret
+
+## Force relocation mode against text.
+    .reloc 0, R_AARCH64_NONE
+.Lend:
diff --git a/bolt/test/AArch64/tail-duplication-pass.s b/bolt/test/AArch64/tail-duplication-pass.s
new file mode 100644
index 0000000000000..6a90531359719
--- /dev/null
+++ b/bolt/test/AArch64/tail-duplication-pass.s
@@ -0,0 +1,36 @@
+# REQUIRES: system-linux
+
+# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
+# RUN: link_fdata %s %t.o %t.fdata
+# RUN: %clang %cflags --target=aarch64-unknown-linux %t.o -o %t.exe -Wl,-q
+# RUN: llvm-bolt %t.exe --data %t.fdata --reorder-blocks=none \
+# RUN:    --print-finalized --tail-duplication=moderate \
+# RUN:    --tail-duplication-minimum-offset=1 -o %t.out | FileCheck %s
+# RUN: llvm-bolt %t.exe --data %t.fdata --reorder-blocks=none \
+# RUN:    --print-finalized --tail-duplication=aggressive \
+# RUN:    --tail-duplication-minimum-offset=1 -o %t.out \
+# RUN:    | FileCheck %s --check-prefix=CHECK-NOLOOP
+
+# FDATA: 1 main 4 1 main #.BB2# 0 10
+# CHECK: BOLT-INFO: tail duplication modified 1 ({{.*}}%) functions; duplicated 1 blocks (4 bytes) responsible for {{.*}} dynamic executions ({{.*}}% of all block executions)
+# CHECK: BB Layout   : .LBB00, .Ltail-dup0, .Ltmp0, .Ltmp1
+
+## Check that the predecessor of Ltail-dup0 is .LBB00, not itself.
+# CHECK-NOLOOP-LABEL: .Ltail-dup0 (1 instructions, align : 1)
+# CHECK-NOLOOP-NEXT:   Predecessors: .LBB00
+# CHECK-NOLOOP-NEXT:   ret
+    .text
+    .globl main
+    .type main, %function
+main:
+.BB0:
+    eor w0, w0, w0
+    b .BB2
+.BB1:
+    add x0, x0, #1
+.BB2:
+    ret
+
+## Force relocation mode against text.
+    .reloc 0, R_AARCH64_NONE
+.Lend:

>From 3435f654585e4663d226a4df43bfaddb0668e69a Mon Sep 17 00:00:00 2001
From: Amichaxx <amina.chabane at arm.com>
Date: Fri, 10 Apr 2026 16:16:27 +0000
Subject: [PATCH 2/4] readd exec count

---
 bolt/test/AArch64/tail-duplication-pass.s | 1 +
 1 file changed, 1 insertion(+)

diff --git a/bolt/test/AArch64/tail-duplication-pass.s b/bolt/test/AArch64/tail-duplication-pass.s
index 6a90531359719..ca15698695d0a 100644
--- a/bolt/test/AArch64/tail-duplication-pass.s
+++ b/bolt/test/AArch64/tail-duplication-pass.s
@@ -17,6 +17,7 @@
 
 ## Check that the predecessor of Ltail-dup0 is .LBB00, not itself.
 # CHECK-NOLOOP-LABEL: .Ltail-dup0 (1 instructions, align : 1)
+# CHECK-NOLOOP-NEXT:   Exec Count : {{.*}}
 # CHECK-NOLOOP-NEXT:   Predecessors: .LBB00
 # CHECK-NOLOOP-NEXT:   ret
     .text

>From 4620157ff47594d266a7a9c3bfc62a26727bde18 Mon Sep 17 00:00:00 2001
From: Amichaxx <amina.chabane at arm.com>
Date: Mon, 13 Apr 2026 16:02:47 +0000
Subject: [PATCH 3/4] Update x86 test comment.

---
 bolt/test/X86/tail-duplication-pass.s | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bolt/test/X86/tail-duplication-pass.s b/bolt/test/X86/tail-duplication-pass.s
index 9867f74fa3444..8c092b3fac485 100644
--- a/bolt/test/X86/tail-duplication-pass.s
+++ b/bolt/test/X86/tail-duplication-pass.s
@@ -16,7 +16,7 @@
 # CHECK: BOLT-INFO: tail duplication modified 1 ({{.*}}%) functions; duplicated 1 blocks (1 bytes) responsible for {{.*}} dynamic executions ({{.*}}% of all block executions)
 # CHECK: BB Layout   : .LBB00, .Ltail-dup0, .Ltmp0, .Ltmp1
 
-## Check that the successor of Ltail-dup0 is .LBB00, not itself.
+## Check that the predecessor of Ltail-dup0 is .LBB00, not itself.
 # CHECK-NOLOOP: .Ltail-dup0 (1 instructions, align : 1)
 # CHECK-NOLOOP: Predecessors: .LBB00
 # CHECK-NOLOOP: retq

>From b28e4e888de2ea83f6c6338825d7f26065e01262 Mon Sep 17 00:00:00 2001
From: Amichaxx <amina.chabane at arm.com>
Date: Tue, 14 Apr 2026 10:04:38 +0000
Subject: [PATCH 4/4] Update tests

---
 bolt/test/AArch64/tail-duplication-cache.s | 8 ++++++++
 bolt/test/AArch64/tail-duplication-pass.s  | 5 +++++
 2 files changed, 13 insertions(+)

diff --git a/bolt/test/AArch64/tail-duplication-cache.s b/bolt/test/AArch64/tail-duplication-cache.s
index bc10438faca20..246d7cf91415a 100644
--- a/bolt/test/AArch64/tail-duplication-cache.s
+++ b/bolt/test/AArch64/tail-duplication-cache.s
@@ -18,6 +18,14 @@
 # FDATA: 1 main #.BB3_br# 1 main #.BB2# 0 50
 # CHECK: BOLT-INFO: tail duplication modified 1 ({{.*}}%) functions; duplicated 1 blocks (20 bytes) responsible for 50 dynamic executions ({{.*}}% of all block executions)
 # CHECK: BB Layout   : .LBB00, .Ltmp0, .Ltmp1, .Ltmp2, .Ltmp3, .Ltmp4, .Ltmp5, .Ltail-dup0, .Ltmp6
+# CHECK-LABEL: .Ltail-dup0 (5 instructions, align : 1)
+# CHECK-NEXT:   Exec Count : {{.*}}
+# CHECK-NEXT:   Predecessors: .Ltmp5
+# CHECK-NEXT:   add x0, x0, #0x1
+# CHECK-NEXT:   add x0, x0, #0x1
+# CHECK-NEXT:   add x0, x0, #0x1
+# CHECK-NEXT:   add x0, x0, #0x1
+# CHECK-NEXT:   ret
 
 ## A test where the tail is not duplicated due to the cache score.
 # FDATA2: 1 main #.BB0_br# 1 main #.BB4# 0 100
diff --git a/bolt/test/AArch64/tail-duplication-pass.s b/bolt/test/AArch64/tail-duplication-pass.s
index ca15698695d0a..5b1dc39607f38 100644
--- a/bolt/test/AArch64/tail-duplication-pass.s
+++ b/bolt/test/AArch64/tail-duplication-pass.s
@@ -14,6 +14,11 @@
 # FDATA: 1 main 4 1 main #.BB2# 0 10
 # CHECK: BOLT-INFO: tail duplication modified 1 ({{.*}}%) functions; duplicated 1 blocks (4 bytes) responsible for {{.*}} dynamic executions ({{.*}}% of all block executions)
 # CHECK: BB Layout   : .LBB00, .Ltail-dup0, .Ltmp0, .Ltmp1
+# CHECK-LABEL: .LBB00 (1 instructions, align : 1)
+# CHECK-NEXT:   Entry Point
+# CHECK-NEXT:   Exec Count : {{.*}}
+# CHECK-NEXT:   eor w0, w0, w0
+# CHECK-NEXT:   Successors: .Ltail-dup0
 
 ## Check that the predecessor of Ltail-dup0 is .LBB00, not itself.
 # CHECK-NOLOOP-LABEL: .Ltail-dup0 (1 instructions, align : 1)



More information about the llvm-commits mailing list