This is an archive of the discontinued LLVM Phabricator instance.

[IR] Add a ConstantInt::getAllOnes wrapper around ConstantInt::get/getSigned.
Changes PlannedPublic

Authored by craig.topper on Apr 4 2023, 12:27 PM.

Details

Summary

Creating an all ones value for a type larger than i64 requires
using using ConstantInt::getSigned with -1, passing true to the
IsSigned operand of ConstantInt::get with -1, or using
Constant::getAllOnesValue.

Many places in tree used the ConstantInt::get -1 without IsSigned.
This likely works fine for the types they see in practice, but
it seemed better to have a more explicit way to do this.

This patch adds ConstantInt::getAllOnes and replaces other calls
to use it.

Diff Detail

Event Timeline

craig.topper created this revision.Apr 4 2023, 12:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 4 2023, 12:27 PM
craig.topper requested review of this revision.Apr 4 2023, 12:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 4 2023, 12:27 PM
nikic added a comment.Apr 4 2023, 12:31 PM

This patch adds ConstantInt::getAllOnes and replaces other calls to use it.

Does it? I don't see any change to the Constant hierarchy.

In any case, I don't get why we need getAllOnes() when we already have getAllOnesValue().

Add the rest of the commit that I meant to push

This patch adds ConstantInt::getAllOnes and replaces other calls to use it.

Does it? I don't see any change to the Constant hierarchy.

In any case, I don't get why we need getAllOnes() when we already have getAllOnesValue().

getAllOnesValue has to reinspect the type to determine int vs FP. We also can't override on IntegerType* to return a ConstantInt*. Not sure if any of the callers of ConstantInt::get/getSigned was using that feature.

nikic added a comment.Apr 5 2023, 5:48 AM

getAllOnesValue has to reinspect the type to determine int vs FP.

Is there reason to believe that this has any non-negligible cost?

We also can't override on IntegerType* to return a ConstantInt*. Not sure if any of the callers of ConstantInt::get/getSigned was using that feature.

We pretty much always handle int or vector of int, so specializing on ConstantInt return doesn't seem like something that would commonly be needed.

craig.topper planned changes to this revision.Apr 5 2023, 9:48 AM