This is an archive of the discontinued LLVM Phabricator instance.

[Utils] Replace llc with cat for tests
ClosedPublic

Authored by sebastian-ne on Sep 21 2021, 3:02 AM.

Details

Summary

Make the update_llc_test_checks script test independant of llc behavior
by using cat with static files to simulate llc output.

This allows changing llc without breaking the script test case.

The update script is executed in a temporary directory, so the
llc-generated assembly files are copied there. %T is deprecated, but it
allows copying a file with a predictable filename.

Diff Detail

Event Timeline

sebastian-ne created this revision.Sep 21 2021, 3:02 AM
sebastian-ne requested review of this revision.Sep 21 2021, 3:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 21 2021, 3:02 AM
foad added a comment.Sep 21 2021, 3:06 AM

Looks great, thanks! Will it work on Windows?

arichardson added inline comments.Sep 21 2021, 3:09 AM
llvm/utils/update_llc_test_checks.py
94 ↗(On Diff #373828)

Doing this in common.py would also fix the other update scripts instead of having to duplicate it everywhere.

Also I wonder if we defer to lit's expansion code instead of re-implementing lit features here?

arichardson requested changes to this revision.Sep 21 2021, 3:11 AM
arichardson added inline comments.
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/amdgpu-no-merge-comments.test
5

IMO this should be in a separate test file since it's not checking "that functions with different IR comments in the output are not merged" but instead is checking the %S lit substitution

This revision now requires changes to proceed.Sep 21 2021, 3:11 AM
sebastian-ne marked an inline comment as done.

Implement substitutions in common.py.

Also I wonder if we defer to lit's expansion code instead of re-implementing lit features here?

That would be nice, but changing that is more involved.

llvm/test/tools/UpdateTestChecks/update_llc_test_checks/amdgpu-no-merge-comments.test
5

Thanks for your review!

This is still testing "that functions with different IR comments in the output are not merged" with the %update_llc_test_checks --llc-binary cat %t.ll command.
The %S substitution in this file was working before (it is already used before this patch).
The two copies of the .s files are needed because %update_llc_test_checks is run on a temporary file in build/test/tools/UpdateTestChecks/update_llc_test_checks/Output/ and the tested .ll file amdgpu_no_merge_comments.ll expects the two .s files to be in the same directory.

The added %S support is only for running %update_llc_test_checks. The two RUN lines in amdgpu_no_merge_comments.ll are exercising this code (although not exactly for testing, but through necessity to somehow reference the .s files).

Remove left over dead code

foad added a comment.Sep 21 2021, 5:34 AM

Implement substitutions in common.py.

Does that mean they can be removed from the individual update_* tools? I guess that can be done as follow-ups.

Implement substitutions in common.py.

Does that mean they can be removed from the individual update_* tools? I guess that can be done as follow-ups.

Most update scripts don’t apply these substitution so far. update_cc_test_checks.py doesn’t use the common functions to start the process, but it could use get- and applySubstitutions.
I’ll do a follow-up if this gets merged.

foad accepted this revision.Sep 21 2021, 6:02 AM

Looks fine to me once @arichardson is happy.

arichardson accepted this revision.Sep 21 2021, 6:27 AM

Thanks for moving it to common. This generally LGTM just a suggestion to avoid %T.

All the other update scripts seem to use invoke_tool() so we should be able to drop %s handling from those scripts too? I guess substitution twice doesn't do any harm but it would be good to remove duplication to make future refactoring easier.

llvm/test/tools/UpdateTestChecks/update_llc_test_checks/amdgpu-no-merge-comments.test
5

I would try to avoid the %T substitituion here, can you use %t.ll-O3.s and %t.ll-0O.s? Then it should be possible to use %s-O3.s in the tests instead of %S?

I think it might also make sense to add a comment above this RUN line. Maybe something like
We override the llc binary with cat to make this test independent of future amdgpu assembly output changes?

This revision is now accepted and ready to land.Sep 21 2021, 6:27 AM

Good idea, I added a comment.

All the other update scripts seem to use invoke_tool() so we should be able to drop %s handling from those scripts too? I guess substitution twice doesn't do any harm but it would be good to remove duplication to make future refactoring easier.

%s is not substituted in the scripts (except update_cc_test_checks.py), it is just removed with .replace('< %s', '').replace('%s', ''). We can move that to invoke_tool() if you think it makes sense?

Then it should be possible to use %s-O3.s in the tests instead of %S?

I tried exactly that before, but for the above reason, that %s is removed and not substituted, this doesn’t work (it tries to run cat -03.s).

Good idea, I added a comment.

All the other update scripts seem to use invoke_tool() so we should be able to drop %s handling from those scripts too? I guess substitution twice doesn't do any harm but it would be good to remove duplication to make future refactoring easier.

%s is not substituted in the scripts (except update_cc_test_checks.py), it is just removed with .replace('< %s', '').replace('%s', ''). We can move that to invoke_tool() if you think it makes sense?

Then it should be possible to use %s-O3.s in the tests instead of %S?

I tried exactly that before, but for the above reason, that %s is removed and not substituted, this doesn’t work (it tries to run cat -03.s).

Does the following work:

# RUN: cp -f %S/Inputs/amdgpu_no_merge_comments-O0.s %t-O0.s && cp -f %S/Inputs/amdgpu_no_merge_comments-O3.s %t-O3.s
# RUN: cp -f %S/Inputs/amdgpu_no_merge_comments.ll %t.ll && %update_llc_test_checks --llc-binary cat %t.ll
# RUN: diff -u %S/Inputs/amdgpu_no_merge_comments.ll.expected %t.ll

And then inside the actual test

; llc is replaced with cat, we just simulate llc by printing text from these files
; RUN: llc %S/amdgpu_no_merge_comments.tmp-O0.s | FileCheck -check-prefixes=GCN,GFX9-O0 %s
; RUN: llc %S/amdgpu_no_merge_comments.tmp-O3.s | FileCheck -check-prefixes=GCN,GFX9-O3 %s

Not sure if that's much better than depending on %T though.

llvm/utils/UpdateTestChecks/common.py
174

Just noticed that we should also be using applySubstitutions here.

sebastian-ne marked an inline comment as done.

Use applySubstitutions in one more place.

Not sure if that's much better than depending on %T though.

Ideally the update scripts would share the code with the lit script and we coud just use %t.
I’ll leave it at %T for now because that doesn’t depend on implementation details.

This revision was landed with ongoing or failed builds.Sep 22 2021, 1:10 AM
This revision was automatically updated to reflect the committed changes.