This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Add bswap(logic_op(bswap(x), y)) regression test case; NFC
ClosedPublic

Authored by austin880625 on May 1 2023, 4:09 AM.

Details

Summary

Fold the following case on IR InstCombine pass. This patch includes the new test cases for this optimization

bswap(logic_op(x, bswap(y))) -> logic_op(bswap(x), y)
bswap(logic_op(bswap(x), y)) -> logic_op(x, bswap(y))
bswap(logic_op(bswap(x), bswap(y))) -> logic_op(x, y) with multi-use

Diff Detail

Event Timeline

austin880625 created this revision.May 1 2023, 4:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 1 2023, 4:09 AM
austin880625 requested review of this revision.May 1 2023, 4:09 AM
goldstein.w.n added inline comments.
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
1693 ↗(On Diff #518420)

I don't see how this is correct if we only have 1 bswap:
https://alive2.llvm.org/ce/z/zBErQk

Also this apples for bitreverse as well.

llvm/test/Transforms/InstCombine/bswap-fold.ll
542

Can you split the new tests to a seperate patch so we can see the diff generated?

goldstein.w.n added inline comments.May 1 2023, 11:11 AM
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
1632 ↗(On Diff #518420)

nit, but since we already have the scope for ::bswap case, can you just declare V before the match.

goldstein.w.n added inline comments.May 1 2023, 11:15 AM
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
1682 ↗(On Diff #518420)

Can you move this to a helper function that takes an Intrisinic ID so we can reuse for bitreverse?

1693 ↗(On Diff #518420)

I don't see how this is correct if we only have 1 bswap:
https://alive2.llvm.org/ce/z/zBErQk

Also this apples for bitreverse as well.

Nevermind, saw this as standalone, missed it was in the bswap case.

hi, thanks for the reviewing! I'll keep working on the suggestions and update here once I've done(probably in 2-3 days)

austin880625 added inline comments.May 1 2023, 2:12 PM
llvm/test/Transforms/InstCombine/bswap-fold.ll
542

Just to confirm(newbie here), are the following separated patches you want:

  1. first one in old implementation and new tests with FileCheck lines generated with old opt
  2. second one with my actual code change, and the new tests with updated FileCheck lines generated with the changed opt. And the patch is based diff-ed with the first one?
goldstein.w.n added inline comments.May 1 2023, 3:34 PM
llvm/test/Transforms/InstCombine/bswap-fold.ll
542

Just to confirm(newbie here), are the following separated patches you want:

  1. first one in old implementation and new tests with FileCheck lines generated with old opt
  2. second one with my actual code change, and the new tests with updated FileCheck lines generated with the changed opt. And the patch is based diff-ed with the first one?

Yeah. You can create series using the 'edit related revisions' then make the test-patch the "parent".
For example:
Tests: D149520
Impl: D149521

and if click 'stack' you see the relationship between the two.

542

Just to confirm(newbie here), are the following separated patches you want:

  1. first one in old implementation and new tests with FileCheck lines generated with old opt
  2. second one with my actual code change, and the new tests with updated FileCheck lines generated with the changed opt. And the patch is based diff-ed with the first one?

Yeah. You can create series using the 'edit related revisions' then make the test-patch the "parent".
For example:
Tests: D149520
Impl: D149521

and if click 'stack' you see the relationship between the two.

542

And welcome! Thank you for the patch!

separate test and implementation

@goldstein.w.n I updated the diff on this revision (as test) and created another D149699 as updated implementation. Let me know if I did anything wrong here, thanks!

@goldstein.w.n I updated the diff on this revision (as test) and created another D149699 as updated implementation. Let me know if I did anything wrong here, thanks!

You created the series properly.

Can you update the summary/title of the two commits to reflect what they are now.

So D149577 doesn't need a summary but the title should be something along the lines of:
"[InstCombine] Add tests for (logic_op (bswap X), Y); NFC"

D149699 should have basically the same title/commit as you originally had (as you have here now).

austin880625 retitled this revision from [InstCombine] Improve bswap optimization to [InstCombine] Add bswap(logic_op(bswap(x), y)) regression test case; NFC.May 3 2023, 9:37 AM
austin880625 retitled this revision from [InstCombine] Add bswap(logic_op(bswap(x), y)) regression test case; NFC to [InstCombine][DAGCombiner] Add bswap(logic_op(bswap(x), y)) regression test case; NFC.

add test cases for CodeGen(DAGCombiner)

austin880625 edited the summary of this revision. (Show Details)
austin880625 retitled this revision from [InstCombine][DAGCombiner] Add bswap(logic_op(bswap(x), y)) regression test case; NFC to [InstCombine] Add bswap(logic_op(bswap(x), y)) regression test case; NFC.
austin880625 edited the summary of this revision. (Show Details)

contains changes for InstCombine only

goldstein.w.n added inline comments.May 3 2023, 2:35 PM
llvm/test/Transforms/InstCombine/bswap-fold.ll
781

your *_rhs_* tests appear to have the bswap still on the lhs.

austin880625 updated this revision to Diff 519623.EditedMay 4 2023, 1:01 PM
austin880625 edited the summary of this revision. (Show Details)

add bswap(logic_op(bswap(x), bswap(y))) -> logic_op(x, y) case with multi-use

This revision is now accepted and ready to land.May 4 2023, 8:30 PM
RKSimon accepted this revision.May 6 2023, 9:05 AM

LGTM

@austin880625 Do you have commit access, if not please can you post your github email address so I can push the changes for you

@austin880625 Do you have commit access, if not please can you post your github email address so I can push the changes for you

@RKSimon I don't, can you use this one: austin880625@gmail.com . Thanks!