This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] canEvaluateTruncated - use KnownBits to check for inrange shift amounts
ClosedPublic

Authored by RKSimon on Jul 3 2020, 5:51 AM.

Details

Summary

Currently canEvaluateTruncated can only attempt to truncate shifts if they are scalar/uniform constant amounts that are in range.

This patch replaces the constant extraction code with KnownBits handling, using the KnownBits::getMaxValue to check that the amounts are inrange.

This enables support for nonuniform constant cases, and also variable shift amounts that have been masked somehow. Annoyingly, this still won't work for vectors with (demanded) undefs as KnownBits returns nothing in those cases, but its a definite improvement on what we currently have.

Diff Detail

Event Timeline

RKSimon created this revision.Jul 3 2020, 5:51 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 3 2020, 5:51 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
lebedev.ri added inline comments.Jul 3 2020, 6:15 AM
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
398

Shouldn't this take AmtKnownBits.getMaxValue() into account?

I.e. if we are truncating i32 -> i16, but are shifting by at most 1,
we don't need for all bits under mask 0xFFFF0000 to be zeros,
we only need that for the bits we'd potentially shift-in,
i.e. only 0x10000. Or am i missing something?

RKSimon marked an inline comment as done.Jul 3 2020, 6:58 AM
RKSimon added inline comments.
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
398

You're right - this is an existing issue - do you want me to deal with that first?

lebedev.ri accepted this revision.Jul 3 2020, 7:08 AM
lebedev.ri added inline comments.
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
398

No, but i'd like to see a FIXME.
It, and the same improvement in ashr handling can be done as follow-ups.

This revision is now accepted and ready to land.Jul 3 2020, 7:08 AM
This revision was automatically updated to reflect the committed changes.