[llvm] 356f2fc - [UpdateTestChecks] Add --filter/--filter-out support to update_mir_test_checks.py (#191059)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 14 05:22:40 PDT 2026
Author: Petar Avramovic
Date: 2026-04-14T14:22:34+02:00
New Revision: 356f2fcf412b19e37a98c61abf36917cad3455d6
URL: https://github.com/llvm/llvm-project/commit/356f2fcf412b19e37a98c61abf36917cad3455d6
DIFF: https://github.com/llvm/llvm-project/commit/356f2fcf412b19e37a98c61abf36917cad3455d6.diff
LOG: [UpdateTestChecks] Add --filter/--filter-out support to update_mir_test_checks.py (#191059)
These options were already accepted by the script but silently ignored.
This patch makes them functional, consistent with
update_llc_test_checks.py.
Co-Authored-By: Claude Sonnet 4.6 <noreply at anthropic.com>
Added:
llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/x86-filter.mir
llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/x86-filter.mir.filter-out.expected
llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/x86-filter.mir.filter.expected
llvm/test/tools/UpdateTestChecks/update_mir_test_checks/x86-filter.test
Modified:
llvm/utils/UpdateTestChecks/mir.py
llvm/utils/update_mir_test_checks.py
Removed:
################################################################################
diff --git a/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/x86-filter.mir b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/x86-filter.mir
new file mode 100644
index 0000000000000..6168bee9c5918
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/x86-filter.mir
@@ -0,0 +1,55 @@
+# RUN: llc -mtriple=x86_64-linux-gnu -run-pass=instruction-select -verify-machineinstrs %s -o - | FileCheck %s
+
+--- |
+
+ define i8 @ptrtoint_s8(ptr %p) {
+ entry:
+ %0 = ptrtoint ptr %p to i8
+ ret i8 %0
+ }
+
+ define i32 @ptrtoint_s32(ptr %p) {
+ entry:
+ %0 = ptrtoint ptr %p to i32
+ ret i32 %0
+ }
+
+...
+---
+name: ptrtoint_s8
+alignment: 16
+legalized: true
+regBankSelected: true
+tracksRegLiveness: true
+registers:
+ - { id: 0, class: gpr }
+ - { id: 1, class: gpr }
+body: |
+ bb.1.entry:
+ liveins: $rdi
+
+ %0:gpr(p0) = COPY $rdi
+ %1:gpr(s8) = G_PTRTOINT %0(p0)
+ $al = COPY %1(s8)
+ RET 0, implicit $al
+
+...
+---
+name: ptrtoint_s32
+alignment: 16
+legalized: true
+regBankSelected: true
+tracksRegLiveness: true
+registers:
+ - { id: 0, class: gpr }
+ - { id: 1, class: gpr }
+body: |
+ bb.1.entry:
+ liveins: $rdi
+
+ %0:gpr(p0) = COPY $rdi
+ %1:gpr(s32) = G_PTRTOINT %0(p0)
+ $eax = COPY %1(s32)
+ RET 0, implicit $eax
+
+...
diff --git a/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/x86-filter.mir.filter-out.expected b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/x86-filter.mir.filter-out.expected
new file mode 100644
index 0000000000000..87c3670a10421
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/x86-filter.mir.filter-out.expected
@@ -0,0 +1,67 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --filter-out "sub_"
+# RUN: llc -mtriple=x86_64-linux-gnu -run-pass=instruction-select -verify-machineinstrs %s -o - | FileCheck %s
+
+--- |
+
+ define i8 @ptrtoint_s8(ptr %p) {
+ entry:
+ %0 = ptrtoint ptr %p to i8
+ ret i8 %0
+ }
+
+ define i32 @ptrtoint_s32(ptr %p) {
+ entry:
+ %0 = ptrtoint ptr %p to i32
+ ret i32 %0
+ }
+
+...
+---
+name: ptrtoint_s8
+alignment: 16
+legalized: true
+regBankSelected: true
+tracksRegLiveness: true
+registers:
+ - { id: 0, class: gpr }
+ - { id: 1, class: gpr }
+body: |
+ bb.1.entry:
+ liveins: $rdi
+
+ ; CHECK-LABEL: name: ptrtoint_s8
+ ; CHECK: liveins: $rdi
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: $al = COPY [[COPY1]]
+ ; CHECK-NEXT: RET 0, implicit $al
+ %0:gpr(p0) = COPY $rdi
+ %1:gpr(s8) = G_PTRTOINT %0(p0)
+ $al = COPY %1(s8)
+ RET 0, implicit $al
+
+...
+---
+name: ptrtoint_s32
+alignment: 16
+legalized: true
+regBankSelected: true
+tracksRegLiveness: true
+registers:
+ - { id: 0, class: gpr }
+ - { id: 1, class: gpr }
+body: |
+ bb.1.entry:
+ liveins: $rdi
+
+ ; CHECK-LABEL: name: ptrtoint_s32
+ ; CHECK: liveins: $rdi
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr64 = COPY $rdi
+ ; CHECK-NEXT: $eax = COPY [[COPY1]]
+ ; CHECK-NEXT: RET 0, implicit $eax
+ %0:gpr(p0) = COPY $rdi
+ %1:gpr(s32) = G_PTRTOINT %0(p0)
+ $eax = COPY %1(s32)
+ RET 0, implicit $eax
+
+...
diff --git a/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/x86-filter.mir.filter.expected b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/x86-filter.mir.filter.expected
new file mode 100644
index 0000000000000..39064f9a3ae3c
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/x86-filter.mir.filter.expected
@@ -0,0 +1,58 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --filter "sub_"
+# RUN: llc -mtriple=x86_64-linux-gnu -run-pass=instruction-select -verify-machineinstrs %s -o - | FileCheck %s
+
+--- |
+
+ define i8 @ptrtoint_s8(ptr %p) {
+ entry:
+ %0 = ptrtoint ptr %p to i8
+ ret i8 %0
+ }
+
+ define i32 @ptrtoint_s32(ptr %p) {
+ entry:
+ %0 = ptrtoint ptr %p to i32
+ ret i32 %0
+ }
+
+...
+---
+name: ptrtoint_s8
+alignment: 16
+legalized: true
+regBankSelected: true
+tracksRegLiveness: true
+registers:
+ - { id: 0, class: gpr }
+ - { id: 1, class: gpr }
+body: |
+ bb.1.entry:
+ liveins: $rdi
+
+ ; CHECK-LABEL: name: ptrtoint_s8
+ ; CHECK: [[COPY1:%[0-9]+]]:gr8 = COPY [[COPY]].sub_8bit
+ %0:gpr(p0) = COPY $rdi
+ %1:gpr(s8) = G_PTRTOINT %0(p0)
+ $al = COPY %1(s8)
+ RET 0, implicit $al
+
+...
+---
+name: ptrtoint_s32
+alignment: 16
+legalized: true
+regBankSelected: true
+tracksRegLiveness: true
+registers:
+ - { id: 0, class: gpr }
+ - { id: 1, class: gpr }
+body: |
+ bb.1.entry:
+ liveins: $rdi
+
+ %0:gpr(p0) = COPY $rdi
+ %1:gpr(s32) = G_PTRTOINT %0(p0)
+ $eax = COPY %1(s32)
+ RET 0, implicit $eax
+
+...
diff --git a/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/x86-filter.test b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/x86-filter.test
new file mode 100644
index 0000000000000..b4c92f80d3bc5
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/x86-filter.test
@@ -0,0 +1,17 @@
+# REQUIRES: x86-registered-target
+
+## Check that --filter works properly.
+# RUN: cp -f %S/Inputs/x86-filter.mir %t.mir && %update_mir_test_checks --filter="sub_" %t.mir
+# RUN:
diff -u %t.mir %S/Inputs/x86-filter.mir.filter.expected
+
+## Check that running the script again does not change the result:
+# RUN: %update_mir_test_checks --filter="sub_" %t.mir
+# RUN:
diff -u %t.mir %S/Inputs/x86-filter.mir.filter.expected
+
+## Check that --filter-out works properly.
+# RUN: cp -f %S/Inputs/x86-filter.mir %t.mir && %update_mir_test_checks --filter-out="sub_" %t.mir
+# RUN:
diff -u %t.mir %S/Inputs/x86-filter.mir.filter-out.expected
+
+## Check that running the script again does not change the result:
+# RUN: %update_mir_test_checks --filter-out="sub_" %t.mir
+# RUN:
diff -u %t.mir %S/Inputs/x86-filter.mir.filter-out.expected
diff --git a/llvm/utils/UpdateTestChecks/mir.py b/llvm/utils/UpdateTestChecks/mir.py
index 01ee0e19f7cb9..b6fa324d0565e 100644
--- a/llvm/utils/UpdateTestChecks/mir.py
+++ b/llvm/utils/UpdateTestChecks/mir.py
@@ -52,7 +52,7 @@
def build_function_info_dictionary(
- test, raw_tool_output, triple, prefixes, func_dict, verbose
+ test, raw_tool_output, triple, prefixes, func_dict, verbose, filters=None
):
for m in MIR_FUNC_RE.finditer(raw_tool_output):
func = m.group("func")
@@ -84,10 +84,11 @@ def build_function_info_dictionary(
)
mangled.append(func_line)
body = "".join(mangled)
+ filtered_body = common.do_filter(body, filters)
for prefix in prefixes:
info = common.function_body(
- body, fixedStack, None, None, None, None, ginfo=None
+ filtered_body, fixedStack, None, None, None, None, ginfo=None
)
if func in func_dict[prefix]:
if (
diff --git a/llvm/utils/update_mir_test_checks.py b/llvm/utils/update_mir_test_checks.py
index ba70249db28e6..0870b66f4139b 100755
--- a/llvm/utils/update_mir_test_checks.py
+++ b/llvm/utils/update_mir_test_checks.py
@@ -139,6 +139,7 @@ def update_test_file(args, test, autogenerated_note):
prefixes,
func_dict,
args.verbose,
+ filters=args.filters,
)
prefix_set = set([prefix for run in run_list for prefix in run[0]])
More information about the llvm-commits
mailing list