[llvm] Add metadata pointer regex substitution to MIR update script (PR #163253)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 14 10:11:23 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: None (saxlungs)
<details>
<summary>Changes</summary>
LLC prints metadata operands as pointers in MIR, meaning tests can fail due to stale values with future changes. This PR makes it so the MIR test update script will substitute these pointers in the output with regex that generically capture any pointer, avoiding stale value test failures.
---
Full diff: https://github.com/llvm/llvm-project/pull/163253.diff
4 Files Affected:
- (added) llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/amdgpu-metadata-pointer.ll (+29)
- (added) llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/amdgpu-metadata-pointer.ll.expected (+36)
- (added) llvm/test/tools/UpdateTestChecks/update_mir_test_checks/amdgpu-metadata-pointer.test (+7)
- (modified) llvm/utils/update_mir_test_checks.py (+10)
``````````diff
diff --git a/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/amdgpu-metadata-pointer.ll b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/amdgpu-metadata-pointer.ll
new file mode 100644
index 0000000000000..3268f1bfdf30a
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/amdgpu-metadata-pointer.ll
@@ -0,0 +1,29 @@
+; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -global-isel -mtriple=amdgcn -mcpu=gfx900 -stop-after=irtranslator -o - %s | FileCheck %s
+
+define i32 @reloc_constant() {
+ ; CHECK-LABEL: name: reloc_constant
+ ; CHECK: bb.1 (%ir-block.0):
+ ; CHECK-NEXT: [[INT:%[0-9]+]]:_(s32) = G_INTRINSIC intrinsic(@llvm.amdgcn.reloc.constant), !0
+ ; CHECK-NEXT: [[INT1:%[0-9]+]]:_(s32) = G_INTRINSIC intrinsic(@llvm.amdgcn.reloc.constant), <0xc50ff1ce>
+ ; CHECK-NEXT: [[ADD:%[0-9]+]]:_(s32) = G_ADD [[INT]], [[INT1]]
+ ; CHECK-NEXT: $vgpr0 = COPY [[ADD]](s32)
+ ; CHECK-NEXT: SI_RETURN implicit $vgpr0
+ %val0 = call i32 @llvm.amdgcn.reloc.constant(metadata !0)
+ %val1 = call i32 @llvm.amdgcn.reloc.constant(metadata i32 4)
+ %res = add i32 %val0, %val1
+ ret i32 %res
+}
+
+define i32 @reloc_other_constant() {
+ %val0 = call i32 @llvm.amdgcn.reloc.constant(metadata !0)
+ %val1 = call i32 @llvm.amdgcn.reloc.constant(metadata i32 8)
+ %res = add i32 %val0, %val1
+ ret i32 %res
+}
+
+declare i32 @llvm.amdgcn.reloc.constant(metadata) #0
+
+attributes #0 = { nounwind readnone speculatable willreturn }
+
+!0 = !{!"arst"}
diff --git a/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/amdgpu-metadata-pointer.ll.expected b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/amdgpu-metadata-pointer.ll.expected
new file mode 100644
index 0000000000000..71bbe7cbb1d02
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/amdgpu-metadata-pointer.ll.expected
@@ -0,0 +1,36 @@
+; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -global-isel -mtriple=amdgcn -mcpu=gfx900 -stop-after=irtranslator -o - %s | FileCheck %s
+
+define i32 @reloc_constant() {
+ ; CHECK-LABEL: name: reloc_constant
+ ; CHECK: bb.1 (%ir-block.0):
+ ; CHECK-NEXT: [[INT:%[0-9]+]]:_(s32) = G_INTRINSIC intrinsic(@llvm.amdgcn.reloc.constant), !0
+ ; CHECK-NEXT: [[INT1:%[0-9]+]]:_(s32) = G_INTRINSIC intrinsic(@llvm.amdgcn.reloc.constant), <0x{{[0-9a-f]+}}>
+ ; CHECK-NEXT: [[ADD:%[0-9]+]]:_(s32) = G_ADD [[INT]], [[INT1]]
+ ; CHECK-NEXT: $vgpr0 = COPY [[ADD]](s32)
+ ; CHECK-NEXT: SI_RETURN implicit $vgpr0
+ %val0 = call i32 @llvm.amdgcn.reloc.constant(metadata !0)
+ %val1 = call i32 @llvm.amdgcn.reloc.constant(metadata i32 4)
+ %res = add i32 %val0, %val1
+ ret i32 %res
+}
+
+define i32 @reloc_other_constant() {
+ ; CHECK-LABEL: name: reloc_other_constant
+ ; CHECK: bb.1 (%ir-block.0):
+ ; CHECK-NEXT: [[INT:%[0-9]+]]:_(s32) = G_INTRINSIC intrinsic(@llvm.amdgcn.reloc.constant), !0
+ ; CHECK-NEXT: [[INT1:%[0-9]+]]:_(s32) = G_INTRINSIC intrinsic(@llvm.amdgcn.reloc.constant), <0x{{[0-9a-f]+}}>
+ ; CHECK-NEXT: [[ADD:%[0-9]+]]:_(s32) = G_ADD [[INT]], [[INT1]]
+ ; CHECK-NEXT: $vgpr0 = COPY [[ADD]](s32)
+ ; CHECK-NEXT: SI_RETURN implicit $vgpr0
+ %val0 = call i32 @llvm.amdgcn.reloc.constant(metadata !0)
+ %val1 = call i32 @llvm.amdgcn.reloc.constant(metadata i32 8)
+ %res = add i32 %val0, %val1
+ ret i32 %res
+}
+
+declare i32 @llvm.amdgcn.reloc.constant(metadata) #0
+
+attributes #0 = { nounwind readnone speculatable willreturn }
+
+!0 = !{!"arst"}
diff --git a/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/amdgpu-metadata-pointer.test b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/amdgpu-metadata-pointer.test
new file mode 100644
index 0000000000000..bcdbb6e384372
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/amdgpu-metadata-pointer.test
@@ -0,0 +1,7 @@
+# REQUIRES: amdgpu-registered-target
+## Check that update_mir_test_checks properly replaces metadata operand pointers
+## written out by LLC with a pointer-capturing regex, and also does not produce
+## new metadata operand pointers
+
+# RUN: cp -f %S/Inputs/amdgpu-metadata-pointer.ll %t.ll && %update_mir_test_checks %t.ll
+# RUN: diff -u %S/Inputs/amdgpu-metadata-pointer.ll.expected %t.ll
diff --git a/llvm/utils/update_mir_test_checks.py b/llvm/utils/update_mir_test_checks.py
index c4ee0523a6469..64fc4076b9371 100755
--- a/llvm/utils/update_mir_test_checks.py
+++ b/llvm/utils/update_mir_test_checks.py
@@ -65,6 +65,8 @@
flags=(re.M | re.S),
)
+MD_PTR_RE = re.compile(r"\<0x[a-f0-9]+\>", re.IGNORECASE)
+
class LLC:
def __init__(self, bin):
@@ -247,6 +249,14 @@ def update_test_file(args, test, autogenerated_note):
common.warn("No triple found: skipping file", test_file=test)
return
+ # Replace metadata pointer values inserted by LLC with generic regex
+ # capturing the pointer's format so that stale values don't break tests
+ no_pointer_output = ""
+ for line in raw_tool_output.splitlines():
+ line = MD_PTR_RE.sub("<0x{{[0-9a-f]+}}>", line)
+ no_pointer_output += line + "\n"
+ raw_tool_output = no_pointer_output
+
build_function_info_dictionary(
test,
raw_tool_output,
``````````
</details>
https://github.com/llvm/llvm-project/pull/163253
More information about the llvm-commits
mailing list