[llvm] [update_mir_test_checks] Handle multiple defs of vreg (PR #66483)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 15 04:09:41 PDT 2023
https://github.com/jayfoad updated https://github.com/llvm/llvm-project/pull/66483
>From 1ebe65c71faa8d6651ac2423cec677d1c42b0776 Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Fri, 15 Sep 2023 10:35:01 +0100
Subject: [PATCH 1/2] [update_mir_test_checks] Precommit test for multiple defs
of vreg
XFAIL it until it is fixed by an upcoming commit.
---
.../Inputs/multiple-defs.mir | 12 ++++++++++++
.../Inputs/multiple-defs.mir.expected | 19 +++++++++++++++++++
.../update_mir_test_checks/multiple-defs.test | 7 +++++++
3 files changed, 38 insertions(+)
create mode 100644 llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/multiple-defs.mir
create mode 100644 llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/multiple-defs.mir.expected
create mode 100644 llvm/test/tools/UpdateTestChecks/update_mir_test_checks/multiple-defs.test
diff --git a/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/multiple-defs.mir b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/multiple-defs.mir
new file mode 100644
index 000000000000000..ff12ed7770beca0
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/multiple-defs.mir
@@ -0,0 +1,12 @@
+# RUN: llc -mtriple=x86_64 -run-pass=none -verify-machineinstrs %s -o - | FileCheck %s
+
+---
+name: test
+body: |
+ bb.0:
+ %0:gr32 = IMPLICIT_DEF
+ %1:gr32 = IMPLICIT_DEF
+ %0:gr32 = IMPLICIT_DEF
+ %2:gr32 = IMPLICIT_DEF
+ KILL %0, %2
+...
diff --git a/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/multiple-defs.mir.expected b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/multiple-defs.mir.expected
new file mode 100644
index 000000000000000..d2b05dd6b585bee
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/multiple-defs.mir.expected
@@ -0,0 +1,19 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+# RUN: llc -mtriple=x86_64 -run-pass=none -verify-machineinstrs %s -o - | FileCheck %s
+
+---
+name: test
+body: |
+ bb.0:
+ ; CHECK-LABEL: name: test
+ ; CHECK: [[DEF:%[0-9]+]]:gr32 = IMPLICIT_DEF
+ ; CHECK-NEXT: [[DEF1:%[0-9]+]]:gr32 = IMPLICIT_DEF
+ ; CHECK-NEXT: [[DEF2:%[0-9]+]]:gr32 = IMPLICIT_DEF
+ ; CHECK-NEXT: [[DEF2:%[0-9]+]]:gr32 = IMPLICIT_DEF
+ ; CHECK-NEXT: KILL [[DEF2]], [[DEF2]]
+ %0:gr32 = IMPLICIT_DEF
+ %1:gr32 = IMPLICIT_DEF
+ %0:gr32 = IMPLICIT_DEF
+ %2:gr32 = IMPLICIT_DEF
+ KILL %0, %2
+...
diff --git a/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/multiple-defs.test b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/multiple-defs.test
new file mode 100644
index 000000000000000..b6f329290c1ee20
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/multiple-defs.test
@@ -0,0 +1,7 @@
+## Check that update_mir_test_checks handles multiple definitions of the same
+## virtual register (after coming out of SSA form).
+
+# RUN: cp -f %S/Inputs/multiple-defs.mir %t.mir && %update_mir_test_checks %t.mir
+# RUN: diff -u %S/Inputs/multiple-defs.mir.expected %t.mir
+# RUN: FileCheck %t.mir < %t.mir
+# XFAIL: *
>From e02c70b75f63ab5d5270b484abe1d09792d8f6f1 Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Fri, 15 Sep 2023 10:36:52 +0100
Subject: [PATCH 2/2] [update_mir_test_checks] Handle multiple defs of vreg
When (post-SSA) MIR has multiple defs of the same vreg,
update_mir_test_checks would use different variable names for each def
like this, where DEF and DEF1 both refer to %0:
%0:gr32 = IMPLICIT_DEF
%0:gr32 = IMPLICIT_DEF
-->
; CHECK: [[DEF:%[0-9]+]]:gr32 = IMPLICIT_DEF
; CHECK-NEXT: [[DEF1:%[0-9]+]]:gr32 = IMPLICIT_DEF
This should be harmless, but it messed up the way that mangle_vreg
counts the number of names in vreg_map to come up with a new numeric
suffix, such that you could get the same variable name for different
vregs, like this, where DEF2 refers to both %0 and %2:
%0:gr32 = IMPLICIT_DEF
%1:gr32 = IMPLICIT_DEF
%0:gr32 = IMPLICIT_DEF
%2:gr32 = IMPLICIT_DEF
-->
; CHECK: [[DEF:%[0-9]+]]:gr32 = IMPLICIT_DEF
; CHECK-NEXT: [[DEF1:%[0-9]+]]:gr32 = IMPLICIT_DEF
; CHECK-NEXT: [[DEF2:%[0-9]+]]:gr32 = IMPLICIT_DEF
; CHECK-NEXT: [[DEF2:%[0-9]+]]:gr32 = IMPLICIT_DEF
Fix this by always using the same variable name for the same vreg.
---
.../Inputs/multiple-defs.mir.expected | 4 ++--
.../update_mir_test_checks/multiple-defs.test | 1 -
llvm/utils/update_mir_test_checks.py | 7 +++++--
3 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/multiple-defs.mir.expected b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/multiple-defs.mir.expected
index d2b05dd6b585bee..61428b94d459dba 100644
--- a/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/multiple-defs.mir.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/multiple-defs.mir.expected
@@ -8,9 +8,9 @@ body: |
; CHECK-LABEL: name: test
; CHECK: [[DEF:%[0-9]+]]:gr32 = IMPLICIT_DEF
; CHECK-NEXT: [[DEF1:%[0-9]+]]:gr32 = IMPLICIT_DEF
+ ; CHECK-NEXT: [[DEF:%[0-9]+]]:gr32 = IMPLICIT_DEF
; CHECK-NEXT: [[DEF2:%[0-9]+]]:gr32 = IMPLICIT_DEF
- ; CHECK-NEXT: [[DEF2:%[0-9]+]]:gr32 = IMPLICIT_DEF
- ; CHECK-NEXT: KILL [[DEF2]], [[DEF2]]
+ ; CHECK-NEXT: KILL [[DEF]], [[DEF2]]
%0:gr32 = IMPLICIT_DEF
%1:gr32 = IMPLICIT_DEF
%0:gr32 = IMPLICIT_DEF
diff --git a/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/multiple-defs.test b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/multiple-defs.test
index b6f329290c1ee20..f97c73ff3bf4a5b 100644
--- a/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/multiple-defs.test
+++ b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/multiple-defs.test
@@ -4,4 +4,3 @@
# RUN: cp -f %S/Inputs/multiple-defs.mir %t.mir && %update_mir_test_checks %t.mir
# RUN: diff -u %S/Inputs/multiple-defs.mir.expected %t.mir
# RUN: FileCheck %t.mir < %t.mir
-# XFAIL: *
diff --git a/llvm/utils/update_mir_test_checks.py b/llvm/utils/update_mir_test_checks.py
index 815738b23402310..8a539b5fb5ce4bc 100755
--- a/llvm/utils/update_mir_test_checks.py
+++ b/llvm/utils/update_mir_test_checks.py
@@ -204,8 +204,11 @@ def build_function_info_dictionary(
m = VREG_DEF_RE.match(func_line)
if m:
for vreg in VREG_RE.finditer(m.group("vregs")):
- name = mangle_vreg(m.group("opcode"), vreg_map.values())
- vreg_map[vreg.group(1)] = name
+ if vreg.group(1) in vreg_map:
+ name = vreg_map[vreg.group(1)]
+ else:
+ name = mangle_vreg(m.group("opcode"), vreg_map.values())
+ vreg_map[vreg.group(1)] = name
func_line = func_line.replace(
vreg.group(1), "[[{}:%[0-9]+]]".format(name), 1
)
More information about the llvm-commits
mailing list