This is an archive of the discontinued LLVM Phabricator instance.

[GlobalOpt] Fix memset handling in global ctor evaluation (PR55859)
ClosedPublic

Authored by nikic on Jun 24 2022, 7:21 AM.

Details

Summary

The global ctor evaluator currently handles by checking whether the memset memory is already zero, and skips it in that case. However, it only actually check the first byte of the memory being set.

This patch extends the code to check all bytes being set. This is done byte-by-byte to avoid converting undef values to zeros in larger reads. However, the handling is still not completely correct, because there might still be padding bytes (though probably this doesn't matter much in practice, as I'd expect global variable padding to be zero-initialized in practice).

Mostly fixes https://github.com/llvm/llvm-project/issues/55859.

Diff Detail

Event Timeline

nikic created this revision.Jun 24 2022, 7:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 24 2022, 7:21 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
nikic requested review of this revision.Jun 24 2022, 7:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 24 2022, 7:21 AM
aeubanks accepted this revision.Jun 24 2022, 9:43 AM
aeubanks added inline comments.
llvm/lib/Transforms/Utils/Evaluator.cpp
453–454

why is this necessary?

463

are there any tests to test non-zero values?

This revision is now accepted and ready to land.Jun 24 2022, 9:43 AM
nikic marked an inline comment as done.Jun 27 2022, 7:47 AM
nikic added inline comments.
llvm/lib/Transforms/Utils/Evaluator.cpp
453–454

This is to handle address space casts that change the index size. However, it doesn't look like this needed here (because the called API doesn't require a specific width for the offset). I'll drop this for now.

463
This revision was landed with ongoing or failed builds.Jun 27 2022, 7:50 AM
This revision was automatically updated to reflect the committed changes.
nikic marked an inline comment as done.