This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Transform `icmp eq/ne ({su}div exact X,Y),C` -> `icmp eq/ne X, Y*C`
ClosedPublic

Authored by goldstein.w.n on May 7 2023, 11:53 PM.

Details

Summary

We can do this if Y*C doesn't overflow. This is trivial if C is
0/1. Otherwise we actually generate a mul instruction iff the div
has one use.

Alive2 Links:

udiv: https://alive2.llvm.org/ce/z/GWPW67
sdiv: https://alive2.llvm.org/ce/z/bUoX9h

Diff Detail

Event Timeline

goldstein.w.n created this revision.May 7 2023, 11:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 7 2023, 11:53 PM
goldstein.w.n requested review of this revision.May 7 2023, 11:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 7 2023, 11:53 PM
nikic accepted this revision.Jun 28 2023, 12:37 AM

LGTM

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
3331–3332

Drop this part of the comment, it does not reflect the implementation.

3339

Check hasOneUse() first here.

This revision is now accepted and ready to land.Jun 28 2023, 12:37 AM

I'd also suggest to update the proofs to match what you are actually implementing. The current ones are rather roundabout.

goldstein.w.n marked 2 inline comments as done.Jul 12 2023, 5:47 PM

Fixup some nits

This revision was landed with ongoing or failed builds.Jul 13 2023, 5:37 PM
This revision was automatically updated to reflect the committed changes.