This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombine] Use `IsKnownNeverZero` to see if we need zero-check in is_pow2 setcc patern
ClosedPublic

Authored by goldstein.w.n on Jun 11 2023, 11:29 PM.

Details

Summary

ctpop(X) eq/ne 1 is checking if X is a non-zero power of 2. Power of
2 check including zero is (X & (X-1)) eq/ne 0 and unfortunately
there is no good pattern for checking a power of 2 while excluding
zero. So, when lowering ctpop(X) eq/ne 1, explicitly check
IsKnownNeverZero(X) to maybe be able to optimize out the extra zero
check.

We need this explicitly as DAGCombiner does not re-analyze provable
setcc nodes, and the middle-end never finds it beneficially to broaden
ctpop(X) eq/ne 1 -> ctpop(X) ule/ugt 1 (power of 2 including
zero).

Diff Detail

Event Timeline

goldstein.w.n created this revision.Jun 11 2023, 11:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 11 2023, 11:29 PM
goldstein.w.n requested review of this revision.Jun 11 2023, 11:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 11 2023, 11:29 PM
RKSimon accepted this revision.Jun 12 2023, 1:45 AM

LGTM

This revision is now accepted and ready to land.Jun 12 2023, 1:45 AM
This revision was landed with ongoing or failed builds.Jun 12 2023, 11:53 AM
This revision was automatically updated to reflect the committed changes.