copied from: http://gcc.gnu.org/ml/gcc-patches/2006-02/msg00812.html Hi Paolo, with your patch: http://gcc.gnu.org/ml/gcc-patches/2005-11/msg01718.html 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) n_constants++; 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; to: gcc_assert (n_ops >= 2); if (!canonicalized) return NULL_RTX; Which was later on changed by Alan Modra with: http://gcc.gnu.org/ml/gcc-patches/2005-12/msg00015.html 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: http://gcc.gnu.org/ml/gcc-patches/2006-02/msg00884.html Thats why I'll assign the bug to him.
Confirmed.
Uhm, fixing this will resurface a wrong-code bug, PR28651, which is more important than this missed optimization. :-(
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.
Subject: Bug 26847 Author: bonzini Date: Tue Sep 5 17:41:22 2006 New Revision: 116701 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116701 Log: 2006-09-05 Paolo Bonzini <bonzini@gnu.org> 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. Modified: trunk/gcc/ChangeLog trunk/gcc/simplify-rtx.c
patch committed, confirmed fixed by andreas