This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Allow IntegerAttr to parse zero width integers.
ClosedPublic

Authored by stellaraccident on Dec 30 2021, 8:02 AM.

Details

Summary

https://reviews.llvm.org/D109555 added support to APInt for this, so the special case to disable it is no longer valid. It is in fact legal to construct these programmatically today, and they print properly but do not parse.

Justification: zero bit integers arise naturally in various bit reduction optimization problems, and having them defined for MLIR reduces special casing.

I think there is a solid case for i0 and ui0 being supported. I'm less convinced about si0 and opted to just allow the parser to round-trip values that already verify. The counter argument is that the proper singular value for an si0 is -1. But the counter to this counter is that the sign bit is N-1, which does not exist for si0 and it is not unreasonable to consider this non-existent bit to be 0. Various sources consider it having the singular value "0" to be the least surprising.

Diff Detail

Event Timeline

stellaraccident requested review of this revision.Dec 30 2021, 8:02 AM
lattner accepted this revision.Dec 30 2021, 11:09 AM

Awesome, thank you for this. I think that it makes sense to allow si0 in addition to ui0 and i0. The interpretation of that is clear by itself - operations (like sign extend / cast) can choose to be defined or not on si0 based on their own constraints.

Thanks!

This revision is now accepted and ready to land.Dec 30 2021, 11:09 AM