update_analyze_test_checks.py: fix --filter handling
authorRoman Lebedev <lebedev.ri@gmail.com>
Mon, 7 Mar 2022 12:37:06 +0000 (15:37 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Mon, 7 Mar 2022 12:41:13 +0000 (15:41 +0300)
In particular, after filtering the check lines can't necessarily
use `-NEXT`, they may not be one directly after another.

llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/x86-filter.ll [new file with mode: 0644]
llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/x86-filter.ll.filter.expected [new file with mode: 0644]
llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/filter.test [new file with mode: 0644]
llvm/utils/UpdateTestChecks/common.py
llvm/utils/update_analyze_test_checks.py

diff --git a/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/x86-filter.ll b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/x86-filter.ll
new file mode 100644 (file)
index 0000000..24c5be2
--- /dev/null
@@ -0,0 +1,10 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
+; RUN: opt < %s -passes='print<cost-model>' -mtriple=x86_64-pc-linux-gnu 2>&1 -disable-output -mattr=+sse2 | FileCheck %s --check-prefixes=SSE2
+
+define void @replication_i64_stride2() nounwind {
+  %vf2 = shufflevector <2 x i64> undef, <2 x i64> poison, <4 x i32> <i32 0, i32 0, i32 1, i32 1>
+  %vf4 = shufflevector <4 x i64> undef, <4 x i64> poison, <8 x i32> <i32 0, i32 0, i32 1, i32 1, i32 2, i32 2, i32 3, i32 3>
+  %vf8 = shufflevector <8 x i64> undef, <8 x i64> poison, <16 x i32> <i32 0, i32 0, i32 1, i32 1, i32 2, i32 2, i32 3, i32 3, i32 4, i32 4, i32 5, i32 5, i32 6, i32 6, i32 7, i32 7>
+  %vf16 = shufflevector <16 x i64> undef, <16 x i64> poison, <32 x i32> <i32 0, i32 0, i32 1, i32 1, i32 2, i32 2, i32 3, i32 3, i32 4, i32 4, i32 5, i32 5, i32 6, i32 6, i32 7, i32 7, i32 8, i32 8, i32 9, i32 9, i32 10, i32 10, i32 11, i32 11, i32 12, i32 12, i32 13, i32 13, i32 14, i32 14, i32 15, i32 15>
+  ret void
+}
diff --git a/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/x86-filter.ll.filter.expected b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/x86-filter.ll.filter.expected
new file mode 100644 (file)
index 0000000..fd0d0a4
--- /dev/null
@@ -0,0 +1,14 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
+; RUN: opt < %s -passes='print<cost-model>' -mtriple=x86_64-pc-linux-gnu 2>&1 -disable-output -mattr=+sse2 | FileCheck %s --check-prefixes=SSE2
+
+define void @replication_i64_stride2() nounwind {
+; SSE2-LABEL: 'replication_i64_stride2'
+; SSE2:  Cost Model: Found an estimated cost of 18 for instruction: %vf4 = shufflevector <4 x i64> undef, <4 x i64> poison, <8 x i32> <i32 0, i32 0, i32 1, i32 1, i32 2, i32 2, i32 3, i32 3>
+; SSE2:  Cost Model: Found an estimated cost of 72 for instruction: %vf16 = shufflevector <16 x i64> undef, <16 x i64> poison, <32 x i32> <i32 0, i32 0, i32 1, i32 1, i32 2, i32 2, i32 3, i32 3, i32 4, i32 4, i32 5, i32 5, i32 6, i32 6, i32 7, i32 7, i32 8, i32 8, i32 9, i32 9, i32 10, i32 10, i32 11, i32 11, i32 12, i32 12, i32 13, i32 13, i32 14, i32 14, i32 15, i32 15>
+;
+  %vf2 = shufflevector <2 x i64> undef, <2 x i64> poison, <4 x i32> <i32 0, i32 0, i32 1, i32 1>
+  %vf4 = shufflevector <4 x i64> undef, <4 x i64> poison, <8 x i32> <i32 0, i32 0, i32 1, i32 1, i32 2, i32 2, i32 3, i32 3>
+  %vf8 = shufflevector <8 x i64> undef, <8 x i64> poison, <16 x i32> <i32 0, i32 0, i32 1, i32 1, i32 2, i32 2, i32 3, i32 3, i32 4, i32 4, i32 5, i32 5, i32 6, i32 6, i32 7, i32 7>
+  %vf16 = shufflevector <16 x i64> undef, <16 x i64> poison, <32 x i32> <i32 0, i32 0, i32 1, i32 1, i32 2, i32 2, i32 3, i32 3, i32 4, i32 4, i32 5, i32 5, i32 6, i32 6, i32 7, i32 7, i32 8, i32 8, i32 9, i32 9, i32 10, i32 10, i32 11, i32 11, i32 12, i32 12, i32 13, i32 13, i32 14, i32 14, i32 15, i32 15>
+  ret void
+}
diff --git a/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/filter.test b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/filter.test
new file mode 100644 (file)
index 0000000..0be97d5
--- /dev/null
@@ -0,0 +1,9 @@
+# REQUIRES: x86-registered-target
+
+## Check that --filter works properly.
+# RUN: cp -f %S/Inputs/x86-filter.ll %t.ll && %update_analyze_test_checks --filter="(vf4|vf16)" %t.ll
+# RUN: diff -u %t.ll %S/Inputs/x86-filter.ll.filter.expected
+
+## Check that running the script again does not change the result:
+# RUN: %update_analyze_test_checks --filter="(vf4|vf16)" %t.ll
+# RUN: diff -u %t.ll %S/Inputs/x86-filter.ll.filter.expected
index c073f25..38a0fd1 100644 (file)
@@ -916,12 +916,12 @@ def add_ir_checks(output_lines, comment_marker, prefix_list, func_dict,
              check_label_format, False, preserve_names, global_vars_seen_dict,
              is_filtered)
 
-def add_analyze_checks(output_lines, comment_marker, prefix_list, func_dict, func_name):
+def add_analyze_checks(output_lines, comment_marker, prefix_list, func_dict, func_name, is_filtered):
   check_label_format = '{} %s-LABEL: \'%s%s\''.format(comment_marker)
   global_vars_seen_dict = {}
   add_checks(output_lines, comment_marker, prefix_list, func_dict, func_name,
              check_label_format, False, True, global_vars_seen_dict,
-             is_filtered = False)
+             is_filtered)
 
 def build_global_values_dictionary(glob_val_dict, raw_tool_output, prefixes):
   for nameless_value in nameless_values:
index cfb0632..15708e5 100755 (executable)
@@ -149,7 +149,8 @@ def main():
             continue
 
         # Print out the various check lines here.
-        common.add_analyze_checks(output_lines, ';', prefix_list, func_dict, func_name)
+        common.add_analyze_checks(output_lines, ';', prefix_list, func_dict, func_name,
+                                  is_filtered=builder.is_filtered())
         is_in_function_start = False
 
       if is_in_function: