This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Canonicalize icmp eq pow2 more thoroughly
ClosedPublic

Authored by nikic on Mar 15 2023, 9:11 AM.

Details

Summary

We currently already canonicalize icmp eq (%x & Pow2), Pow2 to icmp ne (%x & Pow2), 0. This patch generalizes the fold based on known bits.

In particular, this allows us to handle comparisons against !range !{i64 0, i64 2} loads, which addresses an optimization regression in Rust caused by https://github.com/llvm/llvm-project/commit/8df376db7282b955e7990cb8887ee9dcd3565040.

Diff Detail

Event Timeline

nikic created this revision.Mar 15 2023, 9:11 AM
nikic requested review of this revision.Mar 15 2023, 9:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 15 2023, 9:11 AM
goldstein.w.n accepted this revision.Mar 15 2023, 2:02 PM

LGTM.

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
5765

nit: "is" -> "is known to be".
also maybe "Pow2" -> "C_Pow2" so its a little clearer to you are refering to the exact same value.

This revision is now accepted and ready to land.Mar 15 2023, 2:02 PM
This revision was automatically updated to reflect the committed changes.