This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[preliminary patch] Optimize mov in h8300 port (revised!)
- To: gcc-patches at gcc dot gnu dot org
- Subject: [preliminary patch] Optimize mov in h8300 port (revised!)
- From: Kazu Hirata <kazu at hxi dot com>
- CC: law at cygnus dot com
Hi,
> Or one could write this in a generic way and have it controlled by
> the cost of the various ways to load up the constant.
I started to tweak const_costs() in config/h8300/h8300.c. Is the
attached patch in the right direction?
As you suggested, I am looking at how well newlib gets compiled.
Under stdio, stdlib, and math, I counted the number of lines in the
assembly output (direct from gcc, not objdump). I got:
stdio stdlib math
original 8059 11615 33319
patched 8034 11591 33319
So I see some marginal improvement. I see both good and bad things
happening. The math library did change; it is just a coincidence that
the number of lines stayed the same. Here are some noteworthy
differences.
Good (1):
This is due to reload_cse_move2add. (Thank you, Jeff, for letting me
know this!) This is a kind of improvement that does not show up in
the number of assembly instructions. mov.w takes 4 bytes, and adds 2
bytes.
- mov.w #1,r3
+ adds #1,r3
Good (2):
Sometimes knowing a reg being 0 results in a fewer branches. A common
scenario would be a function having a sanity check at its beginning
like "if (p == NULL) return 0;". I see the same happen for -1 as
well.
mov.w r0,r0
beq .L3
mov.w #1,r0
- bra .L2
.L3:
- sub.w r0,r0
-.L2:
rts
Bad (1):
Sometimes a desire to reuse a reg to save constant-loading time
results in more register usage (and more longevity!?). The following
function simply got worse with other differences in the function
having no effect on either speed or space.
@@ -10,8 +10,9 @@
__init_signal_r:
push r4
+ push r5
mov.w r0,r4
Bad (2):
I haven't figured out how this is caused. Ugly.
- btst #1,r2l
+ mov.w r2,r5
+ and #2,r5l
+ and #0,r5h
+ mov.w r5,r5
Bad (3):
Uglier. matherr() should just return 0. Haven't chased this one,
either.
_matherr:
+ mov.w @(6,r0),r1
+ mov.w @(4,r0),r0
+ mov.w r1,@-r7
+ mov.w r0,@-r7
+ jsr @___nesf2
+ adds #2,r7
+ adds #2,r7
+ mov.w r0,r0
+ beq .L3
sub.w r0,r0
+.L3:
rts
Here is the patch for config/h8300/h8300.c. No change in h8300.md! :-)
Kazu Hirata
@@ -852,9 +872,10 @@ function_arg (cum, mode, type, named)
/* Return the cost of the rtx R with code CODE. */
int
-const_costs (r, c)
+const_costs (r, c, outer_code)
rtx r;
enum rtx_code c;
+ enum rtx_code outer_code;
{
switch (c)
{
@@ -862,19 +883,19 @@ const_costs (r, c)
switch (INTVAL (r))
{
case 0:
+ return (outer_code == SET) ? 1 : 0;
case 1:
case 2:
case -1:
case -2:
- return 0;
+ return (outer_code == SET) ? 2 : 1;
case 4:
case -4:
if (TARGET_H8300H || TARGET_H8300S)
- return 0;
- else
- return 1;
+ return (outer_code == SET) ? 2 : 1;
+ /* Fall through. */
default:
- return 1;
+ return 2;
}
case CONST: