Bug 35288

Summary: Expression reassociation problem
Product: gcc Reporter: davidxl <xinliangli>
Component: tree-optimizationAssignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: enhancement CC: gcc-bugs, yinyuefengyi
Priority: P3 Keywords: missed-optimization
Version: unknown   
Target Milestone: ---   
See Also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88842
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111560
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2008-02-22 10:55:53

Description davidxl 2008-02-22 06:36:00 UTC
The second instance of a1+a2 is not PREed due to missing expression reassociation.

int foo(int a1, int a2, int a3)
{
   int b1,b2;
   b1 = a3 + a2 + a1;
   b2 = a1  + a2;
   return b1 + b2;
}
Comment 1 Richard Biener 2008-02-22 10:55:53 UTC
Confirmed.  Re-association generates

  D.1548_3 = a1_4(D) + a1_4(D);
  b1_5 = D.1548_3 + a2_2(D);
  b2_6 = b1_5 + a2_2(D);
  D.1549_7 = b2_6 + a3_1(D);

but that does not expose SSA_NAMEs with the same value.
Comment 2 davidxl 2010-11-02 23:40:15 UTC
LLVM got it right:


	addl	%esi, %edi
	leal	(%rdx,%rdi,2), %eax

vs gcc:


	addl	%esi, %edx
	leal	(%rsi,%rdi,2), %edi
	leal	(%rdi,%rdx), %eax

vs open64:


	leal 0(%rdi,%rsi,1), %eax     	# [0] 
	addl %esi,%edx                	# [0] 
	addl %edx,%edi                	# [1] 
	addl %edi,%eax                	# [2] 

David
Comment 3 Andrew Pinski 2021-12-23 08:14:58 UTC
If we use -fwrapv, then GCC is able to get it. THere might be a dup of this bug already too.