This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner] Fold unsigned and/or of comparisons checking boundaries
Needs ReviewPublic

Authored by goldstein.w.n on Aug 9 2023, 8:38 PM.

Details

Reviewers
pengfei
RKSimon
Summary

The boundary comparisons are of the pattern:

  • Inclusive: (and (icmp uge/ugt Val, Lo), (icmp ule/ult Val, Hi))
  • Exclusive: (or (icmp ule/ult Val, Lo), (icmp uge/ugt Val, Hi))

If we are able to prove Hi u> Lo (or sometimes only Hi u>= Lo), we
can often optimize these patterns to:

`(icmp ule/ult (sub Val, Lo), (sub Hi, Lo))`

Proofs: https://alive2.llvm.org/ce/z/ZM3mXB

Diff Detail

Event Timeline

goldstein.w.n created this revision.Aug 9 2023, 8:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 9 2023, 8:38 PM
goldstein.w.n requested review of this revision.Aug 9 2023, 8:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 9 2023, 8:38 PM

Note, I tested this exhaustively offline. Test script is here: https://pastebin.com/cudJEAJq