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
gcc-combine-if_then_else.ChangeLog
Description: Binary data
gcc-combine-if_then_else.patch
Description: Binary data