Bug 35288 - Expression reassociation problem
Summary: Expression reassociation problem
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: unknown
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2008-02-22 06:36 UTC by davidxl
Modified: 2023-09-24 04:50 UTC (History)
2 users (show)

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


Attachments

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] 

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.