This is an archive of the discontinued LLVM Phabricator instance.

[Attributor] Use ConstantFoldLoadFromConst()
ClosedPublic

Authored by nikic on Oct 7 2022, 2:59 AM.

Details

Summary

When determining the initial value of the object, use the constant folding API to load a given type at a given offset in the global initializer. This makes it work for cases where the load doesn't directly correspond to an aggregate member.

This appears to regress the static_global_simplifiable_2 test though, any idea why?

Diff Detail

Event Timeline

nikic created this revision.Oct 7 2022, 2:59 AM
Herald added a project: Restricted Project. · View Herald Transcript
nikic requested review of this revision.Oct 7 2022, 2:59 AM
Herald added a project: Restricted Project. · View Herald Transcript
jdoerfert accepted this revision.Oct 7 2022, 6:29 AM

LG, thanks! Wrt. regression problem see below.

llvm/lib/Transforms/IPO/Attributor.cpp
245

You exposed a bug, the above should be correct and avoid the regression. If we load any bytes from a null value we get null.

This revision is now accepted and ready to land.Oct 7 2022, 6:29 AM
nikic updated this revision to Diff 466065.Oct 7 2022, 6:47 AM

Fall back to ConstantFoldLoadFromUniformValue() if the offset is not known. This should handle various uniform cases like poison, undef and zeroinitializer.

This revision was automatically updated to reflect the committed changes.