Skip to content

Commit 3a4f47b

Browse files
committed
[AIEX] update_ore_test_checks: don't chain asm update for remark-only tests
With --update-llc-checks, update_ore_test_checks.py stripped the remark RUN lines and always invoked update_llc_test_checks.py. For a test whose only RUN lines are remark runs, that handed the sibling script a file with no RUN lines, which crashed in update_llc_test_checks.py main() with an UnboundLocalError (output_type is only bound inside the per-RUN-line loop). Fix it structurally at the orchestration layer: only delegate to the asm/MIR update script when the test actually has a non-remark RUN line to regenerate (has_asm_run_lines). A remark-only test now skips the asm step and just regenerates its remark CHECK lines. Add a regression test (x86-ore-chain-update-no-asm) covering a remark-only test updated with --update-llc-checks, including UTC_ARGS idempotency.
1 parent 02d28a4 commit 3a4f47b

4 files changed

Lines changed: 90 additions & 4 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2+
; See https://llvm.org/LICENSE.txt for license information.
3+
; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
;
5+
; (c) Copyright 2026 Advanced Micro Devices, Inc. or its affiliates
6+
7+
; RUN: llc -mtriple=x86_64-linux-gnu -pass-remarks-output=- -pass-remarks-filter=asm-printer %s -o /dev/null | FileCheck %s
8+
9+
; Regression fixture: a remark-only test (no asm RUN line) updated with
10+
; --update-llc-checks. The asm-update step has nothing to regenerate and must
11+
; be skipped, rather than stripping the remark RUN line and handing the sibling
12+
; update_llc_test_checks.py a file with no RUN lines (which crashed with
13+
; UnboundLocalError). Only REMARKS-style CHECK lines should be produced.
14+
15+
define i32 @add(i32 %a, i32 %b) {
16+
%c = add i32 %a, %b
17+
ret i32 %c
18+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_ore_test_checks.py UTC_ARGS: --update-llc-checks
2+
; This file is licensed under the Apache License v2.0 with LLVM Exceptions.
3+
; See https://llvm.org/LICENSE.txt for license information.
4+
; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
;
6+
; (c) Copyright 2026 Advanced Micro Devices, Inc. or its affiliates
7+
8+
; RUN: llc -mtriple=x86_64-linux-gnu -pass-remarks-output=- -pass-remarks-filter=asm-printer %s -o /dev/null | FileCheck %s
9+
10+
; Regression fixture: a remark-only test (no asm RUN line) updated with
11+
; --update-llc-checks. The asm-update step has nothing to regenerate and must
12+
; be skipped, rather than stripping the remark RUN line and handing the sibling
13+
; update_llc_test_checks.py a file with no RUN lines (which crashed with
14+
; UnboundLocalError). Only REMARKS-style CHECK lines should be produced.
15+
16+
define i32 @add(i32 %a, i32 %b) {
17+
; CHECK: --- !Analysis
18+
; CHECK-NEXT: Pass: asm-printer
19+
; CHECK-NEXT: Name: InstructionMix
20+
; CHECK-NEXT: Function: add
21+
; CHECK-NEXT: Args:
22+
; CHECK-NEXT: - String: 'BasicBlock: '
23+
; CHECK-NEXT: - BasicBlock: ''
24+
; CHECK-NEXT: - String: "\n"
25+
; CHECK-NEXT: - String: 'leal '
26+
; CHECK-NEXT: - String: ': '
27+
; CHECK-NEXT: - INST_leal: '1'
28+
; CHECK-NEXT: - String: "\n"
29+
; CHECK-NEXT: - String: retq
30+
; CHECK-NEXT: - String: ': '
31+
; CHECK-NEXT: - INST_retq: '1'
32+
; CHECK-NEXT: - String: "\n"
33+
; CHECK-NEXT: ...
34+
; CHECK: --- !Analysis
35+
; CHECK-NEXT: Pass: asm-printer
36+
; CHECK-NEXT: Name: InstructionCount
37+
; CHECK-NEXT: Function: add
38+
; CHECK-NEXT: Args:
39+
; CHECK-NEXT: - NumInstructions: '2'
40+
; CHECK-NEXT: - String: ' instructions in function'
41+
; CHECK-NEXT: ...
42+
%c = add i32 %a, %b
43+
ret i32 %c
44+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# REQUIRES: x86-registered-target
2+
## Remark-only test (no asm RUN line) updated with --update-llc-checks. The
3+
## asm-update step must be skipped because there is nothing to regenerate;
4+
## previously it stripped the remark RUN line and crashed the sibling
5+
## update_llc_test_checks.py with an UnboundLocalError on an empty run list.
6+
7+
# RUN: cp -f %S/Inputs/x86-ore-chain-update-no-asm.ll %t.ll && %update_ore_test_checks --update-llc-checks %t.ll
8+
# RUN: diff -u %S/Inputs/x86-ore-chain-update-no-asm.ll.expected %t.ll
9+
10+
## Idempotency via UTC_ARGS (no --update-llc-checks on the command line):
11+
# RUN: %update_ore_test_checks %t.ll
12+
# RUN: diff -u %S/Inputs/x86-ore-chain-update-no-asm.ll.expected %t.ll

llvm/utils/update_ore_test_checks.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ def split_pipeline(run_line):
210210
return stages
211211

212212

213+
def has_asm_run_lines(run_lines):
214+
"""True if any RUN line is a non-remark run the sibling asm/MIR update
215+
script can regenerate. A test whose RUN lines are all remark runs has no
216+
assembly to update, so the sibling script must not be invoked on it (after
217+
the remark runs are stripped it would see a file with no RUN lines)."""
218+
return any(not PASS_REMARKS_OUTPUT_RE.search(rl) for rl in run_lines)
219+
220+
213221
def parse_remark_runs(run_lines, test_path):
214222
"""Identify RUN lines that produce remark YAML output.
215223
@@ -522,15 +530,19 @@ def main():
522530
else:
523531
asm_flag = parse_utc_args(first_line)
524532

525-
# Optionally regenerate assembly CHECK lines first.
526-
if asm_flag:
533+
run_lines = common.find_run_lines(test_path, input_lines)
534+
535+
# Regenerate assembly CHECK lines first, but only when there is a
536+
# non-remark RUN line to regenerate. Delegating for a remark-only test
537+
# would hand the sibling script a file with no RUN lines.
538+
if asm_flag and has_asm_run_lines(run_lines):
527539
invoke_asm_update_script(test_path, args.llc_binary, asm_flag)
528540

529-
# Re-read the file after the asm script rewrote it.
541+
# Re-read the file (and its RUN lines) after the asm script rewrote it.
530542
with open(test_path) as f:
531543
input_lines = [l.rstrip() for l in f]
544+
run_lines = common.find_run_lines(test_path, input_lines)
532545

533-
run_lines = common.find_run_lines(test_path, input_lines)
534546
remark_runs = parse_remark_runs(run_lines, test_path)
535547

536548
if not remark_runs:

0 commit comments

Comments
 (0)