Skip to content

Commit 597ac47

Browse files
authored
update_test_checks: match IR basic block labels (#88979)
Labels are matched using a regexp of the form '^(pattern):', which requires the addition of a "suffix" concept to NamelessValue. Aside from that, the key challenge is that block labels are values, and we typically capture values including the prefix '%'. However, when labels appear at the start of a basic block, the prefix '%' is not included, so we must capture block label values *without* the prefix '%'. We don't know ahead of time whether an IR value is a label or not. In most cases, they are prefixed by the word "label" (their type), but this isn't the case in phi nodes. We solve this issue by leveraging the two-phase nature of variable generalization: the first pass finds all occurences of a variable and determines whether the '%' prefix can be included or not. The second pass does the actual substitution. This change also unifies the generalization path for assembly with that for IR and analysis, in the hope that any future changes avoid diverging those cases future. I also considered the alternative of trying to detect the phi node case using more regular expression special cases but ultimately decided against that because it seemed more fragile, and perhaps the approach of keeping a tentative prefix that may later be discarded could also be eventually applied to some metadata and attribute cases. Note that an early version of this change was reviewed as https://reviews.llvm.org/D142452, before version numbers were introduced. This is a substantially updated version of that change.
1 parent c3677e4 commit 597ac47

File tree

9 files changed

+534
-516
lines changed

9 files changed

+534
-516
lines changed

llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/phi-labels.ll.expected

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

44
define i32 @phi_after_label(i1 %cc) {
55
; CHECK-LABEL: define i32 @phi_after_label(
66
; CHECK-SAME: i1 [[CC:%.*]]) {
7-
; CHECK-NEXT: entry:
8-
; CHECK-NEXT: br i1 [[CC]], label [[THEN:%.*]], label [[END:%.*]]
9-
; CHECK: then:
10-
; CHECK-NEXT: br label [[END]]
11-
; CHECK: end:
12-
; CHECK-NEXT: [[R:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ 1, [[THEN]] ]
7+
; CHECK-NEXT: [[ENTRY:.*]]:
8+
; CHECK-NEXT: br i1 [[CC]], label %[[THEN:.*]], label %[[END:.*]]
9+
; CHECK: [[THEN]]:
10+
; CHECK-NEXT: br label %[[END]]
11+
; CHECK: [[END]]:
12+
; CHECK-NEXT: [[R:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ 1, %[[THEN]] ]
1313
; CHECK-NEXT: ret i32 [[R]]
1414
;
1515
entry:
@@ -26,14 +26,14 @@ end:
2626
define void @phi_before_label(i32 %bound) {
2727
; CHECK-LABEL: define void @phi_before_label(
2828
; CHECK-SAME: i32 [[BOUND:%.*]]) {
29-
; CHECK-NEXT: entry:
30-
; CHECK-NEXT: br label [[LOOP:%.*]]
31-
; CHECK: loop:
32-
; CHECK-NEXT: [[CTR:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[CTR_NEXT:%.*]], [[LOOP]] ]
29+
; CHECK-NEXT: [[ENTRY:.*]]:
30+
; CHECK-NEXT: br label %[[LOOP:.*]]
31+
; CHECK: [[LOOP]]:
32+
; CHECK-NEXT: [[CTR:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ [[CTR_NEXT:%.*]], %[[LOOP]] ]
3333
; CHECK-NEXT: [[CTR_NEXT]] = add i32 [[CTR]], 1
3434
; CHECK-NEXT: [[CC:%.*]] = icmp ult i32 [[CTR_NEXT]], [[BOUND]]
35-
; CHECK-NEXT: br i1 [[CC]], label [[LOOP]], label [[END:%.*]]
36-
; CHECK: end:
35+
; CHECK-NEXT: br i1 [[CC]], label %[[LOOP]], label %[[END:.*]]
36+
; CHECK: [[END]]:
3737
; CHECK-NEXT: ret void
3838
;
3939
entry:
@@ -52,11 +52,11 @@ end:
5252
define i32 @phi_after_label_unnamed(i1 %cc) {
5353
; CHECK-LABEL: define i32 @phi_after_label_unnamed(
5454
; CHECK-SAME: i1 [[CC:%.*]]) {
55-
; CHECK-NEXT: br i1 [[CC]], label [[TMP1:%.*]], label [[TMP2:%.*]]
56-
; CHECK: 1:
57-
; CHECK-NEXT: br label [[TMP2]]
58-
; CHECK: 2:
59-
; CHECK-NEXT: [[R:%.*]] = phi i32 [ 0, [[TMP0:%.*]] ], [ 1, [[TMP1]] ]
55+
; CHECK-NEXT: br i1 [[CC]], label %[[BB1:.*]], label %[[BB2:.*]]
56+
; CHECK: [[BB1]]:
57+
; CHECK-NEXT: br label %[[BB2]]
58+
; CHECK: [[BB2]]:
59+
; CHECK-NEXT: [[R:%.*]] = phi i32 [ 0, [[TMP0:%.*]] ], [ 1, %[[BB1]] ]
6060
; CHECK-NEXT: ret i32 [[R]]
6161
;
6262
0:

llvm/test/tools/UpdateTestChecks/update_test_checks/phi-labels.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# RUN: cp -f %S/Inputs/phi-labels.ll %t.ll && %update_test_checks --version 4 %t.ll
1+
# RUN: cp -f %S/Inputs/phi-labels.ll %t.ll && %update_test_checks --version 5 %t.ll
22
# RUN: diff -u %t.ll %S/Inputs/phi-labels.ll.expected
33
## Check that running the script again does not change the result:
44
# RUN: %update_test_checks %t.ll

llvm/utils/UpdateTestChecks/asm.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ def add_checks(
605605
prefix_list,
606606
func_dict,
607607
func_name,
608+
ginfo: common.GeneralizerInfo,
608609
global_vars_seen_dict,
609610
is_filtered,
610611
):
@@ -617,9 +618,7 @@ def add_checks(
617618
func_dict,
618619
func_name,
619620
check_label_format,
620-
True,
621-
False,
622-
1,
621+
ginfo,
623622
global_vars_seen_dict,
624623
is_filtered=is_filtered,
625624
)

0 commit comments

Comments
 (0)