This is an archive of the discontinued LLVM Phabricator instance.

[KnownBits] Return zero instead of unknown for always poison shifts
ClosedPublic

Authored by nikic on May 16 2023, 1:48 AM.

Details

Summary

For always poison shifts, any KnownBits return value is valid. Currently we return unknown, but returning zero is generally more profitable. We had some code in ValueTracking that tried to do this, but was actually dead code.

Diff Detail

Event Timeline

nikic created this revision.May 16 2023, 1:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2023, 1:48 AM
nikic requested review of this revision.May 16 2023, 1:48 AM
foad added a comment.May 16 2023, 1:55 AM

Shouldn't something have simplified these shifts to poison already?

No objection to the patch.

nikic added a comment.May 16 2023, 2:01 AM

Shouldn't something have simplified these shifts to poison already?

No objection to the patch.

On the IR level, yes, we do that here: https://github.com/llvm/llvm-project/blob/bba9209f1d198efc7e492f0e273fff0b0a5ef060/llvm/lib/Analysis/InstructionSimplify.cpp#L1361-L1365 The changes in InstCombine are because the shift is a constant expression, so these don't get simplified (until I get around to removing support for shift expressions...) The backend doesn't have something equivalent (and probably shouldn't have it -- doesn't seem like something that is valuable enough to compute known bits for).

Think this makes sense. Don't think I really have the domain knowledge to approve though.

foad accepted this revision.May 23 2023, 5:33 AM

LGTM

This revision is now accepted and ready to land.May 23 2023, 5:33 AM
This revision was landed with ongoing or failed builds.May 23 2023, 5:41 AM
This revision was automatically updated to reflect the committed changes.