[llvm] [X86][utils] Support `-basic-block-sections` in `update_llc_test_checks` (PR #178999)

Mikhail Gudim via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 31 03:45:51 PST 2026


https://github.com/mgudim updated https://github.com/llvm/llvm-project/pull/178999

>From 4ed486d932679c3d925077859d918611ca2e147c Mon Sep 17 00:00:00 2001
From: Mikhail Gudim <mgudim at qti.qualcomm.com>
Date: Fri, 30 Jan 2026 15:48:11 -0800
Subject: [PATCH] [X86][utils] Support `-basic-block-sections` in
 `update_llc_test_checks`

If `-basic-block-sections` is present in the `RUN` line then choose a
different regex to extract function body from generated assembly. This
regex does not end function body at `.section` or `.cfi_endproc`.
---
 llvm/utils/UpdateTestChecks/asm.py   | 23 +++++++++++++++++++----
 llvm/utils/update_llc_test_checks.py |  8 +++++++-
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/llvm/utils/UpdateTestChecks/asm.py b/llvm/utils/UpdateTestChecks/asm.py
index 5f441227092f4..51c891e175a8b 100644
--- a/llvm/utils/UpdateTestChecks/asm.py
+++ b/llvm/utils/UpdateTestChecks/asm.py
@@ -31,6 +31,17 @@ class string:
     flags=(re.M | re.S),
 )
 
+# TODO: update other triplets that support basic-block-sections
+ASM_FUNCTION_X86_BB_SECTIONS_RE = re.compile(
+    r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*(@"?(?P=func)"?| -- Begin function (?P=func))\n(?:\s*\.?Lfunc_begin[^:\n]*:\n)?'
+    r"(?:\.L(?P=func)\$local:\n)?"  # drop .L<func>$local:
+    r"(?:\s*\.type\s+\.L(?P=func)\$local, at function\n)?"  # drop .type .L<func>$local
+    r"(?:[ \t]*(?:\.cfi_startproc|\.cfi_personality|\.cfi_lsda|\.seh_proc|\.seh_handler)\b[^\n]*\n)*"  # drop optional cfi
+    r"(?P<body>^##?[ \t]+[^:]+:.*?)\s*"
+    r"^\s*(?:\.globl|\.comm|#+ -- End function)",
+    flags=(re.M | re.S),
+)
+
 ASM_FUNCTION_ARM_RE = re.compile(
     r'^(?P<func>[0-9a-zA-Z_$]+):[ \t]*(@+[ \t]*@"?(?P=func)"?)?\n'  # f: (name of function)
     r"(?:\.L(?P=func)\$local:\n)?"  # drop .L<func>$local:
@@ -559,11 +570,15 @@ def scrub_asm_loongarch(asm, args):
 # Returns a tuple of a scrub function and a function regex. Scrub function is
 # used to alter function body in some way, for example, remove trailing spaces.
 # Function regex is used to match function name, body, etc. in raw llc output.
-def get_run_handler(triple):
+def get_run_handler(triple, bb_sections=False):
+    # TODO: update other triplets that support basic-block-sections
+    asm_func_x86_re = (
+        ASM_FUNCTION_X86_BB_SECTIONS_RE if bb_sections else ASM_FUNCTION_X86_RE
+    )
     target_handlers = {
-        "i686": (scrub_asm_x86, ASM_FUNCTION_X86_RE),
-        "x86": (scrub_asm_x86, ASM_FUNCTION_X86_RE),
-        "i386": (scrub_asm_x86, ASM_FUNCTION_X86_RE),
+        "i686": (scrub_asm_x86, asm_func_x86_re),
+        "x86": (scrub_asm_x86, asm_func_x86_re),
+        "i386": (scrub_asm_x86, asm_func_x86_re),
         "arm64_32": (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE),
         "aarch64": (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_RE),
         "aarch64-apple-darwin": (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE),
diff --git a/llvm/utils/update_llc_test_checks.py b/llvm/utils/update_llc_test_checks.py
index 98864be62875b..4b9ece4d83d22 100755
--- a/llvm/utils/update_llc_test_checks.py
+++ b/llvm/utils/update_llc_test_checks.py
@@ -170,7 +170,13 @@ def update_test(ti: common.TestInfo):
             )
         else:
             # ASM output mode
-            scrubber, function_re = output_type.get_run_handler(triple)
+
+            bb_sections = "basic-block-sections" in llc_args and (
+                triple.startswith("x86")
+                or triple.startswith("i686")
+                or triple.startswith("i386")
+            )
+            scrubber, function_re = output_type.get_run_handler(triple, bb_sections)
             if 0 == builder.process_run_line(
                 function_re, scrubber, raw_tool_output, prefixes
             ):



More information about the llvm-commits mailing list