Skip to content

Commit 3846019

Browse files
committed
update_test_checks: keep meta variables stable by default
Resubmitting this after previous revert with the following changes: - Split table into table_rhs_idx and table_candidate_idx so that bisect.bisect_left can be used without the `key` argument, which was introduced in Python 3.10 - Remove a re.Pattern type annotation Original commit message: Prior to this change, running UTC on larger tests, especially tests with unnamed IR values, often resulted in a spuriously large diff because e.g. TMPnn variables in the CHECK lines were renumbered. This change attempts to reduce the diff by keeping those variable names the same. There are cases in which this "drift" of variable names can end up being more confusing. The old behavior can be re-enabled with the --reset-variable-names command line argument. The improvement may not be immediately apparent in the diff of this change. The point is that the diff of stable_ir_values.ll against stable_ir_values.ll.expected after this change is smaller. Ideally, we'd also keep meta variables for "global" objects stable, e.g. for attributes (#nn) and metadata (!nn). However, that would require a much more substantial refactoring of how we generate check lines, so I left it for future work.
1 parent b565126 commit 3846019

9 files changed

+556
-42
lines changed

llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/stable_ir_values.ll.expected

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
define i32 @func({i32, i32} %x, i32 %y) {
1010
; CHECK-LABEL: define i32 @func(
1111
; CHECK-SAME: { i32, i32 } [[X:%.*]], i32 [[Y:%.*]]) {
12-
; CHECK-NEXT: [[X_I34:%.*]] = extractvalue { i32, i32 } [[X]], 0
13-
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[Y]], 1
14-
; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[X_I34]], [[TMP1]]
15-
; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], 3
16-
; CHECK-NEXT: ret i32 [[TMP3]]
12+
; CHECK-NEXT: [[X_I33:%.*]] = extractvalue { i32, i32 } [[X]], 0
13+
; CHECK-NEXT: [[TMP3:%.*]] = add i32 [[Y]], 1
14+
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[X_I33]], [[TMP3]]
15+
; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], 3
16+
; CHECK-NEXT: ret i32 [[TMP2]]
1717
;
1818
%x.i34 = extractvalue {i32, i32} %x, 0
1919
%1 = add i32 %y, 1
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
2+
; RUN: opt < %s -S | FileCheck %s
3+
4+
; The assumption underlying this test is that there are pre-existing check lines
5+
; but something has changed, and we would like to avoid needless changes of
6+
; meta variable names so that diffs end up being easier to read, e.g. avoid
7+
; changing X_I33 into X_I34 or renumbering the various TMP variables.
8+
9+
define i32 @func({i32, i32} %x, i32 %y) {
10+
; CHECK-LABEL: define i32 @func(
11+
; CHECK-SAME: { i32, i32 } [[X:%.*]], i32 [[Y:%.*]]) {
12+
; CHECK-NEXT: [[X_I34:%.*]] = extractvalue { i32, i32 } [[X]], 0
13+
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[Y]], 1
14+
; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[X_I34]], [[TMP1]]
15+
; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], 3
16+
; CHECK-NEXT: ret i32 [[TMP3]]
17+
;
18+
%x.i34 = extractvalue {i32, i32} %x, 0
19+
%1 = add i32 %y, 1
20+
%2 = add i32 %x.i34, %1
21+
%3 = mul i32 %2, 3
22+
ret i32 %3
23+
}

llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/stable_ir_values2.ll.expected

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ define i32 @func(i32 %x) {
55
; CHECK-LABEL: define i32 @func(
66
; CHECK-SAME: i32 [[X:%.*]]) {
77
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[X]], 0
8-
; CHECK-NEXT: [[TMP2:%.*]] = call i32 @foo(i1 [[TMP1]])
9-
; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[X]], 2
10-
; CHECK-NEXT: [[TMP4:%.*]] = call i32 @foo(i1 [[TMP3]])
11-
; CHECK-NEXT: [[TMP5:%.*]] = icmp ne i32 [[TMP4]], 0
12-
; CHECK-NEXT: [[TMP6:%.*]] = select i1 [[TMP5]], i32 [[TMP4]], i32 [[TMP2]]
13-
; CHECK-NEXT: ret i32 [[TMP6]]
8+
; CHECK-NEXT: [[TMP6:%.*]] = call i32 @foo(i1 [[TMP1]])
9+
; CHECK-NEXT: [[TMP7:%.*]] = icmp eq i32 [[X]], 2
10+
; CHECK-NEXT: [[TMP8:%.*]] = call i32 @foo(i1 [[TMP7]])
11+
; CHECK-NEXT: [[TMP9:%.*]] = icmp ne i32 [[TMP8]], 0
12+
; CHECK-NEXT: [[TMP10:%.*]] = select i1 [[TMP9]], i32 [[TMP8]], i32 [[TMP6]]
13+
; CHECK-NEXT: ret i32 [[TMP10]]
1414
;
1515
%1 = icmp eq i32 %x, 0
1616
%2 = call i32 @foo(i1 %1)

llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/stable_ir_values3.ll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
22
; RUN: opt < %s -S | FileCheck %s
33

4-
; Test that we don't regress diff quality by trying to keep variable names
5-
; stable (and messing up the matching).
6-
74
define i32 @func(i32 %x) {
85
; CHECK-LABEL: define i32 @func(
96
; CHECK-SAME: i32 [[X:%.*]]) {

llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/stable_ir_values3.ll.expected

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
22
; RUN: opt < %s -S | FileCheck %s
33

4-
; Test that we don't regress diff quality by trying to keep variable names
5-
; stable (and messing up the matching).
6-
74
define i32 @func(i32 %x) {
85
; CHECK-LABEL: define i32 @func(
96
; CHECK-SAME: i32 [[X:%.*]]) {

llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/stable_ir_values4.ll.expected

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ define i32 @func(i32 %x) {
1515
; CHECK-NEXT: [[TMP6:%.*]] = call i32 @foo(i32 [[TMP5]])
1616
; CHECK-NEXT: [[TMP7:%.*]] = call i32 @foo(i32 [[TMP6]])
1717
; CHECK-NEXT: [[TMP8:%.*]] = xor i32 [[TMP7]], 1
18-
; CHECK-NEXT: [[TMP9:%.*]] = call i32 @foo(i32 [[TMP8]])
19-
; CHECK-NEXT: [[TMP10:%.*]] = add i32 [[TMP9]], 1
18+
; CHECK-NEXT: [[TMP13:%.*]] = call i32 @foo(i32 [[TMP8]])
19+
; CHECK-NEXT: [[TMP9:%.*]] = add i32 [[TMP13]], 1
20+
; CHECK-NEXT: [[TMP10:%.*]] = call i32 @foo(i32 [[TMP9]])
2021
; CHECK-NEXT: [[TMP11:%.*]] = call i32 @foo(i32 [[TMP10]])
2122
; CHECK-NEXT: [[TMP12:%.*]] = call i32 @foo(i32 [[TMP11]])
22-
; CHECK-NEXT: [[TMP13:%.*]] = call i32 @foo(i32 [[TMP12]])
23-
; CHECK-NEXT: ret i32 [[TMP13]]
23+
; CHECK-NEXT: ret i32 [[TMP12]]
2424
;
2525
%1 = mul i32 %x, 3
2626
%2 = call i32 @foo(i32 %1)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# RUN: cp -f %S/Inputs/stable_ir_values.ll %t.ll && %update_test_checks %t.ll
22
# RUN: diff -u %t.ll %S/Inputs/stable_ir_values.ll.expected
3+
# Now test that we can reset all the names
4+
# RUN: %update_test_checks %t.ll --reset-variable-names
5+
# RUN: diff -u %t.ll %S/Inputs/stable_ir_values.ll.expected.reset

0 commit comments

Comments
 (0)