This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking] Directly use KnownBits shift functions
ClosedPublic

Authored by nikic on May 31 2023, 9:04 AM.

Details

Summary

Make ValueTracking directly call the KnownBits shift helpers, which provides more precise results.

Unfortunately, ValueTracking has a special case where sometimes we determine non-zero shift amounts using isKnownNonZero(). I have my doubts about the usefulness of that special-case (it is only tested in a single unit test), but I've reproduced the special-case via an extra parameter to the KnownBits methods.

Diff Detail

Event Timeline

nikic created this revision.May 31 2023, 9:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 31 2023, 9:04 AM
nikic requested review of this revision.May 31 2023, 9:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 31 2023, 9:04 AM
goldstein.w.n added inline comments.May 31 2023, 10:54 AM
llvm/lib/Analysis/ValueTracking.cpp
994

what is the Known.getMaxValue().ult(Known.getBitWidth()) is doing here?

coverage-levels.cpp failures might be legitimate.

llvm/lib/Analysis/ValueTracking.cpp
994

Nothing semantically meaningful. It only avoids calling isKnownNonZero() in substantially more cases than the old code.

goldstein.w.n added inline comments.May 31 2023, 1:46 PM
llvm/lib/Analysis/ValueTracking.cpp
994

How does Known.getMaxValue() u< Known.getBitWidth() prevent Known from being 0?

nikic added inline comments.May 31 2023, 1:59 PM
llvm/lib/Analysis/ValueTracking.cpp
994

It doesn't. Note the && rather than ||. It's a heuristic on when it is profitable to call isKnownNonZero() that matches what the old code did. It doesn't make a whole lot of sense, but I'd like to retain the behavior for the purposes of this patch.

goldstein.w.n added inline comments.May 31 2023, 2:17 PM
llvm/lib/Analysis/ValueTracking.cpp
994

Ah, makes sense I had misread as (Known.isNonZero() || MaxVal < GetBitwidth) || isKnownNonZero.

This revision is now accepted and ready to land.May 31 2023, 2:19 PM
This revision was landed with ongoing or failed builds.Jun 1 2023, 12:46 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJun 1 2023, 12:46 AM
Herald added subscribers: Restricted Project, Enna1. · View Herald Transcript