[llvm] [AMDGPU][test]added remove dup options (PR #111769)

Brox Chen via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 9 15:20:40 PDT 2024


https://github.com/broxigarchen updated https://github.com/llvm/llvm-project/pull/111769

>From ac8ee838a462bb992d0de0ec596b4f1c0ddc3bde Mon Sep 17 00:00:00 2001
From: guochen2 <guochen2 at amd.com>
Date: Wed, 9 Oct 2024 18:12:01 -0400
Subject: [PATCH] added remove dup options

---
 .../Inputs/amdgpu_asm_remove_duplicates.s     |  5 ++++
 .../amdgpu_asm_remove_duplicates.s.expected   |  5 ++++
 .../Inputs/amdgpu_dasm_remove_duplicates.txt  |  5 ++++
 ...amdgpu_dasm_remove_duplicates.txt.expected |  5 ++++
 .../amdgpu-remove-duplicates.test             |  7 +++++
 llvm/utils/update_mc_test_checks.py           | 27 ++++++++++++++-----
 6 files changed, 48 insertions(+), 6 deletions(-)
 create mode 100644 llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_remove_duplicates.s
 create mode 100644 llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_remove_duplicates.s.expected
 create mode 100644 llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_remove_duplicates.txt
 create mode 100644 llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_remove_duplicates.txt.expected
 create mode 100644 llvm/test/tools/UpdateTestChecks/update_mc_test_checks/amdgpu-remove-duplicates.test

diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_remove_duplicates.s b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_remove_duplicates.s
new file mode 100644
index 00000000000000..49f02cb5cb89c7
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_remove_duplicates.s
@@ -0,0 +1,5 @@
+// RUN: llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
+
+v_bfrev_b32 v5, v1
+
+v_bfrev_b32 v5, v1
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_remove_duplicates.s.expected b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_remove_duplicates.s.expected
new file mode 100644
index 00000000000000..7336947a3f57a0
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_remove_duplicates.s.expected
@@ -0,0 +1,5 @@
+; NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py
+// RUN: llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
+
+v_bfrev_b32 v5, v1
+// CHECK: v_bfrev_b32_e32 v5, v1                  ; encoding: [0x01,0x71,0x0a,0x7e]
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_remove_duplicates.txt b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_remove_duplicates.txt
new file mode 100644
index 00000000000000..3d0d49ddeea425
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_remove_duplicates.txt
@@ -0,0 +1,5 @@
+# RUN: llvm-mc -triple=amdgcn -mcpu=gfx1100 -disassemble -show-encoding %s 2>&1 | FileCheck -check-prefixes=CHECK %s
+
+0x00,0x00,0x00,0x7e
+
+0x00,0x00,0x00,0x7e
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_remove_duplicates.txt.expected b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_remove_duplicates.txt.expected
new file mode 100644
index 00000000000000..559b1649209531
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_remove_duplicates.txt.expected
@@ -0,0 +1,5 @@
+; NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py
+# RUN: llvm-mc -triple=amdgcn -mcpu=gfx1100 -disassemble -show-encoding %s 2>&1 | FileCheck -check-prefixes=CHECK %s
+
+0x00,0x00,0x00,0x7e
+# CHECK: v_nop                                   ; encoding: [0x00,0x00,0x00,0x7e]
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/amdgpu-remove-duplicates.test b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/amdgpu-remove-duplicates.test
new file mode 100644
index 00000000000000..df7d56a460f45e
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/amdgpu-remove-duplicates.test
@@ -0,0 +1,7 @@
+# REQUIRES: amdgpu-registered-target
+## Check that remove duplicate is working
+
+# RUN: cp -f %S/Inputs/amdgpu_asm_remove_duplicates.s %t.s && %update_mc_test_checks --remove-duplicate %t.s
+# RUN: diff -u %S/Inputs/amdgpu_asm_remove_duplicates.s.expected %t.s
+# RUN: cp -f %S/Inputs/amdgpu_dasm_remove_duplicates.txt %t.txt && %update_mc_test_checks --remove-duplicate %t.txt
+# RUN: diff -u %S/Inputs/amdgpu_dasm_remove_duplicates.txt.expected %t.txt
diff --git a/llvm/utils/update_mc_test_checks.py b/llvm/utils/update_mc_test_checks.py
index f9f8cfdea418d0..0e92fefaeeefd8 100755
--- a/llvm/utils/update_mc_test_checks.py
+++ b/llvm/utils/update_mc_test_checks.py
@@ -118,6 +118,12 @@ def main():
         default=None,
         help="Set a default -march for when neither triple nor arch are found in a RUN line",
     )
+
+    parser.add_argument(
+        "--remove-duplicate",
+        action=argparse.BooleanOptionalAction,
+        help="remove duplicated test line if found",
+    )
     parser.add_argument("tests", nargs="+")
     initial_args = common.parse_commandline_args(parser)
 
@@ -196,6 +202,10 @@ def main():
 
         # find all test line from input
         testlines = [l for l in ti.input_lines if isTestLine(l, mc_mode)]
+        # remove duplicated lines to save running time
+        testlines = list(dict.fromkeys(testlines))
+        common.debug("Valid test line found: ", len(testlines))
+
         run_list_size = len(run_list)
         testnum = len(testlines)
 
@@ -233,7 +243,7 @@ def main():
             raw_prefixes.append(prefixes)
 
         output_lines = []
-        generated_prefixes = []
+        generated_prefixes = {}
         used_prefixes = set()
         prefix_set = set([prefix for p in run_list for prefix in p[0]])
         common.debug("Rewriting FileCheck prefixes:", str(prefix_set))
@@ -298,16 +308,21 @@ def main():
                     else:
                         gen_prefix += getStdCheckLine(prefix, o, mc_mode)
 
-            generated_prefixes.append(gen_prefix.rstrip("\n"))
+            generated_prefixes[input_line] = gen_prefix.rstrip("\n")
 
         # write output
-        prefix_id = 0
+        written_lines = set()
         for input_info in ti.iterlines(output_lines):
             input_line = input_info.line
-            if isTestLine(input_line, mc_mode):
+            if input_line in testlines:
+                if ti.args.remove_duplicate:
+                    if input_line in written_lines:
+                        common.debug("Duplicated line skipped: ", input_line)
+                        continue
+                    else:
+                        written_lines.add(input_line)
                 output_lines.append(input_line)
-                output_lines.append(generated_prefixes[prefix_id])
-                prefix_id += 1
+                output_lines.append(generated_prefixes[input_line])
 
             elif should_add_line_to_output(input_line, prefix_set, mc_mode):
                 output_lines.append(input_line)



More information about the llvm-commits mailing list