This is an archive of the discontinued LLVM Phabricator instance.

MemTag: stack initializer merging.
ClosedPublic

Authored by eugenis on Aug 13 2019, 2:06 PM.

Details

Summary

MTE provides instructions to update memory tags and data at the same
time. This change makes use of those to generate more compact code for
stack variable tagging + initialization.

We collect memory store and memset instructions following an alloca or a
lifetime.start call, and replace them with the corresponding MTE
intrinsics. Since the intrinsics work on 16-byte aligned chunks, the
stored values are combined as necessary.

Diff Detail

Repository
rL LLVM

Event Timeline

eugenis created this revision.Aug 13 2019, 2:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 13 2019, 2:06 PM
pcc added inline comments.Aug 15 2019, 4:28 PM
llvm/lib/Target/AArch64/AArch64StackTagging.cpp
196 ↗(On Diff #214915)

This could call emitUndef, right? Is there an advantage in using STZG instead of STG here, and if so, should we be doing the same thing on line 181?

eugenis marked an inline comment as done.Aug 15 2019, 4:52 PM
eugenis added inline comments.
llvm/lib/Target/AArch64/AArch64StackTagging.cpp
196 ↗(On Diff #214915)

No, because memset(0) does not update Out[] (see applyMemset), so we don't know if the tail is zero or undef. Line 181 is different - with Ranges.empty() we know that the entire allocation is undef.

If we wanted to change this, Out[] would need to remember which bytes have been written to in a separate mask.

I did not do this because STG and STGZ are expected to have approximately same overhead.

pcc accepted this revision.Aug 15 2019, 5:23 PM

LGTM

llvm/lib/Target/AArch64/AArch64StackTagging.cpp
196 ↗(On Diff #214915)

I see. I'd probably leave a comment about that here.

I guess an alternative would be to eliminate this special case by also making memset(0) update Out. Probably doesn't matter much for now, though.

253 ↗(On Diff #214915)

Is there test coverage for this code? Please add if not.

338 ↗(On Diff #214915)

Remove braces

This revision is now accepted and ready to land.Aug 15 2019, 5:23 PM
eugenis updated this revision to Diff 215974.Aug 19 2019, 1:31 PM
eugenis marked 2 inline comments as done.

addressed review comments

eugenis marked an inline comment as done.Aug 19 2019, 1:32 PM
This revision was automatically updated to reflect the committed changes.