[llvm] [utils][UpdateLLCTestChecks] Add MIR support to update_llc_test_checks.py. (PR #164965)
    Valery Pykhtin via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Fri Oct 24 05:21:37 PDT 2025
    
    
  
https://github.com/vpykhtin created https://github.com/llvm/llvm-project/pull/164965
This change enables update_llc_test_checks.py to automatically generate MIR checks for RUN lines that use `-stop-before` or `-stop-after` flags allowing tests to verify intermediate compilation stages (e.g., after instruction selection but before peephole optimizations) alongside the final assembly output.
This resulted from the scenario, when I needed to test two instruction matching patterns where the later pattern in the peepholler reverts the earlier pattern in the instruction selector and distinguish it from the case when the earlier pattern didn't worked at all.
Drawback: this may create very noisy tests.
Note: This is 100% Claude Sonnet 4.5 and I don't feel I understand the change in details, but the change looks so small that I decided to give it a chance.
>From c76fa54d56c013816455a8b48b4816c1f0d8b42b Mon Sep 17 00:00:00 2001
From: Valery Pykhtin <valery.pykhtin at amd.com>
Date: Fri, 24 Oct 2025 11:41:06 +0000
Subject: [PATCH] [utils][UpdateLLCTestChecks] Add MIR support to
 update_llc_test_checks.py
This change enables update_llc_test_checks.py to automatically generate
MIR checks for RUN lines that use -stop-before or -stop-after flags.
This allows tests to verify intermediate compilation stages (e.g., after
instruction selection but before peephole optimizations) alongside the
final assembly output.
---
 llvm/utils/update_llc_test_checks.py | 55 ++++++++++++++++++++++++----
 1 file changed, 48 insertions(+), 7 deletions(-)
diff --git a/llvm/utils/update_llc_test_checks.py b/llvm/utils/update_llc_test_checks.py
index 8c57e75f34f75..5c008e2d2ed2c 100755
--- a/llvm/utils/update_llc_test_checks.py
+++ b/llvm/utils/update_llc_test_checks.py
@@ -13,9 +13,11 @@
 from traceback import print_exc
 import argparse
 import os  # Used to advertise this file's name ("autogenerated_note").
+import re
 import sys
 
 from UpdateTestChecks import common
+import update_mir_test_checks # Reuse MIR parsing code.
 
 # llc is the only llc-like in the LLVM tree but downstream forks can add
 # additional ones here if they have them.
@@ -23,6 +25,9 @@
     "llc",
 ]
 
+def has_stop_pass_flag(llc_args):
+    """Check if llc arguments contain -stop-before or -stop-after flag."""
+    return re.search(r'-stop-(?:before|after)=', llc_args) is not None
 
 def update_test(ti: common.TestInfo):
     triple_in_ir = None
@@ -119,6 +124,10 @@ def update_test(ti: common.TestInfo):
         ginfo=ginfo,
     )
 
+    # Dictionary to store MIR function bodies separately
+    mir_func_dict = {}
+    mir_run_list = []
+
     for (
         prefixes,
         llc_tool,
@@ -141,14 +150,31 @@ def update_test(ti: common.TestInfo):
         if not triple:
             triple = common.get_triple_from_march(march_in_cmd)
 
-        scrubber, function_re = output_type.get_run_handler(triple)
-        if 0 == builder.process_run_line(
-            function_re, scrubber, raw_tool_output, prefixes
-        ):
-            common.warn(
-                "Couldn't match any function. Possibly the wrong target triple has been provided"
+        # Check if this run generates MIR output
+        if has_stop_pass_flag(llc_args):
+            common.debug("Detected MIR output mode for prefixes:", str(prefixes))
+            # Initialize MIR func_dict for these prefixes.
+            for prefix in prefixes:
+                if prefix not in mir_func_dict:
+                    mir_func_dict[prefix] = {}
+            
+            # Build MIR function dictionary using imported function.
+            update_mir_test_checks.build_function_info_dictionary(
+                ti.path, raw_tool_output, triple, prefixes, mir_func_dict, ti.args.verbose
             )
-        builder.processed_prefixes(prefixes)
+            
+            # Store this run info for later.
+            mir_run_list.append((prefixes, llc_tool, llc_args, triple_in_cmd, march_in_cmd))
+        else:
+            # Regular assembly output.
+            scrubber, function_re = output_type.get_run_handler(triple)
+            if 0 == builder.process_run_line(
+                function_re, scrubber, raw_tool_output, prefixes
+            ):
+                common.warn(
+                    "Couldn't match any function. Possibly the wrong target triple has been provided"
+                )
+            builder.processed_prefixes(prefixes)
 
     func_dict = builder.finish_and_get_func_dict()
     global_vars_seen_dict = {}
@@ -221,6 +247,21 @@ def update_test(ti: common.TestInfo):
                         is_filtered=builder.is_filtered(),
                     )
                 )
+                
+                # Also add MIR checks if we have them for this function
+                if mir_run_list and func_name:
+                    common.add_mir_checks_for_function(
+                        ti.path,
+                        output_lines,
+                        mir_run_list,
+                        mir_func_dict,
+                        func_name,
+                        single_bb=False, # Don't skip basic block labels.
+                        print_fixed_stack=False, # Don't print fixed stack (ASM tests don't need it).
+                        first_check_is_next=False, # First check is LABEL, not NEXT.
+                        at_the_function_name=False, # Use "name:" not "@name".
+                    )
+                
                 is_in_function_start = False
 
             if is_in_function:
    
    
More information about the llvm-commits
mailing list