[Mlir-commits] [mlir] [utils] Use stricter SSA regexp for CHECK-SAME. (PR #128083)

Slava Zakharin llvmlistbot at llvm.org
Thu Feb 20 17:13:00 PST 2025


https://github.com/vzakhari updated https://github.com/llvm/llvm-project/pull/128083

>From e3c767cb618176866da754f5a7901af0d149a7fb Mon Sep 17 00:00:00 2001
From: Slava Zakharin <szakharin at nvidia.com>
Date: Thu, 20 Feb 2025 14:49:19 -0800
Subject: [PATCH 1/3] [utils] Use stricter SSA regexp for CHECK-SAME.

When CHECK-SAME checks are split across multiple lines,
the '.*' regexp for the SSA variable name may cause problems, e.g.:
// CHECK_LABEL: func.func @whatever(
// CHECK-SAME: %[[VAL_0:.*]]: i32,
// CHECK-SAME: %[[VAL_1:.*]]: i32,
// CHECK-SAME: %[[VAL_2:.*]]: i64)

This will not work for `func.func @whatever(%0: i32, %1: i32, %2: i64)`,
because VAL_0 will match to `0: i32, %1`.
---
 mlir/utils/generate-test-checks.py | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/mlir/utils/generate-test-checks.py b/mlir/utils/generate-test-checks.py
index 8faa425beace1..80069737be97d 100755
--- a/mlir/utils/generate-test-checks.py
+++ b/mlir/utils/generate-test-checks.py
@@ -159,7 +159,7 @@ def get_num_ssa_results(input_line):
 
 
 # Process a line of input that has been split at each SSA identifier '%'.
-def process_line(line_chunks, variable_namer):
+def process_line(line_chunks, variable_namer, strict=False):
     output_line = ""
 
     # Process the rest that contained an SSA value name.
@@ -180,7 +180,14 @@ def process_line(line_chunks, variable_namer):
         else:
             # Otherwise, generate a new variable.
             variable = variable_namer.generate_name(ssa_name)
-            output_line += "%[[" + variable + ":.*]]"
+            if strict:
+                # Use stricter regexp for the variable name, if requested.
+                # Greedy matching may cause issues with the generic '.*'
+                # regexp when the checks are split across several
+                # lines (e.g. for CHECK-SAME).
+                output_line += "%[[" + variable + ":" + SSA_RE_STR + "]]"
+            else:
+                output_line += "%[[" + variable + ":.*]]"
 
         # Append the non named group.
         output_line += chunk[len(ssa_name) :]
@@ -390,7 +397,7 @@ def main():
                 output_line += " " * len(ssa_split[0])
 
                 # Process the rest of the line.
-                output_line += process_line([argument], variable_namer)
+                output_line += process_line([argument], variable_namer, strict=True)
 
         # Append the output line.
         output_segments[-1].append(output_line)

>From 37a80d40fd8a88a214999452495d7370aca8d29f Mon Sep 17 00:00:00 2001
From: Slava Zakharin <szakharin at nvidia.com>
Date: Thu, 20 Feb 2025 17:08:07 -0800
Subject: [PATCH 2/3] Changed var name.

---
 mlir/utils/generate-test-checks.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mlir/utils/generate-test-checks.py b/mlir/utils/generate-test-checks.py
index 80069737be97d..55a0ef56cde77 100755
--- a/mlir/utils/generate-test-checks.py
+++ b/mlir/utils/generate-test-checks.py
@@ -159,7 +159,7 @@ def get_num_ssa_results(input_line):
 
 
 # Process a line of input that has been split at each SSA identifier '%'.
-def process_line(line_chunks, variable_namer, strict=False):
+def process_line(line_chunks, variable_namer, strict_name_re=False):
     output_line = ""
 
     # Process the rest that contained an SSA value name.
@@ -180,7 +180,7 @@ def process_line(line_chunks, variable_namer, strict=False):
         else:
             # Otherwise, generate a new variable.
             variable = variable_namer.generate_name(ssa_name)
-            if strict:
+            if strict_name_re:
                 # Use stricter regexp for the variable name, if requested.
                 # Greedy matching may cause issues with the generic '.*'
                 # regexp when the checks are split across several
@@ -397,7 +397,7 @@ def main():
                 output_line += " " * len(ssa_split[0])
 
                 # Process the rest of the line.
-                output_line += process_line([argument], variable_namer, strict=True)
+                output_line += process_line([argument], variable_namer, strict_name_re=True)
 
         # Append the output line.
         output_segments[-1].append(output_line)

>From fbbea57b1995d0709088b31e6ca42df81f9df45b Mon Sep 17 00:00:00 2001
From: Slava Zakharin <szakharin at nvidia.com>
Date: Thu, 20 Feb 2025 17:12:46 -0800
Subject: [PATCH 3/3] format

---
 mlir/utils/generate-test-checks.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mlir/utils/generate-test-checks.py b/mlir/utils/generate-test-checks.py
index 55a0ef56cde77..749bfa13fe734 100755
--- a/mlir/utils/generate-test-checks.py
+++ b/mlir/utils/generate-test-checks.py
@@ -397,7 +397,9 @@ def main():
                 output_line += " " * len(ssa_split[0])
 
                 # Process the rest of the line.
-                output_line += process_line([argument], variable_namer, strict_name_re=True)
+                output_line += process_line(
+                    [argument], variable_namer, strict_name_re=True
+                )
 
         # Append the output line.
         output_segments[-1].append(output_line)



More information about the Mlir-commits mailing list