This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Add Defs=[NZCV] to MTE loop pseudos.
ClosedPublic

Authored by simon_tatham on Aug 18 2023, 2:16 AM.

Details

Summary

The STGloop family of pseudo-instructions all expand to a loop which
iterates over a region of memory setting all its MTE tags to a given
value. The loop writes to the flags in order to check termination. But
the unexpanded pseudo-instructions were not marked as modifying the
flags. Therefore it was possible for one to end up in a location where
the flags were live, and then the loop would corrupt them.

We spotted the effect of this in a libc++ test involving a lot of
complicated inlining, and haven't been able to construct a smaller
test case that demonstrates actual incorrect output code. So my test
here is just checking that implicit-def $nzcv shows up on the
pseudo-instructions as they're output from isel.

Diff Detail

Event Timeline

simon_tatham created this revision.Aug 18 2023, 2:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 18 2023, 2:16 AM
simon_tatham requested review of this revision.Aug 18 2023, 2:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 18 2023, 2:16 AM
DavidSpickett added inline comments.Aug 18 2023, 2:40 AM
llvm/test/CodeGen/AArch64/memtag-loop-nzcv.ll
2

Any reason not to do the usual ... | FileCheck %s ...?

10

Add the reason here? of $nzcv because...

15

Might not be needed due to -mtriple above.

simon_tatham marked 3 inline comments as done.

Applied review suggestions in the test.

llvm/test/CodeGen/AArch64/memtag-loop-nzcv.ll
2

I cribbed the RUN line from an existing test using -print-after-isel. It did that because -print-after-isel outputs to stderr, not stdout. But I suppose if we don't also need the stdout, we can use 2>&1 |. I'll do that.

DavidSpickett accepted this revision.Aug 18 2023, 2:55 AM

I thought maybe the test input could be smaller, but it would look less like the actual use case, be more confusing and be prone to breaking randomly. So keep it as is.

This all LGTM.

This revision is now accepted and ready to land.Aug 18 2023, 2:55 AM

Though, should you check for the STZGloops as well? Not sure if you can reliably trigger that, maybe the clearing of tags here uses it but equally it could use STGloop with a tag value of 0.

They're all in the same group so not covering the Z variant isn't that big of a risk.

I agree that it would be nice to test all four pseudos if possible, but I don't know how to generate the other two. The clearing of the tags on function exit in this example is done by the STGloop shown in my CHECK line, so if that didn't cause an STZGloop of any kind then I don't know what would.

I also agree that it's not vital, since the same code change affects all four pseudos in any case.

Closest I found was llvm/test/CodeGen/AArch64/settag.ll but that's just one set not a loop.

Well anyway, all my comments have been addressed.

This revision was landed with ongoing or failed builds.Aug 21 2023, 1:17 AM
This revision was automatically updated to reflect the committed changes.

Cross-reference: this bug was already reported as https://github.com/llvm/llvm-project/issues/64309 (but I only just found out about that).