This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Simplification of relational operations (was [patch for PR18942])
- From: Maxim Kuvyrkov <maxim at codesourcery dot com>
- To: Zdenek Dvorak <rakdver at kam dot mff dot cuni dot cz>
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 2 Dec 2011 15:33:06 +1300
- Subject: Simplification of relational operations (was [patch for PR18942])
Zdenek,
I'm looking at a missed optimizations in combine and it is similar to the one you've fixed in PR18942 (http://thread.gmane.org/gmane.comp.gcc.patches/81504).
I'm trying to make GCC optimize
(leu:SI
(plus:SI (reg:SI) (const_int -1))
(const_int 1))
into
(leu:SI
(reg:SI)
(const_int 2))
.
Your patch for PR18942 handles only EQ/NE comparisons, and I wonder if there is a reason not to handle LEU/GEU, LTU/GTU comparisons as well. I'm a bit fuzzy whether signed comparisons can be optimized here as well, but I can't see the problem with unsigned comparisons.
Any reason why this optimization would be unsafe?
Regarding the testcase, the general pattern
(set (tmp1) (plus:SI (reg:SI) (const_int A))
(set (tmp2) (leu:SI (tmp1) (const_int B))
is generated from switch statement
switch (reg) {
case A:
case B:
...
}
Combine tries merge the two instructions into one, but fails. This causes an extra 'add' instruction per switch statement in the final assembly. The target I'm working with is MIPS, but, I imagine, other architectures are affected as well.
Thank you,
--
Maxim Kuvyrkov
CodeSourcery / Mentor Graphics