This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Add general constant support to eq/ne icmp(add(X,C1),add(Y,C2)) -> icmp(add(X,C1-C2),Y) fold
ClosedPublic

Authored by RKSimon on Mar 13 2022, 7:57 AM.

Details

Summary

A further extension for Issue #32161

For eq/ne comparisons - the sign mismatch and bounds constraints are redundant, so if the that fold fails, fallback and just fold the constants directly.

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

The loop rotation test change looks mostly benign - the backend doesn't seem to suffer? https://gcc.godbolt.org/z/dErMY78To

Diff Detail

Event Timeline

RKSimon created this revision.Mar 13 2022, 7:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 13 2022, 7:57 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
RKSimon requested review of this revision.Mar 13 2022, 7:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 13 2022, 7:57 AM
nikic added a subscriber: nikic.Mar 13 2022, 1:01 PM
nikic added inline comments.
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
4138

ImmConstant?

I guess this looks good other than the constantexpr question.

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

Bikeshedding: is the phaseordering test affected similarly if you "swap" A and C,
in other words, do we have transforms elsewhere to move such computations out of loop body?

RKSimon added inline comments.Mar 14 2022, 7:45 AM
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
4138

I guess I should add constexpr tests

RKSimon updated this revision to Diff 415414.Mar 15 2022, 6:38 AM

Use m_ImmConstant

RKSimon added inline comments.Mar 15 2022, 6:40 AM
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
4142

It makes no difference - I checked if we could handle this by using the oneuse binop but that had on effect either.

lebedev.ri accepted this revision.Mar 15 2022, 6:44 AM

Seems good to me.

This revision is now accepted and ready to land.Mar 15 2022, 6:44 AM
This revision was landed with ongoing or failed builds.Mar 15 2022, 7:18 AM
This revision was automatically updated to reflect the committed changes.