This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Add fold for `(rem (mul/shl X, Y), (mul/shl X, Z))` -> `(mul X, (rem Y, Z))`
Needs ReviewPublic

Authored by goldstein.w.n on Feb 6 2023, 9:50 AM.

Details

Summary

Forked from D142901 to handle the mul/shl when Y and Z are
non-constant.

(srem (mul/shl X, Y), (mul/shl X, Z))

[If `Y`/`Z` are one use]
    -> `(mul/shl nuw nsw X, (srem Y, Z))`
        - https://alive2.llvm.org/ce/z/ccTFj2
        - https://alive2.llvm.org/ce/z/i_UQ5A
    -> `(mul/shl nsw X, (srem Y, Z))`
        - https://alive2.llvm.org/ce/z/mQKc63
        - https://alive2.llvm.org/ce/z/uERkKH

(urem (mul/shl X, Y), (mul/shl X, Z))

[If `Y`/`Z` are one use]
    -> `(mul/shl nuw nsw X, (srem Y, Z))`
        - https://alive2.llvm.org/ce/z/mNnQqJ
        - https://alive2.llvm.org/ce/z/Bj_DR-
        - https://alive2.llvm.org/ce/z/X6ZEtQ
    -> `(mul/shl nuw X, (srem Y, Z))`
        - https://alive2.llvm.org/ce/z/SJYtUV

Diff Detail

Event Timeline

goldstein.w.n created this revision.Feb 6 2023, 9:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 6 2023, 9:50 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
goldstein.w.n requested review of this revision.Feb 6 2023, 9:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 6 2023, 9:50 AM

Rebase + bug fix

Rebase - no change

ping @sdesmalen any update any when you will have time review this (no rush).