This is an archive of the discontinued LLVM Phabricator instance.

[Attributes] Update Attribute::get API to consider zero value for int attributes
AbandonedPublic

Authored by anna on Apr 20 2022, 12:26 PM.

Details

Summary

This patch allows Attribute::get API to consider zero for the uint64_t
argument passed in for int attributes.
Until now, the implicit assumption was that if the value is zero, then
it is an enum attribute. However, we can have cases (such a case exists
downstream for us), where an int attribute can have a zero value.

I initially tried Optional<uint64_t> instead of adding an extra default
argument. However there are places in Attributor where we pass in an enum
attribute with a zero value (see IRPosition::getAttrsFromAssumes). So the
alternate approach is recognize such cases and pass in None as the optional
argument (see D124116 for the idea).

Diff Detail

Event Timeline

anna created this revision.Apr 20 2022, 12:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 20 2022, 12:26 PM
anna requested review of this revision.Apr 20 2022, 12:26 PM
Herald added a reviewer: baziotis. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript

I would prefer to split this into two overloads, one without the uint64_t argument creating an enum attribute and one with creating always an int attribute, and fix up any problematic uses accordingly. The current approach leaves behind a footgun if we start actually using zero values for int attributes (something that we are careful not to do currently).

anna edited the summary of this revision. (Show Details)Apr 20 2022, 12:33 PM
anna added a comment.Apr 20 2022, 12:38 PM

I would prefer to split this into two overloads, one without the uint64_t argument creating an enum attribute and one with creating always an int attribute, and fix up any problematic uses accordingly. The current approach leaves behind a footgun if we start actually using zero values for int attributes (something that we are careful not to do currently).

Actually, yes the overload is a better idea.

The current approach leaves behind a footgun if we start actually using zero values for int attributes (something that we are careful not to do currently).

I'm confused why we cannot have zero values for int attributes? The change here was to specifically allow zero values for any int attribute (because we have a downstream attribute where the value can be zero).
Is this a verifier issue - for example, we cannot have derferenceable_or_null with 0.

The current approach leaves behind a footgun if we start actually using zero values for int attributes (something that we are careful not to do currently).

I'm confused why we cannot have zero values for int attributes? The change here was to specifically allow zero values for any int attribute (because we have a downstream attribute where the value can be zero).
Is this a verifier issue - for example, we cannot have derferenceable_or_null with 0.

I don't think there is a strong technical reason for this restriction, it's just an artifact of the API design. For some int attributes we perform an encode/decode step to translate between a "raw value" (which is never zero) and a semantic value (which can be zero). I do think we should lift this restriction, though I'm not sure if just adjusting this one constructor will be sufficient.

anna added a comment.Apr 21 2022, 11:36 AM

The current approach leaves behind a footgun if we start actually using zero values for int attributes (something that we are careful not to do currently).

I'm confused why we cannot have zero values for int attributes? The change here was to specifically allow zero values for any int attribute (because we have a downstream attribute where the value can be zero).
Is this a verifier issue - for example, we cannot have derferenceable_or_null with 0.

I don't think there is a strong technical reason for this restriction, it's just an artifact of the API design. For some int attributes we perform an encode/decode step to translate between a "raw value" (which is never zero) and a semantic value (which can be zero). I do think we should lift this restriction, though I'm not sure if just adjusting this one constructor will be sufficient.

Yes, it does look like just fixing this one constructor is not enough. For example, in the downstream case, using this change, we no longer fail on the assert about the kind of attribute when the attribute value is 0. However, I'm seeing another assertion failure: "Context of attribute is not the same as the module". I did not investigate the reason for this (but it is very clear that it only fails when the value is zero, because we also update other non-zero attributes with that same context and have no issues).
Also, when making sure the attribute will always have a non-zero value through our front-end, I no longer see that assertion failure. I'm going with the route of fixing the front-end for now until I get a chance to investigate the reason here on what else is preventing a "zero value int attribute".

anna abandoned this revision.May 30 2022, 7:51 AM

went another path.