Bug 37939 - [4.2/4.3/4.4 Regression] CRIS port: no addi insn
Summary: [4.2/4.3/4.4 Regression] CRIS port: no addi insn
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.3.3
: P5 normal
Target Milestone: 4.3.3
Assignee: Hans-Peter Nilsson
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2008-10-28 16:50 UTC by Hans-Peter Nilsson
Modified: 2008-11-01 23:04 UTC (History)
1 user (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target: cris-*-* and crisv32-*-*
Build:
Known to work: 3.2.1
Known to fail: 4.3.3
Last reconfirmed: 2008-10-28 16:51:37


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hans-Peter Nilsson 2008-10-28 16:50:46 UTC
The CRIS port no longer emits an addi insn for (a << N) + b, where N = {1, 2}.
Trivial test-case:
/* Make sure ADDI is combined and emitted successfully.
   See also PRXXXXX.  */
/* { 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;
}

This insn was created and emitted for e.g. 3.2.1
A look at the combine dump shows that the cost for the individual insns is 5 for the shift (the constant counts as 1 as per cris_rtx_costs) and 4 for the add.  However, the combined cost is 10, also as per cris_rtx_costs, because the insn is (perhaps wrongly) specified as (plus (mult 4 reg1) reg2) and the MULT cost is 6 as per cris_rtx_costs and the PLUS counts as 4.
The way the target address cost function is called has changed, and cris_address_cost needs adjustment.  Actually, it needs a rewrite, but an adjustment will do for the 4.3 and 4.4/trunk, being in stage 3.
Patch in progress.
Comment 1 Hans-Peter Nilsson 2008-10-28 16:54:36 UTC
Forgot to mention that combine "simplifies" the ASHIFT to a MULT, despite not being in an address.  The corresponding address mode exists, and having the same shape for both the separate insns and the addressing mode serves the purpose for the time being, but it might be seen as an RTX canonicalization bug on part of the combine pass.
Comment 2 Hans-Peter Nilsson 2008-10-28 16:56:27 UTC
...and the ASHIFT is what is incoming to combine, despite there being a multiplication in the code, all fine and by definition.
Comment 3 Hans-Peter Nilsson 2008-11-01 22:17:31 UTC
Subject: Bug 37939

Author: hp
Date: Sat Nov  1 22:16:09 2008
New Revision: 141524

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141524
Log:
	PR target/37939
	* config/cris/cris.c (cris_rtx_costs) <MULT>: Return 0 for an ADDI
	operand.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/cris/cris.c

Comment 4 Hans-Peter Nilsson 2008-11-01 22:20:48 UTC
Subject: Bug 37939

Author: hp
Date: Sat Nov  1 22:19:26 2008
New Revision: 141525

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141525
Log:
	PR target/37939
	* gcc.target/cris/biap.c: New test.

Added:
    trunk/gcc/testsuite/gcc.target/cris/biap.c
Modified:
    trunk/gcc/testsuite/ChangeLog

Comment 5 Hans-Peter Nilsson 2008-11-01 22:28:05 UTC
Subject: Bug 37939

Author: hp
Date: Sat Nov  1 22:26:43 2008
New Revision: 141526

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141526
Log:
	PR target/37939
	* config/cris/cris.c (cris_rtx_costs) <MULT>: Return 0 for an ADDI
	operand.

Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/config/cris/cris.c

Comment 6 Hans-Peter Nilsson 2008-11-01 22:29:50 UTC
Subject: Bug 37939

Author: hp
Date: Sat Nov  1 22:28:28 2008
New Revision: 141527

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141527
Log:
	PR target/37939
	* gcc.target/cris/biap.c: New test.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/gcc.target/cris/biap.c
Modified:
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

Comment 7 Hans-Peter Nilsson 2008-11-01 23:04:53 UTC
Fixed as per <http://gcc.gnu.org/ml/gcc-patches/2008-11/msg00025.html>.
(I'm dropping 4.2).