This is an archive of the discontinued LLVM Phabricator instance.

[Reassociate] recognize more than one pairs for later CSE - NFC
Needs ReviewPublic

Authored by shchenz on Mar 12 2020, 4:16 AM.

Details

Summary

Motivated case:

void foo(int a, int b, int c, int d, int* res1, int* res2, int* res3)
{
  *res1 = a + b + c + d;
  *res2 = b + c;
  *res3 = a + d;
}

There are two common expressions a+d & c+d, currently Reassociate can recognize one of them.

It gets:

%add = add i32 %b, %c
%add.1 = add i32 %add, %a
%add.2 = add i32 %add.1, %d
store i32 %add, i32*res2, align 4, !tbaa !2
store i32 %add.2, i32* %res1, align 4, !tbaa !2
%add.3 = add nsw i32 %a, %d
store i32 %add.3, i32* %res3, align 4, !tbaa !2
ret void

But we expect:

%add1 = add i32 %d, %a
%add = add i32 %c, %b
%add2 = add i32 %add, %add1
store i32 %add2, i32* %res1, align 4, !tbaa !2
store i32 %add, i32* %res2, align 4, !tbaa !2
store i32 %add1, i32* %res3, align 4, !tbaa !2
ret void

This is first part to recognize more than one pattern. This is NFC.
Changes about rewriting these common expressions will be posted in following patches.

Diff Detail

Event Timeline

shchenz created this revision.Mar 12 2020, 4:16 AM

I'm not familiar with this pass, but this looks a bit too large to be NFC.

@lebedev.ri Thanks response for this patch, Roman. Do you happen to know who is familiar with this pass? I add the reviewer by searching the commit history.

fhahn added a subscriber: fhahn.Mar 13 2020, 3:09 AM

I think it would make the review much easier if the description would include the rational behind the changes, i.e how the patch works, why the changes are necessary in terms of implementation and what issue the patch concretely addressed.

Also you mention follow-on changes that build on this one. Sharing them would probably also help with reviewing this change, to see how things fit together in the end. Phabricator lets you link related/dependent patches.

shchenz planned changes to this revision.Mar 13 2020, 4:08 AM

I think it would make the review much easier if the description would include the rational behind the changes, i.e how the patch works, why the changes are necessary in terms of implementation and what issue the patch concretely addressed.

Also you mention follow-on changes that build on this one. Sharing them would probably also help with reviewing this change, to see how things fit together in the end. Phabricator lets you link related/dependent patches.

Make sense. I will ask for reviewing when follow-on patch is ready. Thanks for your comment @fhahn

shchenz requested review of this revision.Mar 20 2020, 3:06 AM

https://reviews.llvm.org/D76284 is posted as child of this nfc patch.

gentle ping

gentle ping

lebedev.ri resigned from this revision.Jan 12 2023, 5:18 PM

This review seems to be stuck/dead, consider abandoning if no longer relevant.