Simplify chain of GEP in the form of GEP (GEP ... (GEP (GEP p C1) X1) ... Xn) C2 where C1 and C2 are constants by splitting GEP p C1 and breaking its user depedency, allowing visitGEPofGEP to reassociate the cloned inner GEP to outer GEP and perform constant index merging.
Example code that is optimized
struct S {
char padding[123];
int x;
};
int* P(S* s) {
return (int*)((char*)&s->x + s->x - offsetof(S, x));
}originally generates
P(S*): # @P(S*)
movslq 124(%rdi), %rax
addq %rdi, %rax
addq $124, %rax
addq $-124, %rax
retqNow generates
P(S*): # @P(S*) movslq 124(%rdi), %rax addq %rdi, %rax retq