User account creation filtered due to spam.

Bug 26847 - [4.2 Regression] Missed optimization in simplify_plus_minus
Summary: [4.2 Regression] Missed optimization in simplify_plus_minus
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.2.0
: P2 normal
Target Milestone: 4.2.0
Assignee: Paolo Bonzini
Keywords: missed-optimization, patch
Depends on:
Reported: 2006-03-24 15:06 UTC by Andreas Krebbel
Modified: 2006-09-05 21:40 UTC (History)
2 users (show)

See Also:
Host: s390x-ibm-linux-gnu
Target: s390x-ibm-linux-gnu
Build: s390x-ibm-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2006-07-25 14:53:34

patch being tested (1.72 KB, patch)
2006-08-11 09:15 UTC, Paolo Bonzini
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Krebbel 2006-03-24 15:06:25 UTC
copied from:

Hi Paolo,

with your patch:

simplify_plus_minus isn't able anymore to simplify things like (r1 + 8) - r1. 
The function is left at:

  if (!canonicalized)
      int n_constants = 0;

      for (i = 0; i < n_ops; i++)
	if (GET_CODE (ops[i].op) == CONST_INT)

      if (n_constants <= 1)
	return NULL_RTX;

because only a single constant was found and no canonicalization took place.

Your patch changed:

if (n_ops <= 2 && !force)
  return NULL_RTX;


gcc_assert (n_ops >= 2);
if (!canonicalized)
  return NULL_RTX;

Which was later on changed by Alan Modra with:
to the version mentioned above. The reason here was that expressions
like reg + c1 + c2 were not simplified anymore.

So the new version exits always if the initial loop couldn't do any
canonicalization work and only 0 or 1 constants are left. What prevents
simplification in all those cases.

As Roger Sayle pointed out the patch I've proposed in the email isn't the
proper fix for this issue.

Paolo Bonzini already proposed a solution in:

Thats why I'll assign the bug to him.
Comment 1 Andrew Pinski 2006-03-30 20:09:49 UTC
Comment 2 Paolo Bonzini 2006-08-09 07:42:30 UTC
Uhm, fixing this will resurface a wrong-code bug, PR28651, which is more important than this missed optimization. :-(
Comment 3 Paolo Bonzini 2006-08-11 09:15:33 UTC
Created attachment 12062 [details]
patch being tested

Tested so far by checking that it makes PR28651 resurface...

Being bootstrapped and tested on i686-pc-linux-gnu.
Comment 4 Paolo Bonzini 2006-09-05 17:41:30 UTC
Subject: Bug 26847

Author: bonzini
Date: Tue Sep  5 17:41:22 2006
New Revision: 116701

2006-09-05  Paolo Bonzini  <>

	PR rtl-optimization/26847
	* simplify-rtx.c (struct simplify_plus_minus_op_data): Remove ix.
	(simplify_plus_minus_op_data_cmp): For REGs, break ties on the regno.
	(simplify_plus_minus): Count n_constants while filling ops.  Replace
	qsort with insertion sort.  Before going through the array to simplify
	pairs, sort it.  Delay early exit until after the first sort, exiting
	only if no swaps occurred.  Simplify pairs in reversed order, without
	special-casing the first iteration.  Pack ops after simplifying pairs.


Comment 5 Paolo Bonzini 2006-09-05 21:40:50 UTC
patch committed, confirmed fixed by andreas