This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Committed: fix PR37939, CRIS regression in code quality (insn not used)
- From: Hans-Peter Nilsson <hans-peter dot nilsson at axis dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 1 Nov 2008 23:35:57 +0100
- Subject: Committed: fix PR37939, CRIS regression in code quality (insn not used)
See PR37939. The cost of the MULT made the cost of the combined
shift-and-add higher than the individual insns. The benefit of
this fix is highly code-dependent, with results in the range
0.2-7.0% improvement but with no regressions; it depends on how
much focus the code has on indexing 2 or 4-byte arrays. :)
(BIAP is the name of the prefix insn implementing the mode
pre-CRIS v32; better not have "addi" in the file or its name
other than in the scan-assembler directive.)
Right, the patterns (and combine!) should probably use ASHIFT,
not MULT; see comment #1, but fixing that would be unsuitable at
this stage. Note also that there'd then be assummetry for the
side-effect addressing modes (a parallel assignment of the
address to a fourth register):
(parallel
[(set reg0 (mem (plus (mult reg1 2) reg2)))
(set reg3 (plus (ashift reg1 1) reg2))])
The fix was regtested on trunk and gcc-4_3-branch for
cris-axis-elf and crisv32-axis-linux-gnu. Committed, trunk and
branch.
gcc/testsuite:
PR target/37939
* gcc.target/cris/biap.c: New test.
gcc:
PR target/37939
* config/cris/cris.c (cris_rtx_costs) <MULT>: Return 0 for an ADDI
operand.
--- /dev/null 2008-02-22 17:23:55.052000250 +0100
+++ gcc.target/cris/biap.c 2008-10-28 17:23:14.000000000 +0100
@@ -0,0 +1,11 @@
+/* Make sure ADDI is combined and emitted successfully.
+ See also PR37939. */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-final { scan-assembler "addi" } } */
+/* { dg-final { scan-assembler-not "lsl" } } */
+
+int xyzzy (int r10, int r11)
+{
+ return r11 * 4 + r10;
+}
Index: config/cris/cris.c
===================================================================
--- config/cris/cris.c (revision 141344)
+++ config/cris/cris.c (working copy)
@@ -1795,6 +1795,21 @@
return true;
case MULT:
+ /* If we have one arm of an ADDI, make sure it gets the cost of
+ one insn, i.e. zero cost for this operand, and just the cost
+ of the PLUS, as the insn is created by combine from a PLUS
+ and an ASHIFT, and the MULT cost below would make the
+ combined value be larger than the separate insns. The insn
+ validity is checked elsewhere by combine.
+
+ FIXME: this case is a stop-gap for 4.3 and 4.4, this whole
+ function should be rewritten. */
+ if (outer_code == PLUS && BIAP_INDEX_P (x))
+ {
+ *total = 0;
+ return true;
+ }
+
/* Identify values that are no powers of two. Powers of 2 are
taken care of already and those values should not be changed. */
if (!CONST_INT_P (XEXP (x, 1))
brgds, H-P