This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by shchenz on Mar 17 2020, 7:41 AM.

Details

Summary

This is for recognizing more than one pairs in Reassociate pass.
Currently, Reassociate pass can recognize one pair and it can be rewritten for later CSE.

So for below example:

int num1;
int num2;
void foo(int a, int b, int c)
{
  num1 = a + b + c;
  num2= a + c;
}

a+c is common expression in exp a+b+c and a+c, clang generates:

define dso_local void @foo(i32 signext %0, i32 signext %1, i32 signext %2) local_unnamed_addr #0 {
  %4 = add i32 %2, %0
  %5 = add i32 %4, %1
  store i32 %5, i32* @num1, align 4, !tbaa !2
  store i32 %4, i32* @num2, align 4, !tbaa !2
  ret void
}

a + b + c is reassociated to ((a + c) + b)

But Reassociate pass can not recognizing more than one pairs.
for

num1 = a + b + c + d;
num2 = b + c;
num3 = a + d;

clang can recognize b + c is a common expression in a + b + c + d and b + c. It is reassociated to (((b + c) + a) + d)
But it can not do further recognization that a + d is also one common expression. We expect ((b+c) + (a+d))

This patch tries to implement this feature.

patch https://reviews.llvm.org/D76057 is the NFC patch I made for this one.

Any comment is much appreciated.

Diff Detail

Event Timeline

shchenz created this revision.Mar 17 2020, 7:41 AM
shchenz added reviewers: jsji, hfinkel, Restricted Project.Mar 17 2020, 7:48 AM

Tests seem to be missing

This comment was removed by shchenz.
shchenz updated this revision to Diff 251324.Mar 19 2020, 3:33 AM

add testcases and made some logic change

Herald added a project: Restricted Project. · View Herald TranscriptMar 19 2020, 3:33 AM
shchenz updated this revision to Diff 251374.Mar 19 2020, 7:19 AM
shchenz edited the summary of this revision. (Show Details)
shchenz planned changes to this revision.Mar 19 2020, 7:32 AM
shchenz updated this revision to Diff 251583.Mar 20 2020, 3:01 AM

clean up LIT/LNT failure cases

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.