This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] fold icmp equality with udiv and large constant
ClosedPublic

Authored by spatel on May 25 2022, 12:43 PM.

Details

Summary

With large compare constant:
(X u/ Y) == C --> (X == C) && (Y == 1)
(X u/ Y) != C --> (X != C) || (Y != 1)

https://alive2.llvm.org/ce/z/EhKwh6

There are various potential missing icmp (div) transforms shown here:
https://github.com/llvm/llvm-project/issues/55695

This is a generalization for part of the udiv + equality. I didn't check in detail, but some of those may only make sense as codegen transforms.

This results in one extra instruction in IR, but it is better for analysis, and looks much better in codegen on all targets that I tried.

Diff Detail

Event Timeline

spatel created this revision.May 25 2022, 12:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 25 2022, 12:44 PM
spatel requested review of this revision.May 25 2022, 12:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 25 2022, 12:44 PM
nikic accepted this revision.May 25 2022, 1:54 PM

LGTM

This revision is now accepted and ready to land.May 25 2022, 1:54 PM
This revision was landed with ongoing or failed builds.May 26 2022, 6:10 AM
This revision was automatically updated to reflect the committed changes.