This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking] Slight refactor to avoid unnecessary work; NFC
ClosedPublic

Authored by goldstein.w.n on Apr 27 2023, 11:22 PM.

Details

Summary

Two changes:

  1. Make some cases that conditionally returned unconditional.
  2. In cases of Op0 != 0 || Op1 != 0 its better check Op1 first as its more likely to be a constant due to canonicalization (so faster to get knownbits of).

Diff Detail

Event Timeline

goldstein.w.n created this revision.Apr 27 2023, 11:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2023, 11:22 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
goldstein.w.n requested review of this revision.Apr 27 2023, 11:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2023, 11:22 PM

In cases of Op0 != 0 || Op1 != 0 its better check Op1 first as its more likely to be a constant due to canonicalization (so faster to get knownbits of).

I'm not sure this is right: If Op1 is constant, then isKnownNonZero will in practice always return true, because the zero cases get folded away. So we do the call on Op0 anyway.

nikic added inline comments.Apr 28 2023, 1:35 AM
llvm/lib/Analysis/ValueTracking.cpp
2916

This one should probably also be changed to return directly?

In cases of Op0 != 0 || Op1 != 0 its better check Op1 first as its more likely to be a constant due to canonicalization (so faster to get knownbits of).

I'm not sure this is right: If Op1 is constant, then isKnownNonZero will in practice always return true, because the zero cases get folded away. So we do the call on Op0 anyway.

Hmm? In something like the Or case if we have or A, 12, isKnownNonZero(Op1) || isKnownOpZero(Op0) will return true after just finding the constant 12. If you flip the order
it first need to recursve through the A case which can be be alot more expensive.

nikic added a comment.Apr 28 2023, 2:50 PM

In cases of Op0 != 0 || Op1 != 0 its better check Op1 first as its more likely to be a constant due to canonicalization (so faster to get knownbits of).

I'm not sure this is right: If Op1 is constant, then isKnownNonZero will in practice always return true, because the zero cases get folded away. So we do the call on Op0 anyway.

Hmm? In something like the Or case if we have or A, 12, isKnownNonZero(Op1) || isKnownOpZero(Op0) will return true after just finding the constant 12. If you flip the order
it first need to recursve through the A case which can be be alot more expensive.

Oh yeah, you're right. Ignore what I said there. I was thinking of the && case, not the || case.

nikic accepted this revision.Apr 28 2023, 2:51 PM

LGTM

This revision is now accepted and ready to land.Apr 28 2023, 2:51 PM
goldstein.w.n marked an inline comment as done.

Add missing case.