Bug 35288 - Expression reassociation problem
Summary: Expression reassociation problem
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2008-02-22 06:36 UTC by davidxl
Modified: 2010-11-02 23:40 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2008-02-22 10:55:53


Note You need to log in before you can comment on or make changes to this bug.
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]