235 Commits

Author SHA1 Message Date
David Sherwood
194eceff43
update_test_checks: add new --filter-out-after option (#129739)
Whilst trying to clean up some loop vectoriser IR tests (see
test/Transforms/LoopVectorize/AArch64/partial-reduce-chained.ll
for example) a reviewer on PR #129047 suggested it would be
nice to have an option to stop generating CHECK lines after a
certain point. Typically when performing a transformation with
the loop vectoriser we don't usually care about any CHECK lines
generated for the scalar tail of the loop, since the scalar
loop is kept intact. Previously if you wanted to eliminate such
unwanted CHECK lines you had to run the update script, then
manually delete all the lines corresponding to the scalar loop.
This can be very time consuming if the tests ever need changing.

What I've tried to do here is add a new --filter-out-after
option alongside the existing --filter* options that provides
support for stopping the generation of any CHECK lines beyond
the line that matches the filter. With the existing filter
options we never generate CHECK-NEXT lines, but we still care
about ordering with --filter-out-after so I've amended the
code to ensure we treat this filter differently.
2025-03-18 09:46:43 +00:00
Jinsong Ji
5d4998bc02
UpdateTestChecks: Don't check meta details in func definition w/--global none (#124205)
When --check-globals none, we skipped all the globals in check lines.
However, we are still checking the meta info in function defintion.

The generated checks are still sensitive to metadata changes.

This is to scrub the meta info and match them with {{.*}} instead.
2025-02-19 20:29:51 -05:00
Sebastian Pop
46f9cddfd7
[DA] enable update_analyze_test_checks.py (#123435)
Modify the DA pretty printer to match the output of other analysis
passes. This enables update_analyze_test_checks.py to also work on DA
tests. Auto generate all the Dependence Analysis tests.
2025-01-29 15:40:22 -06:00
Momchil Velikov
5315f3f8cb
Handle leading underscores in update_cc_test_checks.py (#121800)
For some ABIs `update_cc_test_checks.py` is unable to generate tests
because of the mismatch between the mangled function names reported by
clang's `-asd-dump` and the function names in LLVM IR.

This patch fixes it by striping the leading underscore from the mangled
name for global functions if the data layout string says they have one.
2025-01-13 11:24:05 +00:00
Jessica Del
d07762e474
[UpdateTestChecks][NFC] - Fix typos (#121964)
substition -> substitution
in-betweem -> in-between
2025-01-08 14:24:39 +01:00
Sergei Barannikov
b3363104d3
[UTC] Add support for Xtensa (#117441)
Regenerate the failing test as well.
2024-11-23 20:43:05 +03:00
Brox Chen
6f973fd4ab
[AMDGPU][test] fix the error case in update_mc_test_check script (#112731)
update_mc_test_check script handle the "error case testline" wrong in
three cases:

1. when user select "--llvm-mc-binary" with a path, the script does not
add "not" on top of the "--llvm-mc-binary" and thus getting non-zero
exit code and failed.
2. When "not" is presented in runline while not all testlines are
expected to fail, the script need to check if the "not" is needed when
it execute llvm-mc line by line. Otherwise the script will fail on
testline which is passing.
3. When there are multiple runlines, the error checkline need to use
correct line offset for "[[LINE-X]]"

This patch solve these three issues
2024-10-30 09:02:40 -04:00
Brox Chen
528e975ac4
[AMDGPU][test]added unique and sort options for update_mc_test_check script (#111769)
add a unique and a sort option to the update_mc_test_check script.

These mc asm/dasm files are usually large in number of lines, and these
lines are mostly similar to each other. These options can be useful when
maintainer is merging or resolving conflicts by making the file
identifical

Also fixed a small issue in asm/dasm such that the auto generated header
line is
1. asm using ";" instead of "//" as comment marker
2. dasm using ";" instead of "#" as comment marker
2024-10-29 13:48:43 -04:00
Nicolai Hähnle
ae6af37bf4
update_test_checks: fix a simple regression (#111347)
Reported-by: Yingwei Zheng <dtcxzyw2333@gmail.com>
Fixes: 02debcef12793b5 ("update_test_checks: improve IR value name
stability (#110940)")
2024-10-07 11:45:44 +02:00
Nicolai Hähnle
9f3f76a6b4
update_test_checks: collect original check lines for old versions of lit tests (#111148)
Old versions of UTC produced function labels like:

    ; CHECK-LABEL: @func(

Fix the regular expression used when scanning for old check lines to
recognize this form of label.

This allows meta variable stability to apply when running UTC on tests
using this form of label.

Reported-by: Nikita Popov <npopov@redhat.com>
2024-10-04 16:31:42 +02:00
Nicolai Hähnle
02debcef12
update_test_checks: improve IR value name stability (#110940)
By default, UTC attempts to keep the produced diff small by keeping IR
value name variables stable. The old algorithm was roughly:

1. Compute a diff between the old and new check lines, where
   "uncommitted" variable names are replaced by a wildcard.
   This leads to a set of non-crossing "candidate" pairs of
   (old line, new line) that we can try to make equal.

2. Greedily walk this list of candidates, committing to variable names
   that make candidate lines equal if possible.

The greedy approach in the second step has the downside that committing
to a variable name greedily can sometimes prevent many subsequent
candidates from getting the variable name assignment that would make
them equal.

We keep the first step as-is, but replace the second one by an algorithm
that finds a large independent set of candidates, i.e. candidate pairs
of (old line, new line) which are non-conflicting in the sense that
their desired variable name mappings are not in conflict.

We find the large independent set by greedily assigning a coloring to
the conflict graph and taking the largest color class. We then commit to
all the variable name mappings which are desired by candidates in this
largest color class.

As before, we then recurse into regions between matching lines. This is
required in large cases. For example, running this algorithm at the
top-level of the new test case (stable_ir_values5.ll) matches up most of
the instructions, but not the names of the result values of all the
`load`s. This is because (unlike e.g. the getelementptrs) the load
instructions are all equal except for variable names, and so step 1 (the
diff algorithm) doesn't consider them as candidates. However, they are
trivially matched by recursion.

This also happens to fix a bug in tracking line indices that went
unnoticed previously...

As is usually the case with these changes, the quality improvement is
hard to see from the diff of this patch. However, it becomes obvious
when
comparing the diff of stable_ir_values5.ll against
stable_ir_value5.ll.expected
before and after this change.
2024-10-04 14:51:12 +02:00
Brox Chen
2b892b0502
added a script to update llvm-mc test file (#107246)
Added a script to update the test file generated by llvm-mc binary. The
script accepts .s and .txt for asm and dasm.

For mc test I am targetting there is no function name which can be used
as a key, thus no clear mapping between input and output. The script
assumes the test are always line-by-line and it update the output marker
for each test line-by-line.

---------

Co-authored-by: Alexander Richardson <mail@alexrichardson.me>
2024-09-23 15:27:41 -04:00
Nicolas van Kempen
c49770c60f
[NFC] Prefer subprocess.DEVNULL over os.devnull (#106500)
There is no need to support Python 2.7 anymore, Python 3.3+ has
`subprocess.DEVNULL`. This is good practice and also prevents file
handles from
staying open unnecessarily.

Also remove a couple unused or unneeded `__future__` imports.
2024-08-30 19:26:49 +01:00
Denis.G
2d1fba67c5
[NVPTX] Support __usAtomicCAS builtin (#99646)
Supported `__usAtomicCAS` builtin originally defined in
`/usr/local/cuda/inlcude/crt/sm_70_rt.hpp`

---------

Co-authored-by: Denis Gerasimov <Denis.Gerasimov@baikalelectronics.ru>
Co-authored-by: Gonzalo Brito Gadeschi <gonzalob@nvidia.com>
Co-authored-by: Denis.Gerasimov <dengzmm@gmail.com>
2024-08-28 12:01:35 -07:00
Juan Manuel Martinez Caamaño
d38bae3c77
[update_llc_test_checks][AMDGPU] Update AMDGPU regexp in update_llc_test_checks.py (#102480)
Updating `llvm/test/CodeGen/AMDGPU/GlobalISel/extractelement.ll` with
`update_llc_test_checks.py` ended with several kernels with no checks.

Llc's output contained the line ".amdgpu_hsa_kernel <funcname>" after
the ".type <funcname>,@function" entry which was not considered by the
regexp.
2024-08-09 09:33:31 +02:00
Ramkumar Ramachandra
915ee0b823
UTC: support debug output from LDist (#93208)
Tweak the LoopDistribute debug output to be prefixed with "LDist: ", get
it to be stable, and extend update_analyze_test_checks.py trivially to
support this output.
2024-07-03 10:50:52 +01:00
Jon Roelofs
e325e2e592
update_test_checks: drop the other arm64_32 handlers 2024-06-04 07:25:38 -07:00
Jon Roelofs
4ee950e75d
update_test_checks: support more arm64_32-apple-watchos triples
Having the version in `get_run_handlers` meant that a RUN line without the
version in it would not match, and therefore UTC would generate a useless
catch-all check of the form:

```
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
; CHECK: {{.*}}
```

This patch also adds `arm64_32` as a base-level run handler, and assumes it
will always apply to a darwin target (which is currently the case for all
arm64_32-* triples I see in tree currently).
2024-06-03 15:34:06 -07:00
Nicolai Hähnle
34388f986a
update_llc_test_checks: better support for non-llc tools (#93135)
A full downstream fork can already hack up update_llc_test_checks.py to
support custom tools that output assembly.

An out-of-tree frontend which is meant to build against upstream
llvm-project cannot do this, and so providing additional arguments to
support a non-standard tool is useful.

This also makes a minor adjustment to the regular expression for
matching AMDGPU functions when fewer comments are enabled, which happens
to be the case for our out-of-tree shader compiler (which motivated this
change).
2024-05-27 19:17:04 +02:00
Eli Friedman
779be6fd1d
Fix update-test-checks.py on Python 3.6 (#93116)
re.Match apparently doesn't exist in older versions.
2024-05-23 10:35:53 -07:00
Nicolai Hähnle
597ac471cc
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.
2024-05-19 01:39:47 +02:00
Stephen Tozer
a634f3ef39
[RemoveDIs] Update update_test_checks script to recognize dbg_records (#87388)
As we've added new IR elements for the RemoveDIs project,
we need the update_test_checks script to understand them. For the
records themselves this is already done automatically, but their
metadata arguments are not recognized as such due to lacking the
`metadata` prefix, which means they won't be checked by the script. This
patch fixes this by adding a check for all `![0-9]+` patterns as long as
they are not at the start of a line (which avoids matching global
values).
2024-04-17 11:39:18 +01:00
Nicolai Hähnle
f4737a2edd
update_test_checks: keep names stable with generated functions (#87988)
Collect the original check lines in a manner that is independent of
where the check lines appear in the file. This is so that we keep
FileCheck variable names stable even when --include-generated-funcs is
used.

Reported-by: Ruiling Song <ruiling.song@amd.com>
2024-04-17 12:24:32 +02:00
Nicolai Hähnle
377a2767a9 update_test_checks: remove an unused function 2024-04-16 22:04:33 +02:00
Nicolai Hähnle
3846019d8f 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.
2024-03-08 04:33:38 +01:00
Nicolai Hähnle
b565126b4d Revert "update_test_checks: keep meta variables stable by default"
This reverts commit fb02f9ac84a6151e41aba8f7391edd132a9aaf14.

Looks like some Python version incompatibility, will investigate.
2024-03-08 04:25:07 +01:00
Nicolai Hähnle
fb02f9ac84 update_test_checks: keep meta variables stable by default
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.
2024-03-08 03:58:12 +01:00
Nicolai Hähnle
5747f9d3e9 update_test_checks: simplify get_ir_regex
The match argument isn't used.
2024-03-08 03:58:11 +01:00
Nicolai Hähnle
fc1e5f9785 update_test_checks: simplify is_local_def_ir_value
The match argument is unused.
2024-03-08 03:58:11 +01:00
Henrik G. Olsson
6a65b44322
[UTC] Don't leave dangling CHECK-SAME when removing CHECK lines (#82569)
When removing only lines that are global value CHECK lines, a related
CHECK-SAME line could be left dangling without a previous line to belong
to.

Resolves #78517
2024-02-28 17:08:36 -08:00
Luke Lau
283a6b9936
[UTC] Fix SyntaxWarning on Python 3.12 (#82327)
On Python 3.12 we now get a warning in common.py:

llvm/utils/UpdateTestChecks/common.py:488: SyntaxWarning: invalid escape
sequence '\s'

This fixes it by using a raw string literal, see
https://github.com/llvm/llvm-project/pull/78036 and
https://docs.python.org/3/library/re.html
2024-02-20 17:36:01 +08:00
Yi Kong
d6c2cbbc65
Fix test failure if CLANG_VENDOR contains spaces (#81017) 2024-02-08 07:31:34 +09:00
James Y Knight
31aebdd891
Include LLVM_VERSION_SUFFIX in the Clang version string. (#74469)
This causes current mainline to now report "18.0.0git" instead of
"18.0.0".

Fixes #53825
2023-12-05 12:20:12 -05:00
Florian Hahn
08a6968127
[UTC] Support arm64-apple-macosx in update_llc_test_checks.py. (#73568)
arm64-apple-macosx is the default triple (usually with the macOS version
number) on arm64 macOS. Support it in update_llc_test_checks.py.
2023-11-28 10:06:20 +00:00
Matthias Braun
331111277a
Support BranchProbabilityInfo in update_analyze_test_checks.py (#72943)
- Change `BranchProbabilityPrinterPass` output to match expectations of `update_analyze_test_checks.py`.
- Add `Branch Probability Analysis` to list of supported analyses.
- Process `llvm/test/Analysis/BranchProbabilityInfo/basic.ll` with `update_analyze_test_checks.py` as proof of concept. Leaving the other tests unchanged to reduce the amount of churn.
2023-11-21 17:08:44 -08:00
Henrik G. Olsson
e6eda66cbc
Recommit changes to global checks (#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.
2023-11-13 14:45:27 +01:00
Florian Hahn
24839c3253
[UTC] Escape multiple {{ or }} in input for check lines. (#71790)
SCEV expressions may contain multiple {{ or }} in the debug output,
which needs escaping.

See
llvm/test/Analysis/LoopAccessAnalysis/loops-with-indirect-reads-and-writes.ll
for a test that needs escaping.
2023-11-09 17:18:11 +00:00
Ramkumar Ramachandra
4c01a58008
update_analyze_test_checks: support output from LAA (#67584)
update_analyze_test_checks.py is an invaluable tool in updating tests.
Unfortunately, it only supports output from the CostModel,
ScalarEvolution, and LoopVectorize analyses. Many LoopAccessAnalysis
tests use hand-crafted CHECK lines, and it is moreover tedious to
generate these CHECK lines, as the output fom the analysis is not
stable, and requires the test-writer to hand-craft FileCheck matches.
Alleviate this pain, and support output from:

  $ opt -passes='print<loop-accesses>'

This patch includes several non-trivial changes including:
- Preserving whitespace at the beginning of the line, so that the LAA
output can be properly indented.
- Regexes matching the unstable output, which is basically a pointer
address hex.
- Separating is_analyze from preserve_names clearly, as the former was
formerly used as an overload for the latter.

To demonstate the utility of this patch, several tests in
LoopAccessAnalysis have been auto-generated by
update_analyze_test_checks.py.
2023-10-31 14:33:53 +00:00
Henrik G. Olsson
da28c33094
[UTC] Recognise CHECK lines with globals matched literally (#70050)
Previously when using `-p` a.k.a. `--preserve-names` existing lines for
checking globals were not recognised as such, leading to the line being
kept while also being emitted again, resulting in duplicated CHECK
lines.

This resolves #70048.
2023-10-30 13:17:26 +01:00
Ramkumar Ramachandra
ac466c7525
UpdateTestChecks: squelch warning on SCEV output (#67443)
update_analyze_test_checks.py currently outputs a warning when updating
a script with the run line:

  $ opt -passes='print<scalar-evolution>'

saying that the script doesn't support its output, when it indeed does,
as evidenced by several tests in test/Analysis/ScalarEvolution generated
by this script. There is even a test for update_analyze_test_checks that
makes sure that SCEV output is supported. Hence, squelch the warning.

While at it, rename the update_analyze_test_checks test from basic.ll to
a more explicit scev.ll.
2023-09-26 19:40:13 +01:00
Paulo Matos
0495cd89fc
[UpdateTestChecks] Add support for SPIRV in update_llc_test_checks.py (#66213)
Support for SPIRV added, updated test SPV_INTEL_optnone.ll using the script.

Previously https://reviews.llvm.org/D157858
2023-09-21 12:51:42 +02:00
Jannik Silvanus
998c323910 [UTC] Keep function args parenthesis on label line (bumps version to 3)
If the function argument block contains patterns, we split argument
matching into a separate SAME line, because LABEL labels may not contain
pattern matches.

Until now, in this case we moved the parenthesis opening the argument block
into the second line.

This generates incorrect labels in case function names are not prefix-free.

For example, for a function `foo` we generated:

   CHECK-LABEL: foo
   CHECK-SAME: (<args of foo>)

If the output also contains a function `foo.specialzied`, then the label for
`foo` can match `foo.specialized`, depending on output order.

This patch moves opening parenthesis to the first line, breaking common prefixes:

   CHECK-LABEL: foo(
   CHECK-SAME: <args of foo>)

Bump the UTC version to 3, and only move the parenthesis for version 3 and later.

Differential Revision: https://reviews.llvm.org/D158497
2023-08-29 16:40:06 +02:00
Johannes Doerfert
dcd4d0a790 [UTC] Honor global-value-regex in UTC_ARGS
Without this we cannot update various clang OpenMP tests as the UTC_ARGS
version of -global-value-regex is simply ignored. The handling of the
flag should be changed to be in line with others, I left TODOs for now.
2023-08-23 10:40:30 -07:00
Johannes Doerfert
b9f1df7a04 Revert "[UTC] Add fallback support for specific metadata, and check their defs"
This reverts commit 8a3fdf7b908978625e9a7e57fbb443e4e6f98976 as it is
broken. See https://github.com/llvm/llvm-project/issues/63746.

Effectively fixes: https://github.com/llvm/llvm-project/issues/63746
2023-07-14 13:53:37 -07:00
Johannes Doerfert
75836eb952 Revert "[UTC] Fix git URL regex"
This reverts commit 6d64faf3b1d96f4dba8c2c46b8b65f1cc978e82b, as it is
built on top of https://reviews.llvm.org/D148216 which is broken.

See also https://github.com/llvm/llvm-project/issues/63746
2023-07-14 13:53:37 -07:00
Johannes Doerfert
c1b1c40920 Revert "[UTC] Generalize version regex"
This reverts commit 4488ee259064532dda24024a7e96037fe9a3c0d9, as it is
built on top of https://reviews.llvm.org/D148216 which is broken.

See also https://github.com/llvm/llvm-project/issues/63746
2023-07-14 13:53:36 -07:00
Johannes Doerfert
5b8b9b39cc Revert "[UTC] Adapt version matcher to glob CLANG_VENDOR"
This reverts commit 68f5d1be3d8f9b2ee2f25098203b24a32057b4e6 as it is
built on top of https://reviews.llvm.org/D148216 which is broken.

See also https://github.com/llvm/llvm-project/issues/63746
2023-07-14 13:53:36 -07:00
Paul Robinson
c2bed2a170 [UTC] Add do-not-autogenerate capability
Differential Revision: https://reviews.llvm.org/D154383
2023-07-06 10:56:42 -07:00
Henrik G. Olsson
68f5d1be3d [UTC] Adapt version matcher to glob CLANG_VENDOR
Both the pattern for finding the clang version metadata, and the emitted
checker, are now more robust, to handle a vendor prefix.

Differential Revision: https://reviews.llvm.org/D154520
2023-07-05 17:10:47 +00:00
Nikita Popov
4488ee2590 [UTC] Generalize version regex
The suffix for the git revision may not be present (or may not be
a git revision).
2023-07-05 16:15:47 +02:00