This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking] Do more thorough non-zero check in `isKnownToBePowerOfTwo` when `OrZero` is no set.
AbandonedPublic

Authored by goldstein.w.n on Aug 7 2023, 10:49 AM.

Details

Summary

We can cover more cases by directly checking if the result is
known-nonzero for common patterns when they are missing OrZero.

This patch add isKnownNonZero checks for shl, lshr, and, and mul.

Diff Detail

Unit TestsFailed

Event Timeline

goldstein.w.n created this revision.Aug 7 2023, 10:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 7 2023, 10:49 AM
goldstein.w.n requested review of this revision.Aug 7 2023, 10:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 7 2023, 10:49 AM
nikic added a comment.Aug 9 2023, 4:06 AM

Please land the remainder of the patch stack first.

llvm/lib/Analysis/ValueTracking.cpp
2046

Would it make sense to preserve the flag checks? I think isKnownNonZero will be able to prove the same result, but in a more roundabout way (it can't just check the flags, it will also have to prove non-zero operands etc).

goldstein.w.n added inline comments.Aug 9 2023, 10:01 AM
llvm/lib/Analysis/ValueTracking.cpp
2046

I think for shl you are right, IPSCCP will propagate nuw in all the cases I think isKnownNonZero helps here.
For lshr however the equivilent logic is missing. I take it you would prefer fixing this with a patch to IPSCCP?

goldstein.w.n added inline comments.Aug 9 2023, 10:10 AM
llvm/lib/Analysis/ValueTracking.cpp
2046

Think actually best in InstCombine, IPSCCP uses ranges which isn't so useful for checking if a remainder is zero. Think computeKnownBits makes more sense for this.

Rebase to end of series + remove isKnownNonZero change from shifts

goldstein.w.n marked an inline comment as done.Aug 9 2023, 11:34 AM
goldstein.w.n added inline comments.
llvm/lib/Analysis/ValueTracking.cpp
2046

Remove from shifts and improved flag adding logic in InstCombe: D157532