This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Transform (icmp eq/ne rotate(X,AX),rotate(Y,AY)) -> (icmp eq/ne rotate(Y,AX-AY))
ClosedPublic

Authored by goldstein.w.n on Jun 7 2023, 1:15 AM.

Details

Summary

Only do so if we don't create more instructions, so either both
rotates have one use or one of the rotates has one use and both AX
and AY are constant.
Proof: https://alive2.llvm.org/ce/z/rVmJgz

Diff Detail

Event Timeline

goldstein.w.n created this revision.Jun 7 2023, 1:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2023, 1:15 AM
goldstein.w.n requested review of this revision.Jun 7 2023, 1:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2023, 1:15 AM
nikic added a comment.Jun 7 2023, 1:54 AM

It looks like you mixed up the descriptions of the two patches maybe?

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

Use CreateIntrinsicCall instead of fetching the declaration manually?

3495

Broken indents

goldstein.w.n retitled this revision from [InstCombine] Canonicalize (icmp eq/ne X, rotate(X)) to always use rotate-left to [InstCombine] Transform (icmp eq/ne rotate(X,A0),rotate(X,A1)) -> (icmp eq/ne rotate(X,A0-A1)).Jun 7 2023, 2:02 AM
goldstein.w.n edited the summary of this revision. (Show Details)

It looks like you mixed up the descriptions of the two patches maybe?

Indeed. Fixed.

goldstein.w.n marked 2 inline comments as done.Jun 7 2023, 10:59 AM

Use Builder.CreateIntrinsic

nikic added inline comments.Jun 7 2023, 12:09 PM
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
3480

Doesn't this also work if the rotates are on different values? https://alive2.llvm.org/ce/z/rVmJgz

goldstein.w.n marked an inline comment as done.Jun 7 2023, 12:33 PM
goldstein.w.n added inline comments.
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
3480

Good catch.

goldstein.w.n marked an inline comment as done.

support roatate(X) with rotate(Y)

goldstein.w.n retitled this revision from [InstCombine] Transform (icmp eq/ne rotate(X,A0),rotate(X,A1)) -> (icmp eq/ne rotate(X,A0-A1)) to [InstCombine] Transform (icmp eq/ne rotate(X,AX),rotate(Y,AY)) -> (icmp eq/ne rotate(Y,AX-AY)).Jun 7 2023, 12:37 PM
goldstein.w.n edited the summary of this revision. (Show Details)
nikic accepted this revision.Jun 7 2023, 12:54 PM

LGTM

This revision is now accepted and ready to land.Jun 7 2023, 12:54 PM
goldstein.w.n edited the summary of this revision. (Show Details)

Rebase