[llvm] [clang] Recommit changes to global checks (PR #71171)

Henrik G. Olsson via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 3 04:03:48 PDT 2023


https://github.com/hnrklssn created https://github.com/llvm/llvm-project/pull/71171

Recommits the changes from https://reviews.llvm.org/D148216.
Explicitly named globals are now matched literally, instead of emitting a capture group for the name. This resolves  #70047.
Metadata and annotations, on the other hand, are captured and matched against by default, since their identifiers are not stable.

The reasons for revert (#63746) have been fixed:
The first issue, that of duplicated checkers, has already been resolved in #70050.
This PR resolves the second issue listed in #63746, regarding the order of named and unnamed globals. This is fixed by recording the index of substrings containing global values, and sorting the checks according to that index before emitting them. This results in global value checks being emitted in the order they were seen instead of being grouped separately.



>From f4fc2a8df3fc0c5033c8d68303aea5e1824342fb Mon Sep 17 00:00:00 2001
From: "Henrik G. Olsson" <hnrklssn at gmail.com>
Date: Fri, 20 Oct 2023 17:38:48 +0200
Subject: [PATCH 1/6] Revert "Revert "[UTC] Add fallback support for specific
 metadata, and check their defs""

This reverts commit b9f1df7a04d7a3169623e437597aa4b32d99d8b3.
---
 .../Inputs/annotations.c                      |   6 +
 .../Inputs/annotations.c.expected             |  21 ++
 .../generated-funcs.c.generated.all.expected  | 259 +++++++++++++++
 .../generated-funcs.c.generated.expected      |   7 +-
 ...enerated-funcs.c.no-generated.all.expected | 130 ++++++++
 .../generated-funcs.c.no-generated.expected   |   7 +-
 .../update_cc_test_checks/annotations.test    |   4 +
 .../update_cc_test_checks/check-globals.test  |  14 +-
 .../generated-funcs.test                      |  16 +-
 ...erated_funcs.ll.generated.globals.expected |   2 +-
 ...ated_funcs.ll.nogenerated.globals.expected |   2 +-
 ...prefix_reuse.ll.generated.globals.expected |   2 +-
 ...efix_reuse.ll.nogenerated.globals.expected |   2 +-
 .../Inputs/global_regex.ll.expected           |   2 +-
 ...ious_ir_values.ll.funcsig.globals.expected | 116 +++----
 ...us_ir_values.ll.funcsig.noglobals.expected | 244 ++++++++++++++
 ...lues.ll.funcsig.transitiveglobals.expected | 305 ++++++++++++++++++
 .../update_test_checks/various_ir_values.test |   6 +
 llvm/utils/UpdateTestChecks/common.py         | 165 +++++++++-
 llvm/utils/update_cc_test_checks.py           |  20 +-
 llvm/utils/update_test_checks.py              |  12 +-
 21 files changed, 1244 insertions(+), 98 deletions(-)
 create mode 100644 clang/test/utils/update_cc_test_checks/Inputs/annotations.c
 create mode 100644 clang/test/utils/update_cc_test_checks/Inputs/annotations.c.expected
 create mode 100644 clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.all.expected
 create mode 100644 clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.no-generated.all.expected
 create mode 100644 clang/test/utils/update_cc_test_checks/annotations.test
 create mode 100644 llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.noglobals.expected
 create mode 100644 llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.transitiveglobals.expected

diff --git a/clang/test/utils/update_cc_test_checks/Inputs/annotations.c b/clang/test/utils/update_cc_test_checks/Inputs/annotations.c
new file mode 100644
index 000000000000000..f09b0f788e9b128
--- /dev/null
+++ b/clang/test/utils/update_cc_test_checks/Inputs/annotations.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fblocks -ftrivial-auto-var-init=zero %s -emit-llvm -o - | FileCheck %s
+
+int foo() {
+    int x = x + 1;
+    return x;
+}
diff --git a/clang/test/utils/update_cc_test_checks/Inputs/annotations.c.expected b/clang/test/utils/update_cc_test_checks/Inputs/annotations.c.expected
new file mode 100644
index 000000000000000..f368ca00dbc84b6
--- /dev/null
+++ b/clang/test/utils/update_cc_test_checks/Inputs/annotations.c.expected
@@ -0,0 +1,21 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fblocks -ftrivial-auto-var-init=zero %s -emit-llvm -o - | FileCheck %s
+
+// CHECK-LABEL: define dso_local i32 @foo(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[X:%.*]] = alloca i32, align 4
+// CHECK-NEXT:    store i32 0, ptr [[X]], align 4, !annotation [[META2:![0-9]+]]
+// CHECK-NEXT:    [[TMP0:%.*]] = load i32, ptr [[X]], align 4
+// CHECK-NEXT:    [[ADD:%.*]] = add nsw i32 [[TMP0]], 1
+// CHECK-NEXT:    store i32 [[ADD]], ptr [[X]], align 4
+// CHECK-NEXT:    [[TMP1:%.*]] = load i32, ptr [[X]], align 4
+// CHECK-NEXT:    ret i32 [[TMP1]]
+//
+int foo() {
+    int x = x + 1;
+    return x;
+}
+//.
+// CHECK: [[META2]] = !{!"auto-init"}
+//.
diff --git a/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.all.expected b/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.all.expected
new file mode 100644
index 000000000000000..66959811660d651
--- /dev/null
+++ b/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.all.expected
@@ -0,0 +1,259 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals --include-generated-funcs
+// Check that the CHECK lines are generated for clang-generated functions
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fopenmp %s -emit-llvm -o - | FileCheck --check-prefix=OMP %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu %s -emit-llvm -o - | FileCheck --check-prefix=NOOMP %s
+
+const int size = 1024 * 1024 * 32;
+
+double A[size];
+
+void foo(void);
+
+int main(void) {
+  int i = 0;
+
+#pragma omp parallel for
+  for (i = 0; i < size; ++i) {
+    A[i] = 0.0;
+  }
+
+  foo();
+
+  return 0;
+}
+
+void foo(void) {
+  int i = 0;
+
+#pragma omp parallel for
+  for (i = 0; i < size; ++i) {
+    A[i] = 1.0;
+  }
+}
+//.
+// OMP: @[[GLOB0:[0-9]+]] = private unnamed_addr constant [23 x i8] c"
+// OMP: @[[GLOB1:[0-9]+]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 514, i32 0, i32 22, ptr @[[GLOB0]] }, align 8
+// OMP: @[[GLOB2:[0-9]+]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 22, ptr @[[GLOB0]] }, align 8
+//.
+// OMP: @A = global [33554432 x double] zeroinitializer, align 16
+// OMP: @size = constant i32 33554432, align 4
+//.
+// NOOMP: @size = constant i32 33554432, align 4
+// NOOMP: @A = global [33554432 x double] zeroinitializer, align 16
+//.
+// OMP-LABEL: @main(
+// OMP-NEXT:  entry:
+// OMP-NEXT:    [[RETVAL:%.*]] = alloca i32, align 4
+// OMP-NEXT:    [[I:%.*]] = alloca i32, align 4
+// OMP-NEXT:    store i32 0, ptr [[RETVAL]], align 4
+// OMP-NEXT:    store i32 0, ptr [[I]], align 4
+// OMP-NEXT:    call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @[[GLOB2]], i32 0, ptr @main.omp_outlined)
+// OMP-NEXT:    call void @foo()
+// OMP-NEXT:    ret i32 0
+//
+//
+// OMP-LABEL: @main.omp_outlined(
+// OMP-NEXT:  entry:
+// OMP-NEXT:    [[DOTGLOBAL_TID__ADDR:%.*]] = alloca ptr, align 8
+// OMP-NEXT:    [[DOTBOUND_TID__ADDR:%.*]] = alloca ptr, align 8
+// OMP-NEXT:    [[DOTOMP_IV:%.*]] = alloca i32, align 4
+// OMP-NEXT:    [[TMP:%.*]] = alloca i32, align 4
+// OMP-NEXT:    [[DOTOMP_LB:%.*]] = alloca i32, align 4
+// OMP-NEXT:    [[DOTOMP_UB:%.*]] = alloca i32, align 4
+// OMP-NEXT:    [[DOTOMP_STRIDE:%.*]] = alloca i32, align 4
+// OMP-NEXT:    [[DOTOMP_IS_LAST:%.*]] = alloca i32, align 4
+// OMP-NEXT:    [[I:%.*]] = alloca i32, align 4
+// OMP-NEXT:    store ptr [[DOTGLOBAL_TID_:%.*]], ptr [[DOTGLOBAL_TID__ADDR]], align 8
+// OMP-NEXT:    store ptr [[DOTBOUND_TID_:%.*]], ptr [[DOTBOUND_TID__ADDR]], align 8
+// OMP-NEXT:    store i32 0, ptr [[DOTOMP_LB]], align 4
+// OMP-NEXT:    store i32 33554431, ptr [[DOTOMP_UB]], align 4
+// OMP-NEXT:    store i32 1, ptr [[DOTOMP_STRIDE]], align 4
+// OMP-NEXT:    store i32 0, ptr [[DOTOMP_IS_LAST]], align 4
+// OMP-NEXT:    [[TMP0:%.*]] = load ptr, ptr [[DOTGLOBAL_TID__ADDR]], align 8
+// OMP-NEXT:    [[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4
+// OMP-NEXT:    call void @__kmpc_for_static_init_4(ptr @[[GLOB1]], i32 [[TMP1]], i32 34, ptr [[DOTOMP_IS_LAST]], ptr [[DOTOMP_LB]], ptr [[DOTOMP_UB]], ptr [[DOTOMP_STRIDE]], i32 1, i32 1)
+// OMP-NEXT:    [[TMP2:%.*]] = load i32, ptr [[DOTOMP_UB]], align 4
+// OMP-NEXT:    [[CMP:%.*]] = icmp sgt i32 [[TMP2]], 33554431
+// OMP-NEXT:    br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]]
+// OMP:       cond.true:
+// OMP-NEXT:    br label [[COND_END:%.*]]
+// OMP:       cond.false:
+// OMP-NEXT:    [[TMP3:%.*]] = load i32, ptr [[DOTOMP_UB]], align 4
+// OMP-NEXT:    br label [[COND_END]]
+// OMP:       cond.end:
+// OMP-NEXT:    [[COND:%.*]] = phi i32 [ 33554431, [[COND_TRUE]] ], [ [[TMP3]], [[COND_FALSE]] ]
+// OMP-NEXT:    store i32 [[COND]], ptr [[DOTOMP_UB]], align 4
+// OMP-NEXT:    [[TMP4:%.*]] = load i32, ptr [[DOTOMP_LB]], align 4
+// OMP-NEXT:    store i32 [[TMP4]], ptr [[DOTOMP_IV]], align 4
+// OMP-NEXT:    br label [[OMP_INNER_FOR_COND:%.*]]
+// OMP:       omp.inner.for.cond:
+// OMP-NEXT:    [[TMP5:%.*]] = load i32, ptr [[DOTOMP_IV]], align 4
+// OMP-NEXT:    [[TMP6:%.*]] = load i32, ptr [[DOTOMP_UB]], align 4
+// OMP-NEXT:    [[CMP1:%.*]] = icmp sle i32 [[TMP5]], [[TMP6]]
+// OMP-NEXT:    br i1 [[CMP1]], label [[OMP_INNER_FOR_BODY:%.*]], label [[OMP_INNER_FOR_END:%.*]]
+// OMP:       omp.inner.for.body:
+// OMP-NEXT:    [[TMP7:%.*]] = load i32, ptr [[DOTOMP_IV]], align 4
+// OMP-NEXT:    [[MUL:%.*]] = mul nsw i32 [[TMP7]], 1
+// OMP-NEXT:    [[ADD:%.*]] = add nsw i32 0, [[MUL]]
+// OMP-NEXT:    store i32 [[ADD]], ptr [[I]], align 4
+// OMP-NEXT:    [[TMP8:%.*]] = load i32, ptr [[I]], align 4
+// OMP-NEXT:    [[IDXPROM:%.*]] = sext i32 [[TMP8]] to i64
+// OMP-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds [33554432 x double], ptr @A, i64 0, i64 [[IDXPROM]]
+// OMP-NEXT:    store double 0.000000e+00, ptr [[ARRAYIDX]], align 8
+// OMP-NEXT:    br label [[OMP_BODY_CONTINUE:%.*]]
+// OMP:       omp.body.continue:
+// OMP-NEXT:    br label [[OMP_INNER_FOR_INC:%.*]]
+// OMP:       omp.inner.for.inc:
+// OMP-NEXT:    [[TMP9:%.*]] = load i32, ptr [[DOTOMP_IV]], align 4
+// OMP-NEXT:    [[ADD2:%.*]] = add nsw i32 [[TMP9]], 1
+// OMP-NEXT:    store i32 [[ADD2]], ptr [[DOTOMP_IV]], align 4
+// OMP-NEXT:    br label [[OMP_INNER_FOR_COND]]
+// OMP:       omp.inner.for.end:
+// OMP-NEXT:    br label [[OMP_LOOP_EXIT:%.*]]
+// OMP:       omp.loop.exit:
+// OMP-NEXT:    call void @__kmpc_for_static_fini(ptr @[[GLOB1]], i32 [[TMP1]])
+// OMP-NEXT:    ret void
+//
+//
+// OMP-LABEL: @foo(
+// OMP-NEXT:  entry:
+// OMP-NEXT:    [[I:%.*]] = alloca i32, align 4
+// OMP-NEXT:    store i32 0, ptr [[I]], align 4
+// OMP-NEXT:    call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @[[GLOB2]], i32 0, ptr @foo.omp_outlined)
+// OMP-NEXT:    ret void
+//
+//
+// OMP-LABEL: @foo.omp_outlined(
+// OMP-NEXT:  entry:
+// OMP-NEXT:    [[DOTGLOBAL_TID__ADDR:%.*]] = alloca ptr, align 8
+// OMP-NEXT:    [[DOTBOUND_TID__ADDR:%.*]] = alloca ptr, align 8
+// OMP-NEXT:    [[DOTOMP_IV:%.*]] = alloca i32, align 4
+// OMP-NEXT:    [[TMP:%.*]] = alloca i32, align 4
+// OMP-NEXT:    [[DOTOMP_LB:%.*]] = alloca i32, align 4
+// OMP-NEXT:    [[DOTOMP_UB:%.*]] = alloca i32, align 4
+// OMP-NEXT:    [[DOTOMP_STRIDE:%.*]] = alloca i32, align 4
+// OMP-NEXT:    [[DOTOMP_IS_LAST:%.*]] = alloca i32, align 4
+// OMP-NEXT:    [[I:%.*]] = alloca i32, align 4
+// OMP-NEXT:    store ptr [[DOTGLOBAL_TID_:%.*]], ptr [[DOTGLOBAL_TID__ADDR]], align 8
+// OMP-NEXT:    store ptr [[DOTBOUND_TID_:%.*]], ptr [[DOTBOUND_TID__ADDR]], align 8
+// OMP-NEXT:    store i32 0, ptr [[DOTOMP_LB]], align 4
+// OMP-NEXT:    store i32 33554431, ptr [[DOTOMP_UB]], align 4
+// OMP-NEXT:    store i32 1, ptr [[DOTOMP_STRIDE]], align 4
+// OMP-NEXT:    store i32 0, ptr [[DOTOMP_IS_LAST]], align 4
+// OMP-NEXT:    [[TMP0:%.*]] = load ptr, ptr [[DOTGLOBAL_TID__ADDR]], align 8
+// OMP-NEXT:    [[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4
+// OMP-NEXT:    call void @__kmpc_for_static_init_4(ptr @[[GLOB1]], i32 [[TMP1]], i32 34, ptr [[DOTOMP_IS_LAST]], ptr [[DOTOMP_LB]], ptr [[DOTOMP_UB]], ptr [[DOTOMP_STRIDE]], i32 1, i32 1)
+// OMP-NEXT:    [[TMP2:%.*]] = load i32, ptr [[DOTOMP_UB]], align 4
+// OMP-NEXT:    [[CMP:%.*]] = icmp sgt i32 [[TMP2]], 33554431
+// OMP-NEXT:    br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]]
+// OMP:       cond.true:
+// OMP-NEXT:    br label [[COND_END:%.*]]
+// OMP:       cond.false:
+// OMP-NEXT:    [[TMP3:%.*]] = load i32, ptr [[DOTOMP_UB]], align 4
+// OMP-NEXT:    br label [[COND_END]]
+// OMP:       cond.end:
+// OMP-NEXT:    [[COND:%.*]] = phi i32 [ 33554431, [[COND_TRUE]] ], [ [[TMP3]], [[COND_FALSE]] ]
+// OMP-NEXT:    store i32 [[COND]], ptr [[DOTOMP_UB]], align 4
+// OMP-NEXT:    [[TMP4:%.*]] = load i32, ptr [[DOTOMP_LB]], align 4
+// OMP-NEXT:    store i32 [[TMP4]], ptr [[DOTOMP_IV]], align 4
+// OMP-NEXT:    br label [[OMP_INNER_FOR_COND:%.*]]
+// OMP:       omp.inner.for.cond:
+// OMP-NEXT:    [[TMP5:%.*]] = load i32, ptr [[DOTOMP_IV]], align 4
+// OMP-NEXT:    [[TMP6:%.*]] = load i32, ptr [[DOTOMP_UB]], align 4
+// OMP-NEXT:    [[CMP1:%.*]] = icmp sle i32 [[TMP5]], [[TMP6]]
+// OMP-NEXT:    br i1 [[CMP1]], label [[OMP_INNER_FOR_BODY:%.*]], label [[OMP_INNER_FOR_END:%.*]]
+// OMP:       omp.inner.for.body:
+// OMP-NEXT:    [[TMP7:%.*]] = load i32, ptr [[DOTOMP_IV]], align 4
+// OMP-NEXT:    [[MUL:%.*]] = mul nsw i32 [[TMP7]], 1
+// OMP-NEXT:    [[ADD:%.*]] = add nsw i32 0, [[MUL]]
+// OMP-NEXT:    store i32 [[ADD]], ptr [[I]], align 4
+// OMP-NEXT:    [[TMP8:%.*]] = load i32, ptr [[I]], align 4
+// OMP-NEXT:    [[IDXPROM:%.*]] = sext i32 [[TMP8]] to i64
+// OMP-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds [33554432 x double], ptr @A, i64 0, i64 [[IDXPROM]]
+// OMP-NEXT:    store double 1.000000e+00, ptr [[ARRAYIDX]], align 8
+// OMP-NEXT:    br label [[OMP_BODY_CONTINUE:%.*]]
+// OMP:       omp.body.continue:
+// OMP-NEXT:    br label [[OMP_INNER_FOR_INC:%.*]]
+// OMP:       omp.inner.for.inc:
+// OMP-NEXT:    [[TMP9:%.*]] = load i32, ptr [[DOTOMP_IV]], align 4
+// OMP-NEXT:    [[ADD2:%.*]] = add nsw i32 [[TMP9]], 1
+// OMP-NEXT:    store i32 [[ADD2]], ptr [[DOTOMP_IV]], align 4
+// OMP-NEXT:    br label [[OMP_INNER_FOR_COND]]
+// OMP:       omp.inner.for.end:
+// OMP-NEXT:    br label [[OMP_LOOP_EXIT:%.*]]
+// OMP:       omp.loop.exit:
+// OMP-NEXT:    call void @__kmpc_for_static_fini(ptr @[[GLOB1]], i32 [[TMP1]])
+// OMP-NEXT:    ret void
+//
+//
+// NOOMP-LABEL: @main(
+// NOOMP-NEXT:  entry:
+// NOOMP-NEXT:    [[RETVAL:%.*]] = alloca i32, align 4
+// NOOMP-NEXT:    [[I:%.*]] = alloca i32, align 4
+// NOOMP-NEXT:    store i32 0, ptr [[RETVAL]], align 4
+// NOOMP-NEXT:    store i32 0, ptr [[I]], align 4
+// NOOMP-NEXT:    store i32 0, ptr [[I]], align 4
+// NOOMP-NEXT:    br label [[FOR_COND:%.*]]
+// NOOMP:       for.cond:
+// NOOMP-NEXT:    [[TMP0:%.*]] = load i32, ptr [[I]], align 4
+// NOOMP-NEXT:    [[CMP:%.*]] = icmp slt i32 [[TMP0]], 33554432
+// NOOMP-NEXT:    br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
+// NOOMP:       for.body:
+// NOOMP-NEXT:    [[TMP1:%.*]] = load i32, ptr [[I]], align 4
+// NOOMP-NEXT:    [[IDXPROM:%.*]] = sext i32 [[TMP1]] to i64
+// NOOMP-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds [33554432 x double], ptr @A, i64 0, i64 [[IDXPROM]]
+// NOOMP-NEXT:    store double 0.000000e+00, ptr [[ARRAYIDX]], align 8
+// NOOMP-NEXT:    br label [[FOR_INC:%.*]]
+// NOOMP:       for.inc:
+// NOOMP-NEXT:    [[TMP2:%.*]] = load i32, ptr [[I]], align 4
+// NOOMP-NEXT:    [[INC:%.*]] = add nsw i32 [[TMP2]], 1
+// NOOMP-NEXT:    store i32 [[INC]], ptr [[I]], align 4
+// NOOMP-NEXT:    br label [[FOR_COND]], !llvm.loop [[LOOP2:![0-9]+]]
+// NOOMP:       for.end:
+// NOOMP-NEXT:    call void @foo()
+// NOOMP-NEXT:    ret i32 0
+//
+//
+// NOOMP-LABEL: @foo(
+// NOOMP-NEXT:  entry:
+// NOOMP-NEXT:    [[I:%.*]] = alloca i32, align 4
+// NOOMP-NEXT:    store i32 0, ptr [[I]], align 4
+// NOOMP-NEXT:    store i32 0, ptr [[I]], align 4
+// NOOMP-NEXT:    br label [[FOR_COND:%.*]]
+// NOOMP:       for.cond:
+// NOOMP-NEXT:    [[TMP0:%.*]] = load i32, ptr [[I]], align 4
+// NOOMP-NEXT:    [[CMP:%.*]] = icmp slt i32 [[TMP0]], 33554432
+// NOOMP-NEXT:    br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
+// NOOMP:       for.body:
+// NOOMP-NEXT:    [[TMP1:%.*]] = load i32, ptr [[I]], align 4
+// NOOMP-NEXT:    [[IDXPROM:%.*]] = sext i32 [[TMP1]] to i64
+// NOOMP-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds [33554432 x double], ptr @A, i64 0, i64 [[IDXPROM]]
+// NOOMP-NEXT:    store double 1.000000e+00, ptr [[ARRAYIDX]], align 8
+// NOOMP-NEXT:    br label [[FOR_INC:%.*]]
+// NOOMP:       for.inc:
+// NOOMP-NEXT:    [[TMP2:%.*]] = load i32, ptr [[I]], align 4
+// NOOMP-NEXT:    [[INC:%.*]] = add nsw i32 [[TMP2]], 1
+// NOOMP-NEXT:    store i32 [[INC]], ptr [[I]], align 4
+// NOOMP-NEXT:    br label [[FOR_COND]], !llvm.loop [[LOOP4:![0-9]+]]
+// NOOMP:       for.end:
+// NOOMP-NEXT:    ret void
+//
+//.
+// OMP: attributes #[[ATTR0:[0-9]+]] = { noinline nounwind optnone "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
+// OMP: attributes #[[ATTR1:[0-9]+]] = { noinline norecurse nounwind optnone "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
+// OMP: attributes #[[ATTR2:[0-9]+]] = { nounwind }
+//.
+// NOOMP: attributes #[[ATTR0:[0-9]+]] = { noinline nounwind optnone "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
+//.
+// OMP: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
+// OMP: [[META1:![0-9]+]] = !{i32 7, !"openmp", i32 51}
+// OMP: [[META2:![0-9]+]] = !{!"clang version {{.*}}"}
+// OMP: [[META3:![0-9]+]] = !{[[META4:![0-9]+]]}
+// OMP: [[META4]] = !{i64 2, i64 -1, i64 -1, i1 true}
+//.
+// NOOMP: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
+// NOOMP: [[META1:![0-9]+]] = !{!"clang version {{.*}}"}
+// NOOMP: [[LOOP2]] = distinct !{[[LOOP2]], [[META3:![0-9]+]]}
+// NOOMP: [[META3]] = !{!"llvm.loop.mustprogress"}
+// NOOMP: [[LOOP4]] = distinct !{[[LOOP4]], [[META3]]}
+//.
diff --git a/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.expected b/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.expected
index 2479cb6e6943265..896d4ede3c053ba 100644
--- a/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.expected
+++ b/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.expected
@@ -1,4 +1,4 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --include-generated-funcs
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals smart --include-generated-funcs
 // Check that the CHECK lines are generated for clang-generated functions
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fopenmp %s -emit-llvm -o - | FileCheck --check-prefix=OMP %s
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu %s -emit-llvm -o - | FileCheck --check-prefix=NOOMP %s
@@ -227,3 +227,8 @@ void foo(void) {
 // NOOMP:       for.end:
 // NOOMP-NEXT:    ret void
 //
+//.
+// NOOMP: [[LOOP2]] = distinct !{[[LOOP2]], [[META3:![0-9]+]]}
+// NOOMP: [[META3]] = !{!"llvm.loop.mustprogress"}
+// NOOMP: [[LOOP4]] = distinct !{[[LOOP4]], [[META3]]}
+//.
diff --git a/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.no-generated.all.expected b/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.no-generated.all.expected
new file mode 100644
index 000000000000000..219e5ceee6c7847
--- /dev/null
+++ b/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.no-generated.all.expected
@@ -0,0 +1,130 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals
+// Check that the CHECK lines are generated for clang-generated functions
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fopenmp %s -emit-llvm -o - | FileCheck --check-prefix=OMP %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu %s -emit-llvm -o - | FileCheck --check-prefix=NOOMP %s
+
+const int size = 1024 * 1024 * 32;
+
+double A[size];
+
+void foo(void);
+
+//.
+// OMP: @[[GLOB0:[0-9]+]] = private unnamed_addr constant [23 x i8] c"
+// OMP: @[[GLOB1:[0-9]+]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 514, i32 0, i32 22, ptr @[[GLOB0]] }, align 8
+// OMP: @[[GLOB2:[0-9]+]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 22, ptr @[[GLOB0]] }, align 8
+//.
+// OMP: @A = global [33554432 x double] zeroinitializer, align 16
+// OMP: @size = constant i32 33554432, align 4
+//.
+// NOOMP: @size = constant i32 33554432, align 4
+// NOOMP: @A = global [33554432 x double] zeroinitializer, align 16
+//.
+// OMP-LABEL: @main(
+// OMP-NEXT:  entry:
+// OMP-NEXT:    [[RETVAL:%.*]] = alloca i32, align 4
+// OMP-NEXT:    [[I:%.*]] = alloca i32, align 4
+// OMP-NEXT:    store i32 0, ptr [[RETVAL]], align 4
+// OMP-NEXT:    store i32 0, ptr [[I]], align 4
+// OMP-NEXT:    call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @[[GLOB2]], i32 0, ptr @main.omp_outlined)
+// OMP-NEXT:    call void @foo()
+// OMP-NEXT:    ret i32 0
+//
+// NOOMP-LABEL: @main(
+// NOOMP-NEXT:  entry:
+// NOOMP-NEXT:    [[RETVAL:%.*]] = alloca i32, align 4
+// NOOMP-NEXT:    [[I:%.*]] = alloca i32, align 4
+// NOOMP-NEXT:    store i32 0, ptr [[RETVAL]], align 4
+// NOOMP-NEXT:    store i32 0, ptr [[I]], align 4
+// NOOMP-NEXT:    store i32 0, ptr [[I]], align 4
+// NOOMP-NEXT:    br label [[FOR_COND:%.*]]
+// NOOMP:       for.cond:
+// NOOMP-NEXT:    [[TMP0:%.*]] = load i32, ptr [[I]], align 4
+// NOOMP-NEXT:    [[CMP:%.*]] = icmp slt i32 [[TMP0]], 33554432
+// NOOMP-NEXT:    br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
+// NOOMP:       for.body:
+// NOOMP-NEXT:    [[TMP1:%.*]] = load i32, ptr [[I]], align 4
+// NOOMP-NEXT:    [[IDXPROM:%.*]] = sext i32 [[TMP1]] to i64
+// NOOMP-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds [33554432 x double], ptr @A, i64 0, i64 [[IDXPROM]]
+// NOOMP-NEXT:    store double 0.000000e+00, ptr [[ARRAYIDX]], align 8
+// NOOMP-NEXT:    br label [[FOR_INC:%.*]]
+// NOOMP:       for.inc:
+// NOOMP-NEXT:    [[TMP2:%.*]] = load i32, ptr [[I]], align 4
+// NOOMP-NEXT:    [[INC:%.*]] = add nsw i32 [[TMP2]], 1
+// NOOMP-NEXT:    store i32 [[INC]], ptr [[I]], align 4
+// NOOMP-NEXT:    br label [[FOR_COND]], !llvm.loop [[LOOP2:![0-9]+]]
+// NOOMP:       for.end:
+// NOOMP-NEXT:    call void @foo()
+// NOOMP-NEXT:    ret i32 0
+//
+int main(void) {
+  int i = 0;
+
+#pragma omp parallel for
+  for (i = 0; i < size; ++i) {
+    A[i] = 0.0;
+  }
+
+  foo();
+
+  return 0;
+}
+
+// OMP-LABEL: @foo(
+// OMP-NEXT:  entry:
+// OMP-NEXT:    [[I:%.*]] = alloca i32, align 4
+// OMP-NEXT:    store i32 0, ptr [[I]], align 4
+// OMP-NEXT:    call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @[[GLOB2]], i32 0, ptr @foo.omp_outlined)
+// OMP-NEXT:    ret void
+//
+// NOOMP-LABEL: @foo(
+// NOOMP-NEXT:  entry:
+// NOOMP-NEXT:    [[I:%.*]] = alloca i32, align 4
+// NOOMP-NEXT:    store i32 0, ptr [[I]], align 4
+// NOOMP-NEXT:    store i32 0, ptr [[I]], align 4
+// NOOMP-NEXT:    br label [[FOR_COND:%.*]]
+// NOOMP:       for.cond:
+// NOOMP-NEXT:    [[TMP0:%.*]] = load i32, ptr [[I]], align 4
+// NOOMP-NEXT:    [[CMP:%.*]] = icmp slt i32 [[TMP0]], 33554432
+// NOOMP-NEXT:    br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
+// NOOMP:       for.body:
+// NOOMP-NEXT:    [[TMP1:%.*]] = load i32, ptr [[I]], align 4
+// NOOMP-NEXT:    [[IDXPROM:%.*]] = sext i32 [[TMP1]] to i64
+// NOOMP-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds [33554432 x double], ptr @A, i64 0, i64 [[IDXPROM]]
+// NOOMP-NEXT:    store double 1.000000e+00, ptr [[ARRAYIDX]], align 8
+// NOOMP-NEXT:    br label [[FOR_INC:%.*]]
+// NOOMP:       for.inc:
+// NOOMP-NEXT:    [[TMP2:%.*]] = load i32, ptr [[I]], align 4
+// NOOMP-NEXT:    [[INC:%.*]] = add nsw i32 [[TMP2]], 1
+// NOOMP-NEXT:    store i32 [[INC]], ptr [[I]], align 4
+// NOOMP-NEXT:    br label [[FOR_COND]], !llvm.loop [[LOOP4:![0-9]+]]
+// NOOMP:       for.end:
+// NOOMP-NEXT:    ret void
+//
+void foo(void) {
+  int i = 0;
+
+#pragma omp parallel for
+  for (i = 0; i < size; ++i) {
+    A[i] = 1.0;
+  }
+}
+//.
+// OMP: attributes #[[ATTR0:[0-9]+]] = { noinline nounwind optnone "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
+// OMP: attributes #[[ATTR1:[0-9]+]] = { noinline norecurse nounwind optnone "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
+// OMP: attributes #[[ATTR2:[0-9]+]] = { nounwind }
+//.
+// NOOMP: attributes #[[ATTR0:[0-9]+]] = { noinline nounwind optnone "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
+//.
+// OMP: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
+// OMP: [[META1:![0-9]+]] = !{i32 7, !"openmp", i32 51}
+// OMP: [[META2:![0-9]+]] = !{!"clang version {{.*}}"}
+// OMP: [[META3:![0-9]+]] = !{[[META4:![0-9]+]]}
+// OMP: [[META4]] = !{i64 2, i64 -1, i64 -1, i1 true}
+//.
+// NOOMP: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
+// NOOMP: [[META1:![0-9]+]] = !{!"clang version {{.*}}"}
+// NOOMP: [[LOOP2]] = distinct !{[[LOOP2]], [[META3:![0-9]+]]}
+// NOOMP: [[META3]] = !{!"llvm.loop.mustprogress"}
+// NOOMP: [[LOOP4]] = distinct !{[[LOOP4]], [[META3]]}
+//.
diff --git a/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.no-generated.expected b/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.no-generated.expected
index 7f5f1c10fcf4048..28c28e5c7a86cfe 100644
--- a/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.no-generated.expected
+++ b/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.no-generated.expected
@@ -1,4 +1,4 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals smart
 // Check that the CHECK lines are generated for clang-generated functions
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fopenmp %s -emit-llvm -o - | FileCheck --check-prefix=OMP %s
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu %s -emit-llvm -o - | FileCheck --check-prefix=NOOMP %s
@@ -98,3 +98,8 @@ void foo(void) {
     A[i] = 1.0;
   }
 }
+//.
+// NOOMP: [[LOOP2]] = distinct !{[[LOOP2]], [[META3:![0-9]+]]}
+// NOOMP: [[META3]] = !{!"llvm.loop.mustprogress"}
+// NOOMP: [[LOOP4]] = distinct !{[[LOOP4]], [[META3]]}
+//.
diff --git a/clang/test/utils/update_cc_test_checks/annotations.test b/clang/test/utils/update_cc_test_checks/annotations.test
new file mode 100644
index 000000000000000..1ef38e1746993d2
--- /dev/null
+++ b/clang/test/utils/update_cc_test_checks/annotations.test
@@ -0,0 +1,4 @@
+## Test that !annotation metadata is matched correctly
+
+# RUN: cp %S/Inputs/annotations.c %t.c && %update_cc_test_checks --version 3 %t.c
+# RUN: diff -u %S/Inputs/annotations.c.expected %t.c
diff --git a/clang/test/utils/update_cc_test_checks/check-globals.test b/clang/test/utils/update_cc_test_checks/check-globals.test
index 9a2e0cca4c4c830..5f527fa1223223c 100644
--- a/clang/test/utils/update_cc_test_checks/check-globals.test
+++ b/clang/test/utils/update_cc_test_checks/check-globals.test
@@ -1,26 +1,26 @@
 RUN: rm -rf %t && mkdir %t
 
-# Check --check-globals in normal mode and in --include-generated-funcs mode.
+# Check --check-globals all in normal mode and in --include-generated-funcs mode.
 
 RUN: cp %S/Inputs/check-globals.c %t/norm.c
-RUN: %update_cc_test_checks %t/norm.c --check-globals
+RUN: %update_cc_test_checks %t/norm.c --check-globals all
 RUN: FileCheck %s --input-file=%t/norm.c --match-full-lines -strict-whitespace \
 RUN:   -check-prefixes=BOTH,NRM
 
 RUN: cp %S/Inputs/check-globals.c %t/igf.c
-RUN: %update_cc_test_checks %t/igf.c --check-globals --include-generated-funcs
+RUN: %update_cc_test_checks %t/igf.c --check-globals all --include-generated-funcs
 RUN: FileCheck %s --input-file=%t/igf.c --match-full-lines -strict-whitespace \
 RUN:   -check-prefixes=BOTH,IGF
 
 # Check that repeating doesn't change it, such as duplicating '//.' occurrences.
 
 RUN: cp %t/norm.c %t/norm-again.c
-RUN: %update_cc_test_checks %t/norm-again.c --check-globals
+RUN: %update_cc_test_checks %t/norm-again.c --check-globals all
 RUN: diff -u %t/norm.c %t/norm-again.c
 RUN: rm %t/norm-again.c
 
 RUN: cp %t/igf.c %t/igf-again.c
-RUN: %update_cc_test_checks %t/igf-again.c --check-globals \
+RUN: %update_cc_test_checks %t/igf-again.c --check-globals all \
 RUN:     --include-generated-funcs
 RUN: diff -u %t/igf.c %t/igf-again.c
 RUN: rm %t/igf-again.c
@@ -74,8 +74,8 @@ BOTH-EMPTY:
  BOTH-NEXT://.
  BOTH-NEXT:// CHECK: attributes {{.*}}
  BOTH-NEXT://.
- BOTH-NEXT:// CHECK: !0 = {{.*}}
- BOTH-NEXT:// CHECK: !1 = {{.*}}
+ BOTH-NEXT:// CHECK: {{\[\[META0:!\[0-9\]\+\]\]}} = {{.*}}
+ BOTH-NEXT:// CHECK: {{\[\[META1:!\[0-9\]\+\]\]}} = {{.*}}
  BOTH-NEXT://.
   BOTH-NOT:{{.}}
 
diff --git a/clang/test/utils/update_cc_test_checks/generated-funcs.test b/clang/test/utils/update_cc_test_checks/generated-funcs.test
index 691969caf9fb6c4..ce06db5a417ec11 100644
--- a/clang/test/utils/update_cc_test_checks/generated-funcs.test
+++ b/clang/test/utils/update_cc_test_checks/generated-funcs.test
@@ -1,8 +1,8 @@
 ## Test that CHECK lines are generated for clang-generated functions
 
-# RUN: cp %S/Inputs/generated-funcs.c %t-generated.c && %update_cc_test_checks --include-generated-funcs %t-generated.c
+# RUN: cp %S/Inputs/generated-funcs.c %t-generated.c && %update_cc_test_checks --include-generated-funcs --check-globals smart %t-generated.c
 # RUN: diff -u %S/Inputs/generated-funcs.c.generated.expected %t-generated.c
-# RUN: cp %S/Inputs/generated-funcs.c %t-no-generated.c && %update_cc_test_checks %t-no-generated.c
+# RUN: cp %S/Inputs/generated-funcs.c %t-no-generated.c && %update_cc_test_checks --check-globals smart %t-no-generated.c
 # RUN: diff -u %S/Inputs/generated-funcs.c.no-generated.expected %t-no-generated.c
 
 ## Check that re-running update_cc_test_checks doesn't change the output
@@ -10,3 +10,15 @@
 # RUN: diff -u %S/Inputs/generated-funcs.c.generated.expected %t-generated.c
 # RUN: %update_cc_test_checks %t-no-generated.c
 # RUN: diff -u %S/Inputs/generated-funcs.c.no-generated.expected %t-no-generated.c
+
+## Same as above for --check-globals all
+# RUN: cp %S/Inputs/generated-funcs.c %t-generated.c && %update_cc_test_checks --include-generated-funcs --check-globals all %t-generated.c
+# RUN: diff -u %S/Inputs/generated-funcs.c.generated.all.expected %t-generated.c
+# RUN: cp %S/Inputs/generated-funcs.c %t-no-generated.c && %update_cc_test_checks --check-globals all %t-no-generated.c
+# RUN: diff -u %S/Inputs/generated-funcs.c.no-generated.all.expected %t-no-generated.c
+
+## Check that re-running update_cc_test_checks doesn't change the output
+# RUN: %update_cc_test_checks --include-generated-funcs %t-generated.c
+# RUN: diff -u %S/Inputs/generated-funcs.c.generated.all.expected %t-generated.c
+# RUN: %update_cc_test_checks %t-no-generated.c
+# RUN: diff -u %S/Inputs/generated-funcs.c.no-generated.all.expected %t-no-generated.c
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.generated.globals.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.generated.globals.expected
index 3b86c36fd39f5df..05e57774c260e86 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.generated.globals.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.generated.globals.expected
@@ -36,7 +36,7 @@ exit:
 declare void @llvm.trap() noreturn cold memory(inaccessiblemem: write)
 declare void @_Z10sideeffectv()
 ;.
-; CHECK: @[[G:[a-zA-Z0-9_$"\\.-]+]] = external dso_local global i32, align 4
+; CHECK: @G = external dso_local global i32, align 4
 ;.
 ; CHECK-LABEL: @foo(
 ; CHECK-NEXT:    [[TMP2:%.*]] = icmp eq i32 [[TMP0:%.*]], 0
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.globals.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.globals.expected
index 30e1a683aac98a5..db7c692a7def986 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.globals.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.globals.expected
@@ -6,7 +6,7 @@ target triple = "x86_64-apple-macosx10.14.0"
 @G = external dso_local global i32, align 4
 
 ;.
-; CHECK: @[[G:[a-zA-Z0-9_$"\\.-]+]] = external dso_local global i32, align 4
+; CHECK: @G = external dso_local global i32, align 4
 ;.
 define void @foo(i32) {
 ; CHECK-LABEL: @foo(
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.generated.globals.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.generated.globals.expected
index e6698db5fbee8da..0001790e66ab37d 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.generated.globals.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.generated.globals.expected
@@ -37,7 +37,7 @@ exit:
 declare void @llvm.trap() noreturn cold memory(inaccessiblemem: write)
 declare void @_Z10sideeffectv()
 ;.
-; REUSE: @[[G:[a-zA-Z0-9_$"\\.-]+]] = external dso_local global i32, align 4
+; REUSE: @G = external dso_local global i32, align 4
 ;.
 ; REUSE-LABEL: @foo(
 ; REUSE-NEXT:    [[TMP2:%.*]] = icmp eq i32 [[TMP0:%.*]], 0
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.nogenerated.globals.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.nogenerated.globals.expected
index 87f588d1de6400a..17be222f15c1258 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.nogenerated.globals.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.nogenerated.globals.expected
@@ -7,7 +7,7 @@ target triple = "x86_64-apple-macosx10.14.0"
 @G = external dso_local global i32, align 4
 
 ;.
-; REUSE: @[[G:[a-zA-Z0-9_$"\\.-]+]] = external dso_local global i32, align 4
+; REUSE: @G = external dso_local global i32, align 4
 ;.
 define void @foo(i32) {
 ; REUSE-LABEL: @foo(
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/global_regex.ll.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/global_regex.ll.expected
index 089b62f9ceccff6..5cd3746d4d68999 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/global_regex.ll.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/global_regex.ll.expected
@@ -6,7 +6,7 @@
 @Baz = global i32 2
 
 ;.
-; CHECK: @[[ONLYFOO:[a-zA-Z0-9_$"\\.-]+]] = global i32 1
+; CHECK: @OnlyFoo = global i32 1
 ;.
 define i32 @t() {
 ; CHECK-LABEL: @t(
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.globals.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.globals.expected
index d71dc3e34107183..a867c34090123d1 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.globals.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.globals.expected
@@ -250,67 +250,67 @@ attributes #3 = { nounwind }
 ; CHECK: attributes #[[ATTR2:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
 ; CHECK: attributes #[[ATTR3]] = { nounwind }
 ;.
-; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 11.0.0 (git at github.com:llvm/llvm-project.git 1d5da8cd30fce1c0a2c2fa6ba656dbfaa36192c8)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
-; CHECK: [[META1:![0-9]+]] = !DIFile(filename: "various_ir_values.c", directory: "/data/build/llvm-project")
-; CHECK: [[META2:![0-9]+]] = !{}
+; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C99, file: [[META1:![0-9]+]], producer: "clang version {{.*}}", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: [[META2:![0-9]+]], splitDebugInlining: false, nameTableKind: None)
+; CHECK: [[META1]] = !DIFile(filename: "various_ir_values.c", directory: {{.*}})
+; CHECK: [[META2]] = !{}
 ; CHECK: [[META3:![0-9]+]] = !{i32 7, !"Dwarf Version", i32 4}
 ; CHECK: [[META4:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3}
 ; CHECK: [[META5:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
-; CHECK: [[META6:![0-9]+]] = !{!"clang version 11.0.0 (git at github.com:llvm/llvm-project.git 1d5da8cd30fce1c0a2c2fa6ba656dbfaa36192c8)"}
-; CHECK: [[DBG7]] = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12)
-; CHECK: [[META8:![0-9]+]] = !DISubroutineType(types: !9)
-; CHECK: [[META9:![0-9]+]] = !{null, !10}
-; CHECK: [[META10:![0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
-; CHECK: [[META11:![0-9]+]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
-; CHECK: [[META12:![0-9]+]] = !{!13, !14}
-; CHECK: [[META13]] = !DILocalVariable(name: "A", arg: 1, scope: !7, file: !1, line: 1, type: !10)
-; CHECK: [[META14]] = !DILocalVariable(name: "i", scope: !15, file: !1, line: 3, type: !11)
-; CHECK: [[META15:![0-9]+]] = distinct !DILexicalBlock(scope: !7, file: !1, line: 3, column: 3)
+; CHECK: [[META6:![0-9]+]] = !{!"clang version {{.*}}"}
+; CHECK: [[DBG7]] = distinct !DISubprogram(name: "foo", scope: [[META1]], file: [[META1]], line: 1, type: [[META8:![0-9]+]], scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META12:![0-9]+]])
+; CHECK: [[META8]] = !DISubroutineType(types: [[META9:![0-9]+]])
+; CHECK: [[META9]] = !{null, [[META10:![0-9]+]]}
+; CHECK: [[META10]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META11:![0-9]+]], size: 64)
+; CHECK: [[META11]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+; CHECK: [[META12]] = !{[[META13]], [[META14]]}
+; CHECK: [[META13]] = !DILocalVariable(name: "A", arg: 1, scope: [[DBG7]], file: [[META1]], line: 1, type: [[META10]])
+; CHECK: [[META14]] = !DILocalVariable(name: "i", scope: [[META15:![0-9]+]], file: [[META1]], line: 3, type: [[META11]])
+; CHECK: [[META15]] = distinct !DILexicalBlock(scope: [[DBG7]], file: [[META1]], line: 3, column: 3)
 ; CHECK: [[DIASSIGNID16]] = distinct !DIAssignID()
-; CHECK: [[DBG17]] = !DILocation(line: 1, column: 15, scope: !7)
-; CHECK: [[TBAA18]] = !{!19, !19, i64 0}
-; CHECK: [[META19:![0-9]+]] = !{!"any pointer", !20, i64 0}
-; CHECK: [[META20:![0-9]+]] = !{!"omnipotent char", !21, i64 0}
-; CHECK: [[META21:![0-9]+]] = !{!"Simple C/C++ TBAA"}
-; CHECK: [[DBG22]] = !DILocation(line: 3, column: 8, scope: !15)
-; CHECK: [[DBG23]] = !DILocation(line: 3, column: 12, scope: !15)
-; CHECK: [[TBAA24]] = !{!25, !25, i64 0}
-; CHECK: [[META25:![0-9]+]] = !{!"int", !20, i64 0}
-; CHECK: [[DBG26]] = !DILocation(line: 3, column: 19, scope: !27)
-; CHECK: [[META27:![0-9]+]] = distinct !DILexicalBlock(scope: !15, file: !1, line: 3, column: 3)
-; CHECK: [[DBG28]] = !DILocation(line: 3, column: 24, scope: !27)
-; CHECK: [[DBG29]] = !DILocation(line: 3, column: 23, scope: !27)
-; CHECK: [[DBG30]] = !DILocation(line: 3, column: 21, scope: !27)
-; CHECK: [[DBG31]] = !DILocation(line: 3, column: 3, scope: !15)
+; CHECK: [[DBG17]] = !DILocation(line: 1, column: 15, scope: [[DBG7]])
+; CHECK: [[TBAA18]] = !{[[META19:![0-9]+]], [[META19]], i64 0}
+; CHECK: [[META19]] = !{!"any pointer", [[META20:![0-9]+]], i64 0}
+; CHECK: [[META20]] = !{!"omnipotent char", [[META21:![0-9]+]], i64 0}
+; CHECK: [[META21]] = !{!"Simple C/C++ TBAA"}
+; CHECK: [[DBG22]] = !DILocation(line: 3, column: 8, scope: [[META15]])
+; CHECK: [[DBG23]] = !DILocation(line: 3, column: 12, scope: [[META15]])
+; CHECK: [[TBAA24]] = !{[[META25:![0-9]+]], [[META25]], i64 0}
+; CHECK: [[META25]] = !{!"int", [[META20]], i64 0}
+; CHECK: [[DBG26]] = !DILocation(line: 3, column: 19, scope: [[META27:![0-9]+]])
+; CHECK: [[META27]] = distinct !DILexicalBlock(scope: [[META15]], file: [[META1]], line: 3, column: 3)
+; CHECK: [[DBG28]] = !DILocation(line: 3, column: 24, scope: [[META27]])
+; CHECK: [[DBG29]] = !DILocation(line: 3, column: 23, scope: [[META27]])
+; CHECK: [[DBG30]] = !DILocation(line: 3, column: 21, scope: [[META27]])
+; CHECK: [[DBG31]] = !DILocation(line: 3, column: 3, scope: [[META15]])
 ; CHECK: [[PROF32]] = !{!"branch_weights", i32 1, i32 1048575}
-; CHECK: [[DBG33]] = !DILocation(line: 3, column: 3, scope: !27)
-; CHECK: [[DBG34]] = !DILocation(line: 4, column: 5, scope: !27)
-; CHECK: [[DBG35]] = !DILocation(line: 4, column: 7, scope: !27)
-; CHECK: [[DBG36]] = !DILocation(line: 4, column: 10, scope: !27)
-; CHECK: [[DBG37]] = !DILocation(line: 3, column: 27, scope: !27)
-; CHECK: [[LOOP38]] = distinct !{!38, !31, !39}
-; CHECK: [[META39:![0-9]+]] = !DILocation(line: 4, column: 12, scope: !15)
-; CHECK: [[DBG40]] = !DILocation(line: 5, column: 1, scope: !7)
-; CHECK: [[DBG41]] = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 7, type: !8, scopeLine: 7, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !42)
-; CHECK: [[META42:![0-9]+]] = !{!43, !44}
-; CHECK: [[META43]] = !DILocalVariable(name: "A", arg: 1, scope: !41, file: !1, line: 7, type: !10)
-; CHECK: [[META44]] = !DILocalVariable(name: "i", scope: !45, file: !1, line: 9, type: !11)
-; CHECK: [[META45:![0-9]+]] = distinct !DILexicalBlock(scope: !41, file: !1, line: 9, column: 3)
-; CHECK: [[DBG46]] = !DILocation(line: 7, column: 15, scope: !41)
-; CHECK: [[DBG47]] = !DILocation(line: 9, column: 8, scope: !45)
-; CHECK: [[DBG48]] = !DILocation(line: 9, column: 12, scope: !45)
-; CHECK: [[DBG49]] = !DILocation(line: 9, column: 19, scope: !50)
-; CHECK: [[META50:![0-9]+]] = distinct !DILexicalBlock(scope: !45, file: !1, line: 9, column: 3)
-; CHECK: [[DBG51]] = !DILocation(line: 9, column: 24, scope: !50)
-; CHECK: [[DBG52]] = !DILocation(line: 9, column: 23, scope: !50)
-; CHECK: [[DBG53]] = !DILocation(line: 9, column: 21, scope: !50)
-; CHECK: [[DBG54]] = !DILocation(line: 9, column: 3, scope: !45)
-; CHECK: [[DBG55]] = !DILocation(line: 9, column: 3, scope: !50)
-; CHECK: [[DBG56]] = !DILocation(line: 10, column: 5, scope: !50)
-; CHECK: [[DBG57]] = !DILocation(line: 10, column: 7, scope: !50)
-; CHECK: [[DBG58]] = !DILocation(line: 10, column: 10, scope: !50)
-; CHECK: [[DBG59]] = !DILocation(line: 9, column: 27, scope: !50)
-; CHECK: [[LOOP60]] = distinct !{!60, !54, !61}
-; CHECK: [[META61:![0-9]+]] = !DILocation(line: 10, column: 12, scope: !45)
-; CHECK: [[DBG62]] = !DILocation(line: 11, column: 1, scope: !41)
+; CHECK: [[DBG33]] = !DILocation(line: 3, column: 3, scope: [[META27]])
+; CHECK: [[DBG34]] = !DILocation(line: 4, column: 5, scope: [[META27]])
+; CHECK: [[DBG35]] = !DILocation(line: 4, column: 7, scope: [[META27]])
+; CHECK: [[DBG36]] = !DILocation(line: 4, column: 10, scope: [[META27]])
+; CHECK: [[DBG37]] = !DILocation(line: 3, column: 27, scope: [[META27]])
+; CHECK: [[LOOP38]] = distinct !{[[LOOP38]], [[DBG31]], [[META39:![0-9]+]]}
+; CHECK: [[META39]] = !DILocation(line: 4, column: 12, scope: [[META15]])
+; CHECK: [[DBG40]] = !DILocation(line: 5, column: 1, scope: [[DBG7]])
+; CHECK: [[DBG41]] = distinct !DISubprogram(name: "bar", scope: [[META1]], file: [[META1]], line: 7, type: [[META8]], scopeLine: 7, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META42:![0-9]+]])
+; CHECK: [[META42]] = !{[[META43]], [[META44]]}
+; CHECK: [[META43]] = !DILocalVariable(name: "A", arg: 1, scope: [[DBG41]], file: [[META1]], line: 7, type: [[META10]])
+; CHECK: [[META44]] = !DILocalVariable(name: "i", scope: [[META45:![0-9]+]], file: [[META1]], line: 9, type: [[META11]])
+; CHECK: [[META45]] = distinct !DILexicalBlock(scope: [[DBG41]], file: [[META1]], line: 9, column: 3)
+; CHECK: [[DBG46]] = !DILocation(line: 7, column: 15, scope: [[DBG41]])
+; CHECK: [[DBG47]] = !DILocation(line: 9, column: 8, scope: [[META45]])
+; CHECK: [[DBG48]] = !DILocation(line: 9, column: 12, scope: [[META45]])
+; CHECK: [[DBG49]] = !DILocation(line: 9, column: 19, scope: [[META50:![0-9]+]])
+; CHECK: [[META50]] = distinct !DILexicalBlock(scope: [[META45]], file: [[META1]], line: 9, column: 3)
+; CHECK: [[DBG51]] = !DILocation(line: 9, column: 24, scope: [[META50]])
+; CHECK: [[DBG52]] = !DILocation(line: 9, column: 23, scope: [[META50]])
+; CHECK: [[DBG53]] = !DILocation(line: 9, column: 21, scope: [[META50]])
+; CHECK: [[DBG54]] = !DILocation(line: 9, column: 3, scope: [[META45]])
+; CHECK: [[DBG55]] = !DILocation(line: 9, column: 3, scope: [[META50]])
+; CHECK: [[DBG56]] = !DILocation(line: 10, column: 5, scope: [[META50]])
+; CHECK: [[DBG57]] = !DILocation(line: 10, column: 7, scope: [[META50]])
+; CHECK: [[DBG58]] = !DILocation(line: 10, column: 10, scope: [[META50]])
+; CHECK: [[DBG59]] = !DILocation(line: 9, column: 27, scope: [[META50]])
+; CHECK: [[LOOP60]] = distinct !{[[LOOP60]], [[DBG54]], [[META61:![0-9]+]]}
+; CHECK: [[META61]] = !DILocation(line: 10, column: 12, scope: [[META45]])
+; CHECK: [[DBG62]] = !DILocation(line: 11, column: 1, scope: [[DBG41]])
 ;.
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.noglobals.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.noglobals.expected
new file mode 100644
index 000000000000000..1ecb8b5dc533090
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.noglobals.expected
@@ -0,0 +1,244 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; Just run it through opt, no passes needed.
+; RUN: opt < %s -S | FileCheck %s
+
+; ModuleID = 'various_ir_values.c'
+source_filename = "various_ir_values.c"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; Function Attrs: nounwind uwtable
+define dso_local void @foo(ptr %A) #0 !dbg !7 {
+; CHECK-LABEL: @foo(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[A_ADDR:%.*]] = alloca ptr, align 8, !DIAssignID [[DIASSIGNID16:![0-9]+]]
+; CHECK-NEXT:    [[I:%.*]] = alloca i32, align 4
+; CHECK-NEXT:    call void @llvm.dbg.assign(metadata i1 undef, metadata [[META13:![0-9]+]], metadata !DIExpression(), metadata [[DIASSIGNID16]], metadata ptr [[A_ADDR]], metadata !DIExpression()), !dbg [[DBG17:![0-9]+]]
+; CHECK-NEXT:    store ptr [[A:%.*]], ptr [[A_ADDR]], align 8, !tbaa [[TBAA18:![0-9]+]]
+; CHECK-NEXT:    call void @llvm.dbg.declare(metadata ptr [[A_ADDR]], metadata [[META13]], metadata !DIExpression()), !dbg [[DBG17]]
+; CHECK-NEXT:    call void @llvm.lifetime.start.p0(i64 4, ptr [[I]]) #[[ATTR3:[0-9]+]], !dbg [[DBG22:![0-9]+]]
+; CHECK-NEXT:    call void @llvm.dbg.declare(metadata ptr [[I]], metadata [[META14:![0-9]+]], metadata !DIExpression()), !dbg [[DBG23:![0-9]+]]
+; CHECK-NEXT:    store i32 0, ptr [[I]], align 4, !dbg [[DBG23]], !tbaa [[TBAA24:![0-9]+]]
+; CHECK-NEXT:    br label [[FOR_COND:%.*]], !dbg [[DBG22]]
+; CHECK:       for.cond:
+; CHECK-NEXT:    [[TMP0:%.*]] = load i32, ptr [[I]], align 4, !dbg [[DBG26:![0-9]+]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    [[TMP1:%.*]] = load ptr, ptr [[A_ADDR]], align 8, !dbg [[DBG28:![0-9]+]], !tbaa [[TBAA18]]
+; CHECK-NEXT:    [[TMP2:%.*]] = load i32, ptr [[TMP1]], align 4, !dbg [[DBG29:![0-9]+]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[TMP0]], [[TMP2]], !dbg [[DBG30:![0-9]+]]
+; CHECK-NEXT:    br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_COND_CLEANUP:%.*]], !dbg [[DBG31:![0-9]+]], !prof [[PROF32:![0-9]+]]
+; CHECK:       for.cond.cleanup:
+; CHECK-NEXT:    call void @llvm.lifetime.end.p0(i64 4, ptr [[I]]) #[[ATTR3]], !dbg [[DBG33:![0-9]+]]
+; CHECK-NEXT:    br label [[FOR_END:%.*]]
+; CHECK:       for.body:
+; CHECK-NEXT:    [[TMP3:%.*]] = load ptr, ptr [[A_ADDR]], align 8, !dbg [[DBG34:![0-9]+]], !tbaa [[TBAA18]]
+; CHECK-NEXT:    [[TMP4:%.*]] = load i32, ptr [[I]], align 4, !dbg [[DBG35:![0-9]+]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    [[IDXPROM:%.*]] = sext i32 [[TMP4]] to i64, !dbg [[DBG34]]
+; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[TMP3]], i64 [[IDXPROM]], !dbg [[DBG34]]
+; CHECK-NEXT:    store i32 0, ptr [[ARRAYIDX]], align 4, !dbg [[DBG36:![0-9]+]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    br label [[FOR_INC:%.*]], !dbg [[DBG34]]
+; CHECK:       for.inc:
+; CHECK-NEXT:    [[TMP5:%.*]] = load i32, ptr [[I]], align 4, !dbg [[DBG37:![0-9]+]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    [[INC:%.*]] = add nsw i32 [[TMP5]], 1, !dbg [[DBG37]]
+; CHECK-NEXT:    store i32 [[INC]], ptr [[I]], align 4, !dbg [[DBG37]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    br label [[FOR_COND]], !dbg [[DBG33]], !llvm.loop [[LOOP38:![0-9]+]]
+; CHECK:       for.end:
+; CHECK-NEXT:    ret void, !dbg [[DBG40:![0-9]+]]
+;
+entry:
+  %A.addr = alloca ptr, align 8, !DIAssignID !62
+  %i = alloca i32, align 4
+  call void @llvm.dbg.assign(metadata i1 undef, metadata !13, metadata !DIExpression(), metadata !62, metadata ptr %A.addr, metadata !DIExpression()), !dbg !20
+  store ptr %A, ptr %A.addr, align 8, !tbaa !16
+  call void @llvm.dbg.declare(metadata ptr %A.addr, metadata !13, metadata !DIExpression()), !dbg !20
+  call void @llvm.lifetime.start.p0(i64 4, ptr %i) #3, !dbg !21
+  call void @llvm.dbg.declare(metadata ptr %i, metadata !14, metadata !DIExpression()), !dbg !22
+  store i32 0, ptr %i, align 4, !dbg !22, !tbaa !23
+  br label %for.cond, !dbg !21
+
+for.cond:                                         ; preds = %for.inc, %entry
+  %0 = load i32, ptr %i, align 4, !dbg !25, !tbaa !23
+  %1 = load ptr, ptr %A.addr, align 8, !dbg !27, !tbaa !16
+  %2 = load i32, ptr %1, align 4, !dbg !28, !tbaa !23
+  %cmp = icmp slt i32 %0, %2, !dbg !29
+  br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !30, !prof !61
+
+for.cond.cleanup:                                 ; preds = %for.cond
+  call void @llvm.lifetime.end.p0(i64 4, ptr %i) #3, !dbg !31
+  br label %for.end
+
+for.body:                                         ; preds = %for.cond
+  %3 = load ptr, ptr %A.addr, align 8, !dbg !32, !tbaa !16
+  %4 = load i32, ptr %i, align 4, !dbg !33, !tbaa !23
+  %idxprom = sext i32 %4 to i64, !dbg !32
+  %arrayidx = getelementptr inbounds i32, ptr %3, i64 %idxprom, !dbg !32
+  store i32 0, ptr %arrayidx, align 4, !dbg !34, !tbaa !23
+  br label %for.inc, !dbg !32
+
+for.inc:                                          ; preds = %for.body
+  %5 = load i32, ptr %i, align 4, !dbg !35, !tbaa !23
+  %inc = add nsw i32 %5, 1, !dbg !35
+  store i32 %inc, ptr %i, align 4, !dbg !35, !tbaa !23
+  br label %for.cond, !dbg !31, !llvm.loop !36
+
+for.end:                                          ; preds = %for.cond.cleanup
+  ret void, !dbg !38
+}
+
+; Function Attrs: nounwind readnone speculatable willreturn
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+; Function Attrs: argmemonly nounwind willreturn
+declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2
+
+; Function Attrs: argmemonly nounwind willreturn
+declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2
+
+; Function Attrs: nounwind uwtable
+define dso_local void @bar(ptr %A) #0 !dbg !39 {
+; CHECK-LABEL: @bar(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[A_ADDR:%.*]] = alloca ptr, align 8
+; CHECK-NEXT:    [[I:%.*]] = alloca i32, align 4
+; CHECK-NEXT:    store ptr [[A:%.*]], ptr [[A_ADDR]], align 8, !tbaa [[TBAA18]]
+; CHECK-NEXT:    call void @llvm.dbg.declare(metadata ptr [[A_ADDR]], metadata [[META43:![0-9]+]], metadata !DIExpression()), !dbg [[DBG46:![0-9]+]]
+; CHECK-NEXT:    call void @llvm.lifetime.start.p0(i64 4, ptr [[I]]) #[[ATTR3]], !dbg [[DBG47:![0-9]+]]
+; CHECK-NEXT:    call void @llvm.dbg.declare(metadata ptr [[I]], metadata [[META44:![0-9]+]], metadata !DIExpression()), !dbg [[DBG48:![0-9]+]]
+; CHECK-NEXT:    store i32 0, ptr [[I]], align 4, !dbg [[DBG48]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    br label [[FOR_COND:%.*]], !dbg [[DBG47]]
+; CHECK:       for.cond:
+; CHECK-NEXT:    [[TMP0:%.*]] = load i32, ptr [[I]], align 4, !dbg [[DBG49:![0-9]+]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    [[TMP1:%.*]] = load ptr, ptr [[A_ADDR]], align 8, !dbg [[DBG51:![0-9]+]], !tbaa [[TBAA18]]
+; CHECK-NEXT:    [[TMP2:%.*]] = load i32, ptr [[TMP1]], align 4, !dbg [[DBG52:![0-9]+]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[TMP0]], [[TMP2]], !dbg [[DBG53:![0-9]+]]
+; CHECK-NEXT:    br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_COND_CLEANUP:%.*]], !dbg [[DBG54:![0-9]+]]
+; CHECK:       for.cond.cleanup:
+; CHECK-NEXT:    call void @llvm.lifetime.end.p0(i64 4, ptr [[I]]) #[[ATTR3]], !dbg [[DBG55:![0-9]+]]
+; CHECK-NEXT:    br label [[FOR_END:%.*]]
+; CHECK:       for.body:
+; CHECK-NEXT:    [[TMP3:%.*]] = load ptr, ptr [[A_ADDR]], align 8, !dbg [[DBG56:![0-9]+]], !tbaa [[TBAA18]]
+; CHECK-NEXT:    [[TMP4:%.*]] = load i32, ptr [[I]], align 4, !dbg [[DBG57:![0-9]+]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    [[IDXPROM:%.*]] = sext i32 [[TMP4]] to i64, !dbg [[DBG56]]
+; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[TMP3]], i64 [[IDXPROM]], !dbg [[DBG56]]
+; CHECK-NEXT:    store i32 0, ptr [[ARRAYIDX]], align 4, !dbg [[DBG58:![0-9]+]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    br label [[FOR_INC:%.*]], !dbg [[DBG56]]
+; CHECK:       for.inc:
+; CHECK-NEXT:    [[TMP5:%.*]] = load i32, ptr [[I]], align 4, !dbg [[DBG59:![0-9]+]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    [[INC:%.*]] = add nsw i32 [[TMP5]], 1, !dbg [[DBG59]]
+; CHECK-NEXT:    store i32 [[INC]], ptr [[I]], align 4, !dbg [[DBG59]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    br label [[FOR_COND]], !dbg [[DBG55]], !llvm.loop [[LOOP60:![0-9]+]]
+; CHECK:       for.end:
+; CHECK-NEXT:    ret void, !dbg [[DBG62:![0-9]+]]
+;
+entry:
+  %A.addr = alloca ptr, align 8
+  %i = alloca i32, align 4
+  store ptr %A, ptr %A.addr, align 8, !tbaa !16
+  call void @llvm.dbg.declare(metadata ptr %A.addr, metadata !41, metadata !DIExpression()), !dbg !44
+  call void @llvm.lifetime.start.p0(i64 4, ptr %i) #3, !dbg !45
+  call void @llvm.dbg.declare(metadata ptr %i, metadata !42, metadata !DIExpression()), !dbg !46
+  store i32 0, ptr %i, align 4, !dbg !46, !tbaa !23
+  br label %for.cond, !dbg !45
+
+for.cond:                                         ; preds = %for.inc, %entry
+  %0 = load i32, ptr %i, align 4, !dbg !47, !tbaa !23
+  %1 = load ptr, ptr %A.addr, align 8, !dbg !49, !tbaa !16
+  %2 = load i32, ptr %1, align 4, !dbg !50, !tbaa !23
+  %cmp = icmp slt i32 %0, %2, !dbg !51
+  br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !52
+
+for.cond.cleanup:                                 ; preds = %for.cond
+  call void @llvm.lifetime.end.p0(i64 4, ptr %i) #3, !dbg !53
+  br label %for.end
+
+for.body:                                         ; preds = %for.cond
+  %3 = load ptr, ptr %A.addr, align 8, !dbg !54, !tbaa !16
+  %4 = load i32, ptr %i, align 4, !dbg !55, !tbaa !23
+  %idxprom = sext i32 %4 to i64, !dbg !54
+  %arrayidx = getelementptr inbounds i32, ptr %3, i64 %idxprom, !dbg !54
+  store i32 0, ptr %arrayidx, align 4, !dbg !56, !tbaa !23
+  br label %for.inc, !dbg !54
+
+for.inc:                                          ; preds = %for.body
+  %5 = load i32, ptr %i, align 4, !dbg !57, !tbaa !23
+  %inc = add nsw i32 %5, 1, !dbg !57
+  store i32 %inc, ptr %i, align 4, !dbg !57, !tbaa !23
+  br label %for.cond, !dbg !53, !llvm.loop !58
+
+for.end:                                          ; preds = %for.cond.cleanup
+  ret void, !dbg !60
+}
+
+declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)
+
+attributes #0 = { nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "denormal-fp-math"="ieee,ieee" "denormal-fp-math-f32"="ieee,ieee" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readnone speculatable willreturn }
+attributes #2 = { argmemonly nounwind willreturn }
+attributes #3 = { nounwind }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 11.0.0 (git at github.com:llvm/llvm-project.git 1d5da8cd30fce1c0a2c2fa6ba656dbfaa36192c8)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "various_ir_values.c", directory: "/data/build/llvm-project")
+!2 = !{}
+!3 = !{i32 7, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{!"clang version 11.0.0 (git at github.com:llvm/llvm-project.git 1d5da8cd30fce1c0a2c2fa6ba656dbfaa36192c8)"}
+!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12)
+!8 = !DISubroutineType(types: !9)
+!9 = !{null, !10}
+!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
+!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!12 = !{!13, !14}
+!13 = !DILocalVariable(name: "A", arg: 1, scope: !7, file: !1, line: 1, type: !10)
+!14 = !DILocalVariable(name: "i", scope: !15, file: !1, line: 3, type: !11)
+!15 = distinct !DILexicalBlock(scope: !7, file: !1, line: 3, column: 3)
+!16 = !{!17, !17, i64 0}
+!17 = !{!"any pointer", !18, i64 0}
+!18 = !{!"omnipotent char", !19, i64 0}
+!19 = !{!"Simple C/C++ TBAA"}
+!20 = !DILocation(line: 1, column: 15, scope: !7)
+!21 = !DILocation(line: 3, column: 8, scope: !15)
+!22 = !DILocation(line: 3, column: 12, scope: !15)
+!23 = !{!24, !24, i64 0}
+!24 = !{!"int", !18, i64 0}
+!25 = !DILocation(line: 3, column: 19, scope: !26)
+!26 = distinct !DILexicalBlock(scope: !15, file: !1, line: 3, column: 3)
+!27 = !DILocation(line: 3, column: 24, scope: !26)
+!28 = !DILocation(line: 3, column: 23, scope: !26)
+!29 = !DILocation(line: 3, column: 21, scope: !26)
+!30 = !DILocation(line: 3, column: 3, scope: !15)
+!31 = !DILocation(line: 3, column: 3, scope: !26)
+!32 = !DILocation(line: 4, column: 5, scope: !26)
+!33 = !DILocation(line: 4, column: 7, scope: !26)
+!34 = !DILocation(line: 4, column: 10, scope: !26)
+!35 = !DILocation(line: 3, column: 27, scope: !26)
+!36 = distinct !{!36, !30, !37}
+!37 = !DILocation(line: 4, column: 12, scope: !15)
+!38 = !DILocation(line: 5, column: 1, scope: !7)
+!39 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 7, type: !8, scopeLine: 7, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !40)
+!40 = !{!41, !42}
+!41 = !DILocalVariable(name: "A", arg: 1, scope: !39, file: !1, line: 7, type: !10)
+!42 = !DILocalVariable(name: "i", scope: !43, file: !1, line: 9, type: !11)
+!43 = distinct !DILexicalBlock(scope: !39, file: !1, line: 9, column: 3)
+!44 = !DILocation(line: 7, column: 15, scope: !39)
+!45 = !DILocation(line: 9, column: 8, scope: !43)
+!46 = !DILocation(line: 9, column: 12, scope: !43)
+!47 = !DILocation(line: 9, column: 19, scope: !48)
+!48 = distinct !DILexicalBlock(scope: !43, file: !1, line: 9, column: 3)
+!49 = !DILocation(line: 9, column: 24, scope: !48)
+!50 = !DILocation(line: 9, column: 23, scope: !48)
+!51 = !DILocation(line: 9, column: 21, scope: !48)
+!52 = !DILocation(line: 9, column: 3, scope: !43)
+!53 = !DILocation(line: 9, column: 3, scope: !48)
+!54 = !DILocation(line: 10, column: 5, scope: !48)
+!55 = !DILocation(line: 10, column: 7, scope: !48)
+!56 = !DILocation(line: 10, column: 10, scope: !48)
+!57 = !DILocation(line: 9, column: 27, scope: !48)
+!58 = distinct !{!58, !52, !59}
+!59 = !DILocation(line: 10, column: 12, scope: !43)
+!60 = !DILocation(line: 11, column: 1, scope: !39)
+!61 = !{!"branch_weights", i32 1, i32 1048575}
+!62 = distinct !DIAssignID()
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.transitiveglobals.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.transitiveglobals.expected
new file mode 100644
index 000000000000000..debe0911d91120e
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.transitiveglobals.expected
@@ -0,0 +1,305 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals smart
+; Just run it through opt, no passes needed.
+; RUN: opt < %s -S | FileCheck %s
+
+; ModuleID = 'various_ir_values.c'
+source_filename = "various_ir_values.c"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; Function Attrs: nounwind uwtable
+define dso_local void @foo(ptr %A) #0 !dbg !7 {
+; CHECK-LABEL: @foo(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[A_ADDR:%.*]] = alloca ptr, align 8, !DIAssignID [[DIASSIGNID16:![0-9]+]]
+; CHECK-NEXT:    [[I:%.*]] = alloca i32, align 4
+; CHECK-NEXT:    call void @llvm.dbg.assign(metadata i1 undef, metadata [[META13:![0-9]+]], metadata !DIExpression(), metadata [[DIASSIGNID16]], metadata ptr [[A_ADDR]], metadata !DIExpression()), !dbg [[DBG17:![0-9]+]]
+; CHECK-NEXT:    store ptr [[A:%.*]], ptr [[A_ADDR]], align 8, !tbaa [[TBAA18:![0-9]+]]
+; CHECK-NEXT:    call void @llvm.dbg.declare(metadata ptr [[A_ADDR]], metadata [[META13]], metadata !DIExpression()), !dbg [[DBG17]]
+; CHECK-NEXT:    call void @llvm.lifetime.start.p0(i64 4, ptr [[I]]) #[[ATTR3:[0-9]+]], !dbg [[DBG22:![0-9]+]]
+; CHECK-NEXT:    call void @llvm.dbg.declare(metadata ptr [[I]], metadata [[META14:![0-9]+]], metadata !DIExpression()), !dbg [[DBG23:![0-9]+]]
+; CHECK-NEXT:    store i32 0, ptr [[I]], align 4, !dbg [[DBG23]], !tbaa [[TBAA24:![0-9]+]]
+; CHECK-NEXT:    br label [[FOR_COND:%.*]], !dbg [[DBG22]]
+; CHECK:       for.cond:
+; CHECK-NEXT:    [[TMP0:%.*]] = load i32, ptr [[I]], align 4, !dbg [[DBG26:![0-9]+]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    [[TMP1:%.*]] = load ptr, ptr [[A_ADDR]], align 8, !dbg [[DBG28:![0-9]+]], !tbaa [[TBAA18]]
+; CHECK-NEXT:    [[TMP2:%.*]] = load i32, ptr [[TMP1]], align 4, !dbg [[DBG29:![0-9]+]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[TMP0]], [[TMP2]], !dbg [[DBG30:![0-9]+]]
+; CHECK-NEXT:    br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_COND_CLEANUP:%.*]], !dbg [[DBG31:![0-9]+]], !prof [[PROF32:![0-9]+]]
+; CHECK:       for.cond.cleanup:
+; CHECK-NEXT:    call void @llvm.lifetime.end.p0(i64 4, ptr [[I]]) #[[ATTR3]], !dbg [[DBG33:![0-9]+]]
+; CHECK-NEXT:    br label [[FOR_END:%.*]]
+; CHECK:       for.body:
+; CHECK-NEXT:    [[TMP3:%.*]] = load ptr, ptr [[A_ADDR]], align 8, !dbg [[DBG34:![0-9]+]], !tbaa [[TBAA18]]
+; CHECK-NEXT:    [[TMP4:%.*]] = load i32, ptr [[I]], align 4, !dbg [[DBG35:![0-9]+]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    [[IDXPROM:%.*]] = sext i32 [[TMP4]] to i64, !dbg [[DBG34]]
+; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[TMP3]], i64 [[IDXPROM]], !dbg [[DBG34]]
+; CHECK-NEXT:    store i32 0, ptr [[ARRAYIDX]], align 4, !dbg [[DBG36:![0-9]+]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    br label [[FOR_INC:%.*]], !dbg [[DBG34]]
+; CHECK:       for.inc:
+; CHECK-NEXT:    [[TMP5:%.*]] = load i32, ptr [[I]], align 4, !dbg [[DBG37:![0-9]+]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    [[INC:%.*]] = add nsw i32 [[TMP5]], 1, !dbg [[DBG37]]
+; CHECK-NEXT:    store i32 [[INC]], ptr [[I]], align 4, !dbg [[DBG37]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    br label [[FOR_COND]], !dbg [[DBG33]], !llvm.loop [[LOOP38:![0-9]+]]
+; CHECK:       for.end:
+; CHECK-NEXT:    ret void, !dbg [[DBG40:![0-9]+]]
+;
+entry:
+  %A.addr = alloca ptr, align 8, !DIAssignID !62
+  %i = alloca i32, align 4
+  call void @llvm.dbg.assign(metadata i1 undef, metadata !13, metadata !DIExpression(), metadata !62, metadata ptr %A.addr, metadata !DIExpression()), !dbg !20
+  store ptr %A, ptr %A.addr, align 8, !tbaa !16
+  call void @llvm.dbg.declare(metadata ptr %A.addr, metadata !13, metadata !DIExpression()), !dbg !20
+  call void @llvm.lifetime.start.p0(i64 4, ptr %i) #3, !dbg !21
+  call void @llvm.dbg.declare(metadata ptr %i, metadata !14, metadata !DIExpression()), !dbg !22
+  store i32 0, ptr %i, align 4, !dbg !22, !tbaa !23
+  br label %for.cond, !dbg !21
+
+for.cond:                                         ; preds = %for.inc, %entry
+  %0 = load i32, ptr %i, align 4, !dbg !25, !tbaa !23
+  %1 = load ptr, ptr %A.addr, align 8, !dbg !27, !tbaa !16
+  %2 = load i32, ptr %1, align 4, !dbg !28, !tbaa !23
+  %cmp = icmp slt i32 %0, %2, !dbg !29
+  br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !30, !prof !61
+
+for.cond.cleanup:                                 ; preds = %for.cond
+  call void @llvm.lifetime.end.p0(i64 4, ptr %i) #3, !dbg !31
+  br label %for.end
+
+for.body:                                         ; preds = %for.cond
+  %3 = load ptr, ptr %A.addr, align 8, !dbg !32, !tbaa !16
+  %4 = load i32, ptr %i, align 4, !dbg !33, !tbaa !23
+  %idxprom = sext i32 %4 to i64, !dbg !32
+  %arrayidx = getelementptr inbounds i32, ptr %3, i64 %idxprom, !dbg !32
+  store i32 0, ptr %arrayidx, align 4, !dbg !34, !tbaa !23
+  br label %for.inc, !dbg !32
+
+for.inc:                                          ; preds = %for.body
+  %5 = load i32, ptr %i, align 4, !dbg !35, !tbaa !23
+  %inc = add nsw i32 %5, 1, !dbg !35
+  store i32 %inc, ptr %i, align 4, !dbg !35, !tbaa !23
+  br label %for.cond, !dbg !31, !llvm.loop !36
+
+for.end:                                          ; preds = %for.cond.cleanup
+  ret void, !dbg !38
+}
+
+; Function Attrs: nounwind readnone speculatable willreturn
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+; Function Attrs: argmemonly nounwind willreturn
+declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2
+
+; Function Attrs: argmemonly nounwind willreturn
+declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2
+
+; Function Attrs: nounwind uwtable
+define dso_local void @bar(ptr %A) #0 !dbg !39 {
+; CHECK-LABEL: @bar(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[A_ADDR:%.*]] = alloca ptr, align 8
+; CHECK-NEXT:    [[I:%.*]] = alloca i32, align 4
+; CHECK-NEXT:    store ptr [[A:%.*]], ptr [[A_ADDR]], align 8, !tbaa [[TBAA18]]
+; CHECK-NEXT:    call void @llvm.dbg.declare(metadata ptr [[A_ADDR]], metadata [[META43:![0-9]+]], metadata !DIExpression()), !dbg [[DBG46:![0-9]+]]
+; CHECK-NEXT:    call void @llvm.lifetime.start.p0(i64 4, ptr [[I]]) #[[ATTR3]], !dbg [[DBG47:![0-9]+]]
+; CHECK-NEXT:    call void @llvm.dbg.declare(metadata ptr [[I]], metadata [[META44:![0-9]+]], metadata !DIExpression()), !dbg [[DBG48:![0-9]+]]
+; CHECK-NEXT:    store i32 0, ptr [[I]], align 4, !dbg [[DBG48]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    br label [[FOR_COND:%.*]], !dbg [[DBG47]]
+; CHECK:       for.cond:
+; CHECK-NEXT:    [[TMP0:%.*]] = load i32, ptr [[I]], align 4, !dbg [[DBG49:![0-9]+]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    [[TMP1:%.*]] = load ptr, ptr [[A_ADDR]], align 8, !dbg [[DBG51:![0-9]+]], !tbaa [[TBAA18]]
+; CHECK-NEXT:    [[TMP2:%.*]] = load i32, ptr [[TMP1]], align 4, !dbg [[DBG52:![0-9]+]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[TMP0]], [[TMP2]], !dbg [[DBG53:![0-9]+]]
+; CHECK-NEXT:    br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_COND_CLEANUP:%.*]], !dbg [[DBG54:![0-9]+]]
+; CHECK:       for.cond.cleanup:
+; CHECK-NEXT:    call void @llvm.lifetime.end.p0(i64 4, ptr [[I]]) #[[ATTR3]], !dbg [[DBG55:![0-9]+]]
+; CHECK-NEXT:    br label [[FOR_END:%.*]]
+; CHECK:       for.body:
+; CHECK-NEXT:    [[TMP3:%.*]] = load ptr, ptr [[A_ADDR]], align 8, !dbg [[DBG56:![0-9]+]], !tbaa [[TBAA18]]
+; CHECK-NEXT:    [[TMP4:%.*]] = load i32, ptr [[I]], align 4, !dbg [[DBG57:![0-9]+]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    [[IDXPROM:%.*]] = sext i32 [[TMP4]] to i64, !dbg [[DBG56]]
+; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[TMP3]], i64 [[IDXPROM]], !dbg [[DBG56]]
+; CHECK-NEXT:    store i32 0, ptr [[ARRAYIDX]], align 4, !dbg [[DBG58:![0-9]+]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    br label [[FOR_INC:%.*]], !dbg [[DBG56]]
+; CHECK:       for.inc:
+; CHECK-NEXT:    [[TMP5:%.*]] = load i32, ptr [[I]], align 4, !dbg [[DBG59:![0-9]+]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    [[INC:%.*]] = add nsw i32 [[TMP5]], 1, !dbg [[DBG59]]
+; CHECK-NEXT:    store i32 [[INC]], ptr [[I]], align 4, !dbg [[DBG59]], !tbaa [[TBAA24]]
+; CHECK-NEXT:    br label [[FOR_COND]], !dbg [[DBG55]], !llvm.loop [[LOOP60:![0-9]+]]
+; CHECK:       for.end:
+; CHECK-NEXT:    ret void, !dbg [[DBG62:![0-9]+]]
+;
+entry:
+  %A.addr = alloca ptr, align 8
+  %i = alloca i32, align 4
+  store ptr %A, ptr %A.addr, align 8, !tbaa !16
+  call void @llvm.dbg.declare(metadata ptr %A.addr, metadata !41, metadata !DIExpression()), !dbg !44
+  call void @llvm.lifetime.start.p0(i64 4, ptr %i) #3, !dbg !45
+  call void @llvm.dbg.declare(metadata ptr %i, metadata !42, metadata !DIExpression()), !dbg !46
+  store i32 0, ptr %i, align 4, !dbg !46, !tbaa !23
+  br label %for.cond, !dbg !45
+
+for.cond:                                         ; preds = %for.inc, %entry
+  %0 = load i32, ptr %i, align 4, !dbg !47, !tbaa !23
+  %1 = load ptr, ptr %A.addr, align 8, !dbg !49, !tbaa !16
+  %2 = load i32, ptr %1, align 4, !dbg !50, !tbaa !23
+  %cmp = icmp slt i32 %0, %2, !dbg !51
+  br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !52
+
+for.cond.cleanup:                                 ; preds = %for.cond
+  call void @llvm.lifetime.end.p0(i64 4, ptr %i) #3, !dbg !53
+  br label %for.end
+
+for.body:                                         ; preds = %for.cond
+  %3 = load ptr, ptr %A.addr, align 8, !dbg !54, !tbaa !16
+  %4 = load i32, ptr %i, align 4, !dbg !55, !tbaa !23
+  %idxprom = sext i32 %4 to i64, !dbg !54
+  %arrayidx = getelementptr inbounds i32, ptr %3, i64 %idxprom, !dbg !54
+  store i32 0, ptr %arrayidx, align 4, !dbg !56, !tbaa !23
+  br label %for.inc, !dbg !54
+
+for.inc:                                          ; preds = %for.body
+  %5 = load i32, ptr %i, align 4, !dbg !57, !tbaa !23
+  %inc = add nsw i32 %5, 1, !dbg !57
+  store i32 %inc, ptr %i, align 4, !dbg !57, !tbaa !23
+  br label %for.cond, !dbg !53, !llvm.loop !58
+
+for.end:                                          ; preds = %for.cond.cleanup
+  ret void, !dbg !60
+}
+
+declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)
+
+attributes #0 = { nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "denormal-fp-math"="ieee,ieee" "denormal-fp-math-f32"="ieee,ieee" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readnone speculatable willreturn }
+attributes #2 = { argmemonly nounwind willreturn }
+attributes #3 = { nounwind }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 11.0.0 (git at github.com:llvm/llvm-project.git 1d5da8cd30fce1c0a2c2fa6ba656dbfaa36192c8)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "various_ir_values.c", directory: "/data/build/llvm-project")
+!2 = !{}
+!3 = !{i32 7, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{!"clang version 11.0.0 (git at github.com:llvm/llvm-project.git 1d5da8cd30fce1c0a2c2fa6ba656dbfaa36192c8)"}
+!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12)
+!8 = !DISubroutineType(types: !9)
+!9 = !{null, !10}
+!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
+!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!12 = !{!13, !14}
+!13 = !DILocalVariable(name: "A", arg: 1, scope: !7, file: !1, line: 1, type: !10)
+!14 = !DILocalVariable(name: "i", scope: !15, file: !1, line: 3, type: !11)
+!15 = distinct !DILexicalBlock(scope: !7, file: !1, line: 3, column: 3)
+!16 = !{!17, !17, i64 0}
+!17 = !{!"any pointer", !18, i64 0}
+!18 = !{!"omnipotent char", !19, i64 0}
+!19 = !{!"Simple C/C++ TBAA"}
+!20 = !DILocation(line: 1, column: 15, scope: !7)
+!21 = !DILocation(line: 3, column: 8, scope: !15)
+!22 = !DILocation(line: 3, column: 12, scope: !15)
+!23 = !{!24, !24, i64 0}
+!24 = !{!"int", !18, i64 0}
+!25 = !DILocation(line: 3, column: 19, scope: !26)
+!26 = distinct !DILexicalBlock(scope: !15, file: !1, line: 3, column: 3)
+!27 = !DILocation(line: 3, column: 24, scope: !26)
+!28 = !DILocation(line: 3, column: 23, scope: !26)
+!29 = !DILocation(line: 3, column: 21, scope: !26)
+!30 = !DILocation(line: 3, column: 3, scope: !15)
+!31 = !DILocation(line: 3, column: 3, scope: !26)
+!32 = !DILocation(line: 4, column: 5, scope: !26)
+!33 = !DILocation(line: 4, column: 7, scope: !26)
+!34 = !DILocation(line: 4, column: 10, scope: !26)
+!35 = !DILocation(line: 3, column: 27, scope: !26)
+!36 = distinct !{!36, !30, !37}
+!37 = !DILocation(line: 4, column: 12, scope: !15)
+!38 = !DILocation(line: 5, column: 1, scope: !7)
+!39 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 7, type: !8, scopeLine: 7, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !40)
+!40 = !{!41, !42}
+!41 = !DILocalVariable(name: "A", arg: 1, scope: !39, file: !1, line: 7, type: !10)
+!42 = !DILocalVariable(name: "i", scope: !43, file: !1, line: 9, type: !11)
+!43 = distinct !DILexicalBlock(scope: !39, file: !1, line: 9, column: 3)
+!44 = !DILocation(line: 7, column: 15, scope: !39)
+!45 = !DILocation(line: 9, column: 8, scope: !43)
+!46 = !DILocation(line: 9, column: 12, scope: !43)
+!47 = !DILocation(line: 9, column: 19, scope: !48)
+!48 = distinct !DILexicalBlock(scope: !43, file: !1, line: 9, column: 3)
+!49 = !DILocation(line: 9, column: 24, scope: !48)
+!50 = !DILocation(line: 9, column: 23, scope: !48)
+!51 = !DILocation(line: 9, column: 21, scope: !48)
+!52 = !DILocation(line: 9, column: 3, scope: !43)
+!53 = !DILocation(line: 9, column: 3, scope: !48)
+!54 = !DILocation(line: 10, column: 5, scope: !48)
+!55 = !DILocation(line: 10, column: 7, scope: !48)
+!56 = !DILocation(line: 10, column: 10, scope: !48)
+!57 = !DILocation(line: 9, column: 27, scope: !48)
+!58 = distinct !{!58, !52, !59}
+!59 = !DILocation(line: 10, column: 12, scope: !43)
+!60 = !DILocation(line: 11, column: 1, scope: !39)
+!61 = !{!"branch_weights", i32 1, i32 1048575}
+!62 = distinct !DIAssignID()
+;.
+; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C99, file: [[META1:![0-9]+]], producer: "clang version {{.*}}", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: [[META2:![0-9]+]], splitDebugInlining: false, nameTableKind: None)
+; CHECK: [[META1]] = !DIFile(filename: "various_ir_values.c", directory: {{.*}})
+; CHECK: [[META2]] = !{}
+; CHECK: [[META7:![0-9]+]] = distinct !DISubprogram(name: "foo", scope: [[META1]], file: [[META1]], line: 1, type: [[META8:![0-9]+]], scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META12:![0-9]+]])
+; CHECK: [[META8]] = !DISubroutineType(types: [[META9:![0-9]+]])
+; CHECK: [[META9]] = !{null, [[META10:![0-9]+]]}
+; CHECK: [[META10]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META11:![0-9]+]], size: 64)
+; CHECK: [[META11]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+; CHECK: [[META12]] = !{[[META13]], [[META14]]}
+; CHECK: [[META13]] = !DILocalVariable(name: "A", arg: 1, scope: [[META7]], file: [[META1]], line: 1, type: [[META10]])
+; CHECK: [[META14]] = !DILocalVariable(name: "i", scope: [[META15:![0-9]+]], file: [[META1]], line: 3, type: [[META11]])
+; CHECK: [[META15]] = distinct !DILexicalBlock(scope: [[META7]], file: [[META1]], line: 3, column: 3)
+; CHECK: [[DIASSIGNID16]] = distinct !DIAssignID()
+; CHECK: [[DBG17]] = !DILocation(line: 1, column: 15, scope: [[META7]])
+; CHECK: [[TBAA18]] = !{[[META19:![0-9]+]], [[META19]], i64 0}
+; CHECK: [[META19]] = !{!"any pointer", [[META20:![0-9]+]], i64 0}
+; CHECK: [[META20]] = !{!"omnipotent char", [[META21:![0-9]+]], i64 0}
+; CHECK: [[META21]] = !{!"Simple C/C++ TBAA"}
+; CHECK: [[DBG22]] = !DILocation(line: 3, column: 8, scope: [[META15]])
+; CHECK: [[DBG23]] = !DILocation(line: 3, column: 12, scope: [[META15]])
+; CHECK: [[TBAA24]] = !{[[META25:![0-9]+]], [[META25]], i64 0}
+; CHECK: [[META25]] = !{!"int", [[META20]], i64 0}
+; CHECK: [[DBG26]] = !DILocation(line: 3, column: 19, scope: [[META27:![0-9]+]])
+; CHECK: [[META27]] = distinct !DILexicalBlock(scope: [[META15]], file: [[META1]], line: 3, column: 3)
+; CHECK: [[DBG28]] = !DILocation(line: 3, column: 24, scope: [[META27]])
+; CHECK: [[DBG29]] = !DILocation(line: 3, column: 23, scope: [[META27]])
+; CHECK: [[DBG30]] = !DILocation(line: 3, column: 21, scope: [[META27]])
+; CHECK: [[DBG31]] = !DILocation(line: 3, column: 3, scope: [[META15]])
+; CHECK: [[PROF32]] = !{!"branch_weights", i32 1, i32 1048575}
+; CHECK: [[DBG33]] = !DILocation(line: 3, column: 3, scope: [[META27]])
+; CHECK: [[DBG34]] = !DILocation(line: 4, column: 5, scope: [[META27]])
+; CHECK: [[DBG35]] = !DILocation(line: 4, column: 7, scope: [[META27]])
+; CHECK: [[DBG36]] = !DILocation(line: 4, column: 10, scope: [[META27]])
+; CHECK: [[DBG37]] = !DILocation(line: 3, column: 27, scope: [[META27]])
+; CHECK: [[LOOP38]] = distinct !{[[LOOP38]], [[DBG31]], [[META39:![0-9]+]]}
+; CHECK: [[META39]] = !DILocation(line: 4, column: 12, scope: [[META15]])
+; CHECK: [[DBG40]] = !DILocation(line: 5, column: 1, scope: [[META7]])
+; CHECK: [[META41:![0-9]+]] = distinct !DISubprogram(name: "bar", scope: [[META1]], file: [[META1]], line: 7, type: [[META8]], scopeLine: 7, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META42:![0-9]+]])
+; CHECK: [[META42]] = !{[[META43]], [[META44]]}
+; CHECK: [[META43]] = !DILocalVariable(name: "A", arg: 1, scope: [[META41]], file: [[META1]], line: 7, type: [[META10]])
+; CHECK: [[META44]] = !DILocalVariable(name: "i", scope: [[META45:![0-9]+]], file: [[META1]], line: 9, type: [[META11]])
+; CHECK: [[META45]] = distinct !DILexicalBlock(scope: [[META41]], file: [[META1]], line: 9, column: 3)
+; CHECK: [[DBG46]] = !DILocation(line: 7, column: 15, scope: [[META41]])
+; CHECK: [[DBG47]] = !DILocation(line: 9, column: 8, scope: [[META45]])
+; CHECK: [[DBG48]] = !DILocation(line: 9, column: 12, scope: [[META45]])
+; CHECK: [[DBG49]] = !DILocation(line: 9, column: 19, scope: [[META50:![0-9]+]])
+; CHECK: [[META50]] = distinct !DILexicalBlock(scope: [[META45]], file: [[META1]], line: 9, column: 3)
+; CHECK: [[DBG51]] = !DILocation(line: 9, column: 24, scope: [[META50]])
+; CHECK: [[DBG52]] = !DILocation(line: 9, column: 23, scope: [[META50]])
+; CHECK: [[DBG53]] = !DILocation(line: 9, column: 21, scope: [[META50]])
+; CHECK: [[DBG54]] = !DILocation(line: 9, column: 3, scope: [[META45]])
+; CHECK: [[DBG55]] = !DILocation(line: 9, column: 3, scope: [[META50]])
+; CHECK: [[DBG56]] = !DILocation(line: 10, column: 5, scope: [[META50]])
+; CHECK: [[DBG57]] = !DILocation(line: 10, column: 7, scope: [[META50]])
+; CHECK: [[DBG58]] = !DILocation(line: 10, column: 10, scope: [[META50]])
+; CHECK: [[DBG59]] = !DILocation(line: 9, column: 27, scope: [[META50]])
+; CHECK: [[LOOP60]] = distinct !{[[LOOP60]], [[DBG54]], [[META61:![0-9]+]]}
+; CHECK: [[META61]] = !DILocation(line: 10, column: 12, scope: [[META45]])
+; CHECK: [[DBG62]] = !DILocation(line: 11, column: 1, scope: [[META41]])
+;.
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/various_ir_values.test b/llvm/test/tools/UpdateTestChecks/update_test_checks/various_ir_values.test
index c65150eed0a8c19..c8483ffbafa2d61 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/various_ir_values.test
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/various_ir_values.test
@@ -16,3 +16,9 @@
 ## Also try the --check-globals flag
 # RUN: %update_test_checks %t.ll --check-globals
 # RUN: diff -u %t.ll %S/Inputs/various_ir_values.ll.funcsig.globals.expected
+# RUN: cp -f %S/Inputs/various_ir_values.ll %t.ll && %update_test_checks %t.ll --function-signature --check-globals all
+# RUN: diff -u %t.ll %S/Inputs/various_ir_values.ll.funcsig.globals.expected
+# RUN: cp -f %S/Inputs/various_ir_values.ll %t.ll && %update_test_checks %t.ll --check-globals none
+# RUN: diff -u %t.ll %S/Inputs/various_ir_values.ll.funcsig.noglobals.expected
+# RUN: cp -f %S/Inputs/various_ir_values.ll %t.ll && %update_test_checks %t.ll --check-globals smart
+# RUN: diff -u %t.ll %S/Inputs/various_ir_values.ll.funcsig.transitiveglobals.expected
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index 74044f925aadde4..e33fe5cef3b1942 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -26,6 +26,8 @@
    type/attributes.
 3: Opening parenthesis of function args is kept on the first LABEL line
    in case arguments are split to a separate SAME line.
+4: --check-globals now has a third option ('smart'). The others are now called
+   'none' and 'all'. 'smart' is the default.
 """
 DEFAULT_VERSION = 3
 
@@ -228,6 +230,8 @@ def parse_args(parser, argv):
     _verbose = args.verbose
     _global_value_regex = args.global_value_regex
     _global_hex_value_regex = args.global_hex_value_regex
+    if "check_globals" in args and args.check_globals == "default":
+        args.check_globals = "none" if args.version < 3 else "smart"
     return args
 
 
@@ -896,7 +900,8 @@ def __init__(
         *,
         is_before_functions=False,
         is_number=False,
-        replace_number_with_counter=False
+        replace_number_with_counter=False,
+        match_literally=False,
     ):
         self.check_prefix = check_prefix
         self.check_key = check_key
@@ -908,6 +913,7 @@ def __init__(
         # Some variable numbers (e.g. MCINST1234) will change based on unrelated
         # modifications to LLVM, replace those with an incrementing counter.
         self.replace_number_with_counter = replace_number_with_counter
+        self.match_literally = match_literally
         self.variable_mapping = {}
 
     # Return true if this kind of IR value is "local", basically if it matches '%{{.*}}'.
@@ -919,9 +925,10 @@ def is_global_scope_ir_value_match(self, match):
         return self.global_ir_rhs_regexp is not None
 
     # Return the IR prefix and check prefix we use for this kind or IR value,
-    # e.g., (%, TMP) for locals.
+    # e.g., (%, TMP) for locals. If the IR prefix is a regex, return the prefix
+    # used in the IR output
     def get_ir_prefix_from_ir_value_match(self, match):
-        return self.ir_prefix, self.check_prefix
+        return re.search(self.ir_prefix, match[0])[0], self.check_prefix
 
     # Return the IR regexp we use for this kind or IR value, e.g., [\w.-]+? for locals
     def get_ir_regex_from_ir_value_re_match(self, match):
@@ -990,8 +997,15 @@ def get_value_use(self, var, match, var_prefix=None):
     NamelessValue(r"ATTR", "#", r"#", r"[0-9]+", None),
     NamelessValue(r"ATTR", "#", r"attributes #", r"[0-9]+", r"{[^}]*}"),
     NamelessValue(r"GLOB", "@", r"@", r"[0-9]+", None),
+    NamelessValue(r"GLOB", "@", r"@", r"[0-9]+", r".+", is_before_functions=True),
     NamelessValue(
-        r"GLOB", "@", r"@", r'[a-zA-Z0-9_$"\\.-]+', r".+", is_before_functions=True
+        r"GLOBNAMED",
+        "@",
+        r"@",
+        r"[a-zA-Z0-9_$\"\\.-]*[a-zA-Z_$\"\\.-][a-zA-Z0-9_$\"\\.-]*",
+        r".+",
+        is_before_functions=True,
+        match_literally=True,
     ),
     NamelessValue(r"DBG", "!", r"!dbg ", r"![0-9]+", None),
     NamelessValue(r"DIASSIGNID", "!", r"!DIAssignID ", r"![0-9]+", None),
@@ -1003,6 +1017,19 @@ def get_value_use(self, var, match, var_prefix=None):
     NamelessValue(r"META", "!", r"metadata ", r"![0-9]+", None),
     NamelessValue(r"META", "!", r"", r"![0-9]+", r"(?:distinct |)!.*"),
     NamelessValue(r"ACC_GRP", "!", r"!llvm.access.group ", r"![0-9]+", None),
+    NamelessValue(r"META", "!", r"![a-z.]+ ", r"![0-9]+", None),
+]
+
+global_nameless_values = [
+    nameless_value
+    for nameless_value in ir_nameless_values
+    if nameless_value.global_ir_rhs_regexp is not None
+]
+# global variable names should be matched literally
+global_nameless_values_w_unstable_ids = [
+    nameless_value
+    for nameless_value in global_nameless_values
+    if not nameless_value.match_literally
 ]
 
 asm_nameless_values = [
@@ -1060,7 +1087,7 @@ def createPrefixMatch(prefix_str, prefix_re):
     if nameless_value.global_ir_rhs_regexp is not None:
         match = "^" + match
     IR_VALUE_REGEXP_STRING = createOrRegexp(IR_VALUE_REGEXP_STRING, match)
-IR_VALUE_REGEXP_SUFFIX = r"([,\s\(\)]|\Z)"
+IR_VALUE_REGEXP_SUFFIX = r"([,\s\(\)\}]|\Z)"
 IR_VALUE_RE = re.compile(
     IR_VALUE_REGEXP_PREFIX
     + r"("
@@ -1069,6 +1096,18 @@ def createPrefixMatch(prefix_str, prefix_re):
     + IR_VALUE_REGEXP_SUFFIX
 )
 
+GLOBAL_VALUE_REGEXP_STRING = r""
+for nameless_value in global_nameless_values_w_unstable_ids:
+    match = createPrefixMatch(nameless_value.ir_prefix, nameless_value.ir_regexp)
+    GLOBAL_VALUE_REGEXP_STRING = createOrRegexp(GLOBAL_VALUE_REGEXP_STRING, match)
+GLOBAL_VALUE_RE = re.compile(
+    IR_VALUE_REGEXP_PREFIX
+    + r"("
+    + GLOBAL_VALUE_REGEXP_STRING
+    + r")"
+    + IR_VALUE_REGEXP_SUFFIX
+)
+
 # Build the regexp that matches an "ASM value" (currently only for --asm-show-inst comments).
 ASM_VALUE_REGEXP_STRING = ""
 for nameless_value in asm_nameless_values:
@@ -1101,6 +1140,7 @@ def createPrefixMatch(prefix_str, prefix_re):
 variable_group_in_ir_value_match = 3
 attribute_group_in_ir_value_match = 4
 
+
 # Check a match for IR_VALUE_RE and inspect it to determine if it was a local
 # value, %..., global @..., debug number !dbg !..., etc. See the PREFIXES above.
 def get_idx_from_ir_value_match(match):
@@ -1219,6 +1259,20 @@ def generalize_check_lines(
     )
 
 
+def generalize_global_check_line(line, preserve_names, global_vars_seen):
+    [new_line] = generalize_check_lines_common(
+        [line],
+        False,
+        set(),
+        global_vars_seen,
+        global_nameless_values_w_unstable_ids,
+        GLOBAL_VALUE_RE,
+        False,
+        preserve_names,
+    )
+    return new_line
+
+
 def generalize_asm_check_lines(lines, vars_seen, global_vars_seen):
     return generalize_check_lines_common(
         lines,
@@ -1546,7 +1600,7 @@ def add_analyze_checks(
 
 
 def build_global_values_dictionary(glob_val_dict, raw_tool_output, prefixes):
-    for nameless_value in itertools.chain(ir_nameless_values, asm_nameless_values):
+    for nameless_value in itertools.chain(global_nameless_values, asm_nameless_values):
         if nameless_value.global_ir_rhs_regexp is None:
             continue
 
@@ -1573,6 +1627,74 @@ def build_global_values_dictionary(glob_val_dict, raw_tool_output, prefixes):
             glob_val_dict[prefix][nameless_value.check_prefix] = lines
 
 
+def filter_globals_according_to_preference(
+    global_val_lines, global_vars_seen, nameless_value, global_check_setting
+):
+    if global_check_setting == "none":
+        return []
+    if global_check_setting == "all":
+        return global_val_lines
+    assert global_check_setting == "smart"
+
+    if nameless_value.check_key == "#":
+        # attribute sets are usually better checked by --check-attributes
+        return []
+
+    def extract(line, nv):
+        p = (
+            "^"
+            + nv.ir_prefix
+            + "("
+            + nv.ir_regexp
+            + ") = ("
+            + nv.global_ir_rhs_regexp
+            + ")"
+        )
+        match = re.match(p, line)
+        return (match.group(1), re.findall(nv.ir_regexp, match.group(2)))
+
+    transitively_visible = set()
+    contains_refs_to = {}
+
+    def add(var):
+        nonlocal transitively_visible
+        nonlocal contains_refs_to
+        if var in transitively_visible:
+            return
+        transitively_visible.add(var)
+        if not var in contains_refs_to:
+            return
+        for x in contains_refs_to[var]:
+            add(x)
+
+    for line in global_val_lines:
+        (var, refs) = extract(line, nameless_value)
+        contains_refs_to[var] = refs
+    for var, check_key in global_vars_seen:
+        if check_key != nameless_value.check_key:
+            continue
+        add(var)
+    return [
+        line
+        for line in global_val_lines
+        if extract(line, nameless_value)[0] in transitively_visible
+    ]
+
+
+# The capture group is kept as is, followed by a {{.*}} glob
+METADATA_FILTERS = [
+    r"(\w+ version )[\d.]+ \(git@[\w.:/-]+\.git \w+\)",
+    r'(!DIFile\(filename: ".+", directory: )".+"',
+]
+METADATA_FILTERS_RE = [re.compile(s) for s in METADATA_FILTERS]
+
+
+def filter_unstable_metadata(line):
+    for f in METADATA_FILTERS_RE:
+        line = f.sub(r"\1{{.*}}", line)
+    return line
+
+
 def add_global_checks(
     glob_val_dict,
     comment_marker,
@@ -1581,11 +1703,10 @@ def add_global_checks(
     global_vars_seen_dict,
     preserve_names,
     is_before_functions,
+    global_check_setting,
 ):
     printed_prefixes = set()
-    for nameless_value in ir_nameless_values:
-        if nameless_value.global_ir_rhs_regexp is None:
-            continue
+    for nameless_value in global_nameless_values:
         if nameless_value.is_before_functions != is_before_functions:
             continue
         for p in prefix_list:
@@ -1609,19 +1730,26 @@ def add_global_checks(
 
                 check_lines = []
                 global_vars_seen_before = [key for key in global_vars_seen.keys()]
-                for line in glob_val_dict[checkprefix][nameless_value.check_prefix]:
+                lines = glob_val_dict[checkprefix][nameless_value.check_prefix]
+                lines = filter_globals_according_to_preference(
+                    lines, global_vars_seen_before, nameless_value, global_check_setting
+                )
+                for line in lines:
                     if _global_value_regex:
                         matched = False
                         for regex in _global_value_regex:
-                            if re.match("^@" + regex + " = ", line):
+                            if re.match("^@" + regex + " = ", line) or re.match(
+                                "^!" + regex + " = ", line
+                            ):
                                 matched = True
                                 break
                         if not matched:
                             continue
-                    tmp = generalize_check_lines(
-                        [line], False, set(), global_vars_seen, preserve_names
+                    new_line = generalize_global_check_line(
+                        line, preserve_names, global_vars_seen
                     )
-                    check_line = "%s %s: %s" % (comment_marker, checkprefix, tmp[0])
+                    new_line = filter_unstable_metadata(new_line)
+                    check_line = "%s %s: %s" % (comment_marker, checkprefix, new_line)
                     check_lines.append(check_line)
                 if not check_lines:
                     continue
@@ -1705,6 +1833,15 @@ def get_autogennote_suffix(parser, args):
         ):
             continue
         value = getattr(args, action.dest)
+        if action.dest == "check_globals":
+            default_value = "none" if args.version < 3 else "smart"
+            if value == default_value:
+                continue
+            autogenerated_note_args += action.option_strings[0] + " "
+            if args.version < 3 and value == "all":
+                continue
+            autogenerated_note_args += "%s " % value
+            continue
         if action.const is not None:  # action stores a constant (usually True/False)
             # Skip actions with different constant values (this happens with boolean
             # --foo/--no-foo options)
diff --git a/llvm/utils/update_cc_test_checks.py b/llvm/utils/update_cc_test_checks.py
index e96d4167e6567f4..28c6bb0409f3af4 100755
--- a/llvm/utils/update_cc_test_checks.py
+++ b/llvm/utils/update_cc_test_checks.py
@@ -205,7 +205,10 @@ def config():
     )
     parser.add_argument(
         "--check-globals",
-        action="store_true",
+        nargs="?",
+        const="all",
+        default="default",
+        choices=["none", "smart", "all"],
         help="Check global entries (global variables, metadata, attribute sets, ...) for functions",
     )
     parser.add_argument("tests", nargs="+")
@@ -436,7 +439,7 @@ def check_generator(my_output_lines, prefixes, func):
                         is_filtered=builder.is_filtered(),
                     )
 
-            if ti.args.check_globals:
+            if ti.args.check_globals != 'none':
                 generated_prefixes.extend(
                     common.add_global_checks(
                         builder.global_var_dict(),
@@ -444,8 +447,9 @@ def check_generator(my_output_lines, prefixes, func):
                         run_list,
                         output_lines,
                         global_vars_seen_dict,
+                        False,
                         True,
-                        True,
+                        ti.args.check_globals,
                     )
                 )
             generated_prefixes.extend(
@@ -493,7 +497,7 @@ def check_generator(my_output_lines, prefixes, func):
                                 output_lines.pop()
                                 last_line = output_lines[-1].strip()
                             if (
-                                ti.args.check_globals
+                                ti.args.check_globals != 'none'
                                 and not has_checked_pre_function_globals
                             ):
                                 generated_prefixes.extend(
@@ -503,8 +507,9 @@ def check_generator(my_output_lines, prefixes, func):
                                         run_list,
                                         output_lines,
                                         global_vars_seen_dict,
+                                        False,
                                         True,
-                                        True,
+                                        ti.args.check_globals,
                                     )
                                 )
                                 has_checked_pre_function_globals = True
@@ -531,7 +536,7 @@ def check_generator(my_output_lines, prefixes, func):
                 if include_line:
                     output_lines.append(line.rstrip("\n"))
 
-        if ti.args.check_globals:
+        if ti.args.check_globals != 'none':
             generated_prefixes.extend(
                 common.add_global_checks(
                     builder.global_var_dict(),
@@ -539,8 +544,9 @@ def check_generator(my_output_lines, prefixes, func):
                     run_list,
                     output_lines,
                     global_vars_seen_dict,
-                    True,
                     False,
+                    False,
+                    ti.args.check_globals,
                 )
             )
         if ti.args.gen_unused_prefix_body:
diff --git a/llvm/utils/update_test_checks.py b/llvm/utils/update_test_checks.py
index 56ff675ab78d272..06c247c8010a90e 100755
--- a/llvm/utils/update_test_checks.py
+++ b/llvm/utils/update_test_checks.py
@@ -79,7 +79,10 @@ def main():
     )
     parser.add_argument(
         "--check-globals",
-        action="store_true",
+        nargs="?",
+        const="all",
+        default="default",
+        choices=["none", "smart", "all"],
         help="Check global entries (global variables, metadata, attribute sets, ...) for functions",
     )
     parser.add_argument("tests", nargs="+")
@@ -195,7 +198,7 @@ def main():
             common.dump_input_lines(output_lines, ti, prefix_set, ";")
 
             args = ti.args
-            if args.check_globals:
+            if args.check_globals != 'none':
                 generated_prefixes.extend(
                     common.add_global_checks(
                         builder.global_var_dict(),
@@ -205,6 +208,7 @@ def main():
                         global_vars_seen_dict,
                         args.preserve_names,
                         True,
+                        args.check_globals,
                     )
                 )
 
@@ -272,6 +276,7 @@ def main():
                                 global_vars_seen_dict,
                                 args.preserve_names,
                                 True,
+                                args.check_globals,
                             )
                         )
                     has_checked_pre_function_globals = True
@@ -301,7 +306,7 @@ def main():
                     continue
                 is_in_function = is_in_function_start = True
 
-        if args.check_globals:
+        if args.check_globals != 'none':
             generated_prefixes.extend(
                 common.add_global_checks(
                     builder.global_var_dict(),
@@ -311,6 +316,7 @@ def main():
                     global_vars_seen_dict,
                     args.preserve_names,
                     False,
+                    args.check_globals,
                 )
             )
         if ti.args.gen_unused_prefix_body:

>From 535b55dfaddf62c6777b4adcc9f46761080d7ab0 Mon Sep 17 00:00:00 2001
From: "Henrik G. Olsson" <hnrklssn at gmail.com>
Date: Fri, 20 Oct 2023 17:39:04 +0200
Subject: [PATCH 2/6] Revert "Revert "[UTC] Fix git URL regex""

This reverts commit 75836eb952d1dae16f206f68113577bd38530471.
---
 llvm/utils/UpdateTestChecks/common.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index e33fe5cef3b1942..2994ead86a37f76 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -1683,7 +1683,7 @@ def add(var):
 
 # The capture group is kept as is, followed by a {{.*}} glob
 METADATA_FILTERS = [
-    r"(\w+ version )[\d.]+ \(git@[\w.:/-]+\.git \w+\)",
+    r"(\w+ version )[\d.]+ \([\w.:/@-]+\.git \w+\)",
     r'(!DIFile\(filename: ".+", directory: )".+"',
 ]
 METADATA_FILTERS_RE = [re.compile(s) for s in METADATA_FILTERS]

>From 6b37cb976a1323d4a5b342811ccf1c78998f926d Mon Sep 17 00:00:00 2001
From: "Henrik G. Olsson" <hnrklssn at gmail.com>
Date: Fri, 20 Oct 2023 17:39:15 +0200
Subject: [PATCH 3/6] Revert "Revert "[UTC] Generalize version regex""

This reverts commit c1b1c40920301bd337e97945cf93b3364b0e2548.
---
 llvm/utils/UpdateTestChecks/common.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index 2994ead86a37f76..317319eed52332b 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -1683,7 +1683,7 @@ def add(var):
 
 # The capture group is kept as is, followed by a {{.*}} glob
 METADATA_FILTERS = [
-    r"(\w+ version )[\d.]+ \([\w.:/@-]+\.git \w+\)",
+    r"(\w+ version )[\d.]+(?: \([^)]+\))?",
     r'(!DIFile\(filename: ".+", directory: )".+"',
 ]
 METADATA_FILTERS_RE = [re.compile(s) for s in METADATA_FILTERS]

>From e72b3d4d162447b0d56ecc337897aecb0f18542e Mon Sep 17 00:00:00 2001
From: "Henrik G. Olsson" <hnrklssn at gmail.com>
Date: Fri, 20 Oct 2023 17:39:26 +0200
Subject: [PATCH 4/6] Revert "Revert "[UTC] Adapt version matcher to glob
 CLANG_VENDOR""

This reverts commit 5b8b9b39ccd06989b722f8d0adad0aa4da6d7d72.
---
 .../Inputs/generated-funcs.c.generated.all.expected   |  4 ++--
 .../generated-funcs.c.no-generated.all.expected       |  4 ++--
 .../various_ir_values.ll.funcsig.globals.expected     |  4 ++--
 ...us_ir_values.ll.funcsig.transitiveglobals.expected |  2 +-
 llvm/utils/UpdateTestChecks/common.py                 | 11 +++++------
 5 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.all.expected b/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.all.expected
index 66959811660d651..6ec61165377512d 100644
--- a/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.all.expected
+++ b/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.all.expected
@@ -247,12 +247,12 @@ void foo(void) {
 //.
 // OMP: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
 // OMP: [[META1:![0-9]+]] = !{i32 7, !"openmp", i32 51}
-// OMP: [[META2:![0-9]+]] = !{!"clang version {{.*}}"}
+// OMP: [[META2:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"}
 // OMP: [[META3:![0-9]+]] = !{[[META4:![0-9]+]]}
 // OMP: [[META4]] = !{i64 2, i64 -1, i64 -1, i1 true}
 //.
 // NOOMP: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
-// NOOMP: [[META1:![0-9]+]] = !{!"clang version {{.*}}"}
+// NOOMP: [[META1:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"}
 // NOOMP: [[LOOP2]] = distinct !{[[LOOP2]], [[META3:![0-9]+]]}
 // NOOMP: [[META3]] = !{!"llvm.loop.mustprogress"}
 // NOOMP: [[LOOP4]] = distinct !{[[LOOP4]], [[META3]]}
diff --git a/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.no-generated.all.expected b/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.no-generated.all.expected
index 219e5ceee6c7847..1b0074023a60cb9 100644
--- a/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.no-generated.all.expected
+++ b/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.no-generated.all.expected
@@ -118,12 +118,12 @@ void foo(void) {
 //.
 // OMP: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
 // OMP: [[META1:![0-9]+]] = !{i32 7, !"openmp", i32 51}
-// OMP: [[META2:![0-9]+]] = !{!"clang version {{.*}}"}
+// OMP: [[META2:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"}
 // OMP: [[META3:![0-9]+]] = !{[[META4:![0-9]+]]}
 // OMP: [[META4]] = !{i64 2, i64 -1, i64 -1, i1 true}
 //.
 // NOOMP: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
-// NOOMP: [[META1:![0-9]+]] = !{!"clang version {{.*}}"}
+// NOOMP: [[META1:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"}
 // NOOMP: [[LOOP2]] = distinct !{[[LOOP2]], [[META3:![0-9]+]]}
 // NOOMP: [[META3]] = !{!"llvm.loop.mustprogress"}
 // NOOMP: [[LOOP4]] = distinct !{[[LOOP4]], [[META3]]}
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.globals.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.globals.expected
index a867c34090123d1..ea35ec593720e7c 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.globals.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.globals.expected
@@ -250,13 +250,13 @@ attributes #3 = { nounwind }
 ; CHECK: attributes #[[ATTR2:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
 ; CHECK: attributes #[[ATTR3]] = { nounwind }
 ;.
-; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C99, file: [[META1:![0-9]+]], producer: "clang version {{.*}}", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: [[META2:![0-9]+]], splitDebugInlining: false, nameTableKind: None)
+; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C99, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: [[META2:![0-9]+]], splitDebugInlining: false, nameTableKind: None)
 ; CHECK: [[META1]] = !DIFile(filename: "various_ir_values.c", directory: {{.*}})
 ; CHECK: [[META2]] = !{}
 ; CHECK: [[META3:![0-9]+]] = !{i32 7, !"Dwarf Version", i32 4}
 ; CHECK: [[META4:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3}
 ; CHECK: [[META5:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
-; CHECK: [[META6:![0-9]+]] = !{!"clang version {{.*}}"}
+; CHECK: [[META6:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"}
 ; CHECK: [[DBG7]] = distinct !DISubprogram(name: "foo", scope: [[META1]], file: [[META1]], line: 1, type: [[META8:![0-9]+]], scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META12:![0-9]+]])
 ; CHECK: [[META8]] = !DISubroutineType(types: [[META9:![0-9]+]])
 ; CHECK: [[META9]] = !{null, [[META10:![0-9]+]]}
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.transitiveglobals.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.transitiveglobals.expected
index debe0911d91120e..73d17052212e10b 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.transitiveglobals.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.transitiveglobals.expected
@@ -243,7 +243,7 @@ attributes #3 = { nounwind }
 !61 = !{!"branch_weights", i32 1, i32 1048575}
 !62 = distinct !DIAssignID()
 ;.
-; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C99, file: [[META1:![0-9]+]], producer: "clang version {{.*}}", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: [[META2:![0-9]+]], splitDebugInlining: false, nameTableKind: None)
+; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C99, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: [[META2:![0-9]+]], splitDebugInlining: false, nameTableKind: None)
 ; CHECK: [[META1]] = !DIFile(filename: "various_ir_values.c", directory: {{.*}})
 ; CHECK: [[META2]] = !{}
 ; CHECK: [[META7:![0-9]+]] = distinct !DISubprogram(name: "foo", scope: [[META1]], file: [[META1]], line: 1, type: [[META8:![0-9]+]], scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META12:![0-9]+]])
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index 317319eed52332b..7c1f2896f21e88e 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -1681,17 +1681,16 @@ def add(var):
     ]
 
 
-# The capture group is kept as is, followed by a {{.*}} glob
 METADATA_FILTERS = [
-    r"(\w+ version )[\d.]+(?: \([^)]+\))?",
-    r'(!DIFile\(filename: ".+", directory: )".+"',
+    (r"(?<=\")(\w+ )?(\w+ version )[\d.]+(?: \([^)]+\))?", r"{{.*}}\2{{.*}}"), # preface with glob also, to capture optional CLANG_VENDOR
+    (r'(!DIFile\(filename: ".+", directory: )".+"', r"\1{{.*}}"),
 ]
-METADATA_FILTERS_RE = [re.compile(s) for s in METADATA_FILTERS]
+METADATA_FILTERS_RE = [(re.compile(f),r) for (f,r) in METADATA_FILTERS]
 
 
 def filter_unstable_metadata(line):
-    for f in METADATA_FILTERS_RE:
-        line = f.sub(r"\1{{.*}}", line)
+    for (f,replacement) in METADATA_FILTERS_RE:
+        line = f.sub(replacement, line)
     return line
 
 

>From 1d2c54d28252b32fcf06acb72329967e7ccabeb5 Mon Sep 17 00:00:00 2001
From: "Henrik G. Olsson" <hnrklssn at gmail.com>
Date: Mon, 23 Oct 2023 17:25:42 +0200
Subject: [PATCH 5/6] [UTC] Fixup after recommitting

UTC version 3 already exists, bump the reintroduced changes to version 4.
---
 .../update_cc_test_checks/Inputs/annotations.c.expected   | 2 +-
 clang/test/utils/update_cc_test_checks/annotations.test   | 2 +-
 llvm/utils/UpdateTestChecks/common.py                     | 8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/clang/test/utils/update_cc_test_checks/Inputs/annotations.c.expected b/clang/test/utils/update_cc_test_checks/Inputs/annotations.c.expected
index f368ca00dbc84b6..1eb82f6eb5ddccc 100644
--- a/clang/test/utils/update_cc_test_checks/Inputs/annotations.c.expected
+++ b/clang/test/utils/update_cc_test_checks/Inputs/annotations.c.expected
@@ -1,4 +1,4 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 3
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -fblocks -ftrivial-auto-var-init=zero %s -emit-llvm -o - | FileCheck %s
 
 // CHECK-LABEL: define dso_local i32 @foo(
diff --git a/clang/test/utils/update_cc_test_checks/annotations.test b/clang/test/utils/update_cc_test_checks/annotations.test
index 1ef38e1746993d2..06e88930b9d4a0a 100644
--- a/clang/test/utils/update_cc_test_checks/annotations.test
+++ b/clang/test/utils/update_cc_test_checks/annotations.test
@@ -1,4 +1,4 @@
 ## Test that !annotation metadata is matched correctly
 
-# RUN: cp %S/Inputs/annotations.c %t.c && %update_cc_test_checks --version 3 %t.c
+# RUN: cp %S/Inputs/annotations.c %t.c && %update_cc_test_checks --version 4 %t.c
 # RUN: diff -u %S/Inputs/annotations.c.expected %t.c
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index 7c1f2896f21e88e..fca5d1b440cb715 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -29,7 +29,7 @@
 4: --check-globals now has a third option ('smart'). The others are now called
    'none' and 'all'. 'smart' is the default.
 """
-DEFAULT_VERSION = 3
+DEFAULT_VERSION = 4
 
 
 class Regex(object):
@@ -231,7 +231,7 @@ def parse_args(parser, argv):
     _global_value_regex = args.global_value_regex
     _global_hex_value_regex = args.global_hex_value_regex
     if "check_globals" in args and args.check_globals == "default":
-        args.check_globals = "none" if args.version < 3 else "smart"
+        args.check_globals = "none" if args.version < 4 else "smart"
     return args
 
 
@@ -1833,11 +1833,11 @@ def get_autogennote_suffix(parser, args):
             continue
         value = getattr(args, action.dest)
         if action.dest == "check_globals":
-            default_value = "none" if args.version < 3 else "smart"
+            default_value = "none" if args.version < 4 else "smart"
             if value == default_value:
                 continue
             autogenerated_note_args += action.option_strings[0] + " "
-            if args.version < 3 and value == "all":
+            if args.version < 4 and value == "all":
                 continue
             autogenerated_note_args += "%s " % value
             continue

>From f6c2574edbd1d4fa586b7577149c67cd104d36dc Mon Sep 17 00:00:00 2001
From: "Henrik G. Olsson" <hnrklssn at gmail.com>
Date: Tue, 24 Oct 2023 15:36:02 +0200
Subject: [PATCH 6/6] [UTC] Re-merge checkers for named and unnamed globals

Since the matcher for named globals was extracted into a separate match
instance (GLOBNAMED) UTC scripts would emit unnamed globals first,
followed by named globals. LLVM IR allows them to be interspersed in any
order, leading to CHECK lines being incorrectly ordered.

This fixes that by recording each check-line's index in the input file,
allowing them to be sorted properly after being collected. A new
attribute is added to NamelessValue (interlaced_with_previous), which
is set to True for GLOBNAMED, to indicate that it should be emitted
together with GLOB check-lines.
---
 .../generated-funcs.c.generated.all.expected  |  5 +-
 ...enerated-funcs.c.no-generated.all.expected |  5 +-
 llvm/utils/UpdateTestChecks/common.py         | 52 ++++++++++++++-----
 3 files changed, 43 insertions(+), 19 deletions(-)

diff --git a/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.all.expected b/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.all.expected
index 6ec61165377512d..b3945741ad49577 100644
--- a/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.all.expected
+++ b/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.all.expected
@@ -31,13 +31,12 @@ void foo(void) {
   }
 }
 //.
+// OMP: @A = global [33554432 x double] zeroinitializer, align 16
+// OMP: @size = constant i32 33554432, align 4
 // OMP: @[[GLOB0:[0-9]+]] = private unnamed_addr constant [23 x i8] c"
 // OMP: @[[GLOB1:[0-9]+]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 514, i32 0, i32 22, ptr @[[GLOB0]] }, align 8
 // OMP: @[[GLOB2:[0-9]+]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 22, ptr @[[GLOB0]] }, align 8
 //.
-// OMP: @A = global [33554432 x double] zeroinitializer, align 16
-// OMP: @size = constant i32 33554432, align 4
-//.
 // NOOMP: @size = constant i32 33554432, align 4
 // NOOMP: @A = global [33554432 x double] zeroinitializer, align 16
 //.
diff --git a/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.no-generated.all.expected b/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.no-generated.all.expected
index 1b0074023a60cb9..8eda594112e3fbf 100644
--- a/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.no-generated.all.expected
+++ b/clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.no-generated.all.expected
@@ -10,13 +10,12 @@ double A[size];
 void foo(void);
 
 //.
+// OMP: @A = global [33554432 x double] zeroinitializer, align 16
+// OMP: @size = constant i32 33554432, align 4
 // OMP: @[[GLOB0:[0-9]+]] = private unnamed_addr constant [23 x i8] c"
 // OMP: @[[GLOB1:[0-9]+]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 514, i32 0, i32 22, ptr @[[GLOB0]] }, align 8
 // OMP: @[[GLOB2:[0-9]+]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 22, ptr @[[GLOB0]] }, align 8
 //.
-// OMP: @A = global [33554432 x double] zeroinitializer, align 16
-// OMP: @size = constant i32 33554432, align 4
-//.
 // NOOMP: @size = constant i32 33554432, align 4
 // NOOMP: @A = global [33554432 x double] zeroinitializer, align 16
 //.
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index fca5d1b440cb715..8fe4533e3c5a2ad 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -902,6 +902,7 @@ def __init__(
         is_number=False,
         replace_number_with_counter=False,
         match_literally=False,
+        interlaced_with_previous=False
     ):
         self.check_prefix = check_prefix
         self.check_key = check_key
@@ -914,6 +915,7 @@ def __init__(
         # modifications to LLVM, replace those with an incrementing counter.
         self.replace_number_with_counter = replace_number_with_counter
         self.match_literally = match_literally
+        self.interlaced_with_previous = interlaced_with_previous
         self.variable_mapping = {}
 
     # Return true if this kind of IR value is "local", basically if it matches '%{{.*}}'.
@@ -1006,6 +1008,7 @@ def get_value_use(self, var, match, var_prefix=None):
         r".+",
         is_before_functions=True,
         match_literally=True,
+        interlaced_with_previous=True,
     ),
     NamelessValue(r"DBG", "!", r"!dbg ", r"![0-9]+", None),
     NamelessValue(r"DIASSIGNID", "!", r"!DIAssignID ", r"![0-9]+", None),
@@ -1611,7 +1614,10 @@ def build_global_values_dictionary(glob_val_dict, raw_tool_output, prefixes):
         global_ir_value_re = re.compile(global_ir_value_re_str, flags=(re.M))
         lines = []
         for m in global_ir_value_re.finditer(raw_tool_output):
-            lines.append(m.group(0))
+            # Attach the substring's start index so that CHECK lines
+            # can be sorted properly even if they are matched by different nameless values.
+            # This is relevant for GLOB and GLOBNAMED since they may appear interlaced.
+            lines.append((m.start(), m.group(0)))
 
         for prefix in prefixes:
             if glob_val_dict[prefix] is None:
@@ -1628,12 +1634,12 @@ def build_global_values_dictionary(glob_val_dict, raw_tool_output, prefixes):
 
 
 def filter_globals_according_to_preference(
-    global_val_lines, global_vars_seen, nameless_value, global_check_setting
+    global_val_lines_w_index, global_vars_seen, nameless_value, global_check_setting
 ):
     if global_check_setting == "none":
         return []
     if global_check_setting == "all":
-        return global_val_lines
+        return global_val_lines_w_index
     assert global_check_setting == "smart"
 
     if nameless_value.check_key == "#":
@@ -1667,7 +1673,7 @@ def add(var):
         for x in contains_refs_to[var]:
             add(x)
 
-    for line in global_val_lines:
+    for i, line in global_val_lines_w_index:
         (var, refs) = extract(line, nameless_value)
         contains_refs_to[var] = refs
     for var, check_key in global_vars_seen:
@@ -1675,8 +1681,8 @@ def add(var):
             continue
         add(var)
     return [
-        line
-        for line in global_val_lines
+        (i, line)
+        for i, line in global_val_lines_w_index
         if extract(line, nameless_value)[0] in transitively_visible
     ]
 
@@ -1693,6 +1699,14 @@ def filter_unstable_metadata(line):
         line = f.sub(replacement, line)
     return line
 
+def flush_current_checks(output_lines, new_lines_w_index, comment_marker):
+    if not new_lines_w_index:
+        return
+    output_lines.append(comment_marker + SEPARATOR)
+    new_lines_w_index.sort()
+    for _, line in new_lines_w_index:
+        output_lines.append(line)
+    new_lines_w_index.clear()
 
 def add_global_checks(
     glob_val_dict,
@@ -1705,6 +1719,7 @@ def add_global_checks(
     global_check_setting,
 ):
     printed_prefixes = set()
+    output_lines_loc = {} # Allows GLOB and GLOBNAMED to be sorted correctly
     for nameless_value in global_nameless_values:
         if nameless_value.is_before_functions != is_before_functions:
             continue
@@ -1729,11 +1744,11 @@ def add_global_checks(
 
                 check_lines = []
                 global_vars_seen_before = [key for key in global_vars_seen.keys()]
-                lines = glob_val_dict[checkprefix][nameless_value.check_prefix]
-                lines = filter_globals_according_to_preference(
-                    lines, global_vars_seen_before, nameless_value, global_check_setting
+                lines_w_index = glob_val_dict[checkprefix][nameless_value.check_prefix]
+                lines_w_index = filter_globals_according_to_preference(
+                    lines_w_index, global_vars_seen_before, nameless_value, global_check_setting
                 )
-                for line in lines:
+                for i, line in lines_w_index:
                     if _global_value_regex:
                         matched = False
                         for regex in _global_value_regex:
@@ -1749,13 +1764,16 @@ def add_global_checks(
                     )
                     new_line = filter_unstable_metadata(new_line)
                     check_line = "%s %s: %s" % (comment_marker, checkprefix, new_line)
-                    check_lines.append(check_line)
+                    check_lines.append((i, check_line))
                 if not check_lines:
                     continue
 
-                output_lines.append(comment_marker + SEPARATOR)
+                if not checkprefix in output_lines_loc:
+                    output_lines_loc[checkprefix] = []
+                if not nameless_value.interlaced_with_previous:
+                    flush_current_checks(output_lines, output_lines_loc[checkprefix], comment_marker)
                 for check_line in check_lines:
-                    output_lines.append(check_line)
+                    output_lines_loc[checkprefix].append(check_line)
 
                 printed_prefixes.add((checkprefix, nameless_value.check_prefix))
 
@@ -1766,6 +1784,14 @@ def add_global_checks(
                 break
 
     if printed_prefixes:
+        for p in prefix_list:
+            if p[0] is None:
+                continue
+            for checkprefix in p[0]:
+                if checkprefix not in output_lines_loc:
+                    continue
+                flush_current_checks(output_lines, output_lines_loc[checkprefix], comment_marker)
+                break
         output_lines.append(comment_marker + SEPARATOR)
     return printed_prefixes
 



More information about the cfe-commits mailing list