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.
clang-format: please reformat the code