This is an archive of the discontinued LLVM Phabricator instance.

[MSAN] Support load and stores of scalable vector types
ClosedPublic

Authored by reames on Mar 15 2023, 10:55 AM.

Details

Summary

This adds support for scalable vector types - at least far enough to get basic load and store cases working. It turns out that load/store without origin tracking already worked; I apparently got that working with one of the pre patches to use TypeSize utilities and didn't notice. The code changes here are required to enable origin tracking.

For origin tracking, a 4 byte value - the origin - is broadcast into a shadow region whose size exactly matches the type being accessed. This origin is only written if the shadow value is non-zero. The details of how shadow is computed from the original value being stored aren't relevant for this patch.

The code changes involve two related primitives.

First, we need to be able to perform that broadcast into a scalable sized memory region. This requires the use of a loop, and appropriate bound. The fixed size case optimizes with larger stores and alignment; I did not bother with that for the scalable case for now. We can optimize this codepath later if desired.

Second, we need a way to test if the shadow is zero. The mechanism for this in the code is to convert the shadow value into a scalar, and then zero check that. There's an assumption that this scalar is zero exactly when all elements of the shadow value are zero. As a result, we use an OR reduction on the scalable vector. This is analogous to how e.g. an array is handled. I landed a bunch of cleanup changes to remove other direct uses of the scalar conversion to convince myself there were no other undocumented invariants.

Diff Detail

Event Timeline

reames created this revision.Mar 15 2023, 10:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 15 2023, 10:55 AM
reames requested review of this revision.Mar 15 2023, 10:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 15 2023, 10:55 AM
vitalybuka added 1 blocking reviewer(s): vitalybuka.Mar 20 2023, 5:31 PM
vitalybuka added inline comments.
llvm/test/Instrumentation/MemorySanitizer/vector-load-store.ll
51

it should be sanitize_memory
can you please fix and regenerate the test separately?

530

I am confused, how passes=msan created asan calls?

vitalybuka added inline comments.Mar 20 2023, 7:15 PM
llvm/test/Instrumentation/MemorySanitizer/vector-load-store.ll
627

could you include these cases into precommited tests?

reames added inline comments.Mar 22 2023, 2:10 PM
llvm/test/Instrumentation/MemorySanitizer/vector-load-store.ll
51

Fixed in 473e9adb84c29764da51e4d2a995fce9b2e2ffa5, thanks for noticing.

530

This looks like a copy paste mistake on my part. update_test_checks.py doesn't strip out check lines which don't correspond to a run line, and I'd copied these from the ASAN test. Will fix and refresh.

627

Can't. We crash on scalable input types. That's the whole point of the patch.

reames updated this revision to Diff 507498.Mar 22 2023, 2:10 PM

Address review comment

vitalybuka accepted this revision.Mar 22 2023, 9:17 PM

Thanks!

This revision is now accepted and ready to land.Mar 22 2023, 9:17 PM
This revision was landed with ongoing or failed builds.Mar 23 2023, 7:38 AM
This revision was automatically updated to reflect the committed changes.