This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Improve combining of conditionals


This patch fixes the problem with substituting expressions into IF_THEN_ELSE during combining.  Without this patch combining of conditionals inside IF_THEN_ELSE is seriously inhibited.

The problem this patch fixes is that combine_simplify_rtx() prefers to return an expression (say, <xor (a) (b)>) even when a comparison is prefered (say, <neq (xor (a) (b)) 0>).  Expressions are not recognized as valid conditions of if_then_else for most targets, so combiner misses a potential optimization.  This patch makes combine_simplify_rtx() aware of the context it was invoked in, and, when appropriate, does not discourage it from returning a conditional.

The motivating example for this fix was crcu8() routine from CoreMark.  Compiling this routine for MIPS32R2 at -O3 produces there are several instances of sequence

andi	$2,$2,0x1
xori	$2,$2,0x1
movn	$3,$5,$2  ; $2 dies here

which can be optimized into

andi	$2,$2,0x1
movz	$3,$5,$2  ; $2 dies here
.

The patch was successfully tested on {i686, arm, mips}-linux, both GCC testsuites and SPEC2000 runs.  For all targets there was no observable code difference in SPEC2000 benchmarks, so the example does not trigger very often.  Still, it speeds up CoreMark by about 1%.

OK for trunk?

--
Maxim Kuvyrkov
Mentor Graphics / CodeSourcery


Attachment: gcc-combine-if_then_else.ChangeLog
Description: Binary data

Attachment: gcc-combine-if_then_else.patch
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]