This is an archive of the discontinued LLVM Phabricator instance.

[Patch 4/4]: Use cannoical patterns `(A > C1 && A < C2)` and `(A & B != C)` in `isKnownNonZero`
AbandonedPublic

Authored by goldstein.w.n on Jan 2 2023, 11:22 AM.

Details

Reviewers
nikic
majnemer
Summary

Both patterns where missed because they go through a level of
indirection:

  1. A > C1 && A < C2 cannonicalizes to ICMP_ULT (A + C3, C4)
    • Try and match this pattern explicitly in isKnownNonNullFromDominatingCondition
  1. A & B != C
    • Since cmp ne (A & B, 0) implies cmp ne (A, 0) just match that as an additional generic pattern in isKnownNonNullFromDominatingCondition. This was already done in the final worklist loop.

The rationale is C-code like:

int foo(int A, int B) {
    if(A % 2 == 0) {
        // A is provably odd but `isKnownNonZero(A)` will not find any
        // cmp directly acting on A. The same applies for the ICMP_ULT
        // case.
        return !!(A * B);
    }
    ...
}

Diff Detail

Event Timeline

goldstein.w.n created this revision.Jan 2 2023, 11:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 2 2023, 11:22 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
goldstein.w.n requested review of this revision.Jan 2 2023, 11:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 2 2023, 11:22 AM

Note:

I have run alive2 to verify all the transformations from this patch in relation to D140849 although I have not verified the changes from D140850 and D140851 individually.

propegating changes from rebase

goldstein.w.n abandoned this revision.Jan 28 2023, 9:02 PM

Closing in favor the series starting at: D142827