This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] minor ashldi3 tweaks for x86
- From: Roger Sayle <roger at eyesopen dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 7 Sep 2004 19:31:41 -0600 (MDT)
- Subject: [PATCH] minor ashldi3 tweaks for x86
Honestly, I'm in stage3 bug-fix mode, but...
The following is a minor tweak to i386.c's ix86_split_ashldi function
to avoid creating shifts by small immediate constants on processors
where a short sequence of additions is preferable.
This patch has been tested on i686-pc-linux-gnu with a full bootstrap,
all default languages, and regression tested with a top-level "make -k
check" with no new failures.
2004-09-07 Roger Sayle <roger@eyesopen.com>
* config/i386/i386.c (ix86_expand_ashlsi3_const): New function to
expand a left shift by an immediate constant as either a ashl or
a sequence of additions.
(ix86_split_ashldi): Use new ix86_expand_ashlsi3_const function
instead of calling gen_ashlsi3 with a constant directly.
Index: config/i386/i386.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.c,v
retrieving revision 1.717
diff -c -3 -p -r1.717 i386.c
*** config/i386/i386.c 25 Aug 2004 09:52:12 -0000 1.717
--- config/i386/i386.c 6 Sep 2004 23:36:14 -0000
*************** ix86_split_long_move (rtx operands[])
*** 9875,9880 ****
--- 9875,9900 ----
return;
}
+ /* Helper function of ix86_split_ashldi used to generate an SImode
+ left shift by a constant, either using a single shift or
+ a sequence of add instructions. */
+
+ static void
+ ix86_expand_ashlsi3_const (rtx operand, int count)
+ {
+ if (count == 1)
+ emit_insn (gen_addsi3 (operand, operand, operand));
+ else if (!optimize_size
+ && count * ix86_cost->add <= ix86_cost->shift_const)
+ {
+ int i;
+ for (i=0; i<count; i++)
+ emit_insn (gen_addsi3 (operand, operand, operand));
+ }
+ else
+ emit_insn (gen_ashlsi3 (operand, operand, GEN_INT (count)));
+ }
+
void
ix86_split_ashldi (rtx *operands, rtx scratch)
{
*************** ix86_split_ashldi (rtx *operands, rtx sc
*** 9892,9905 ****
emit_move_insn (low[0], const0_rtx);
if (count > 32)
! emit_insn (gen_ashlsi3 (high[0], high[0], GEN_INT (count - 32)));
}
else
{
if (!rtx_equal_p (operands[0], operands[1]))
emit_move_insn (operands[0], operands[1]);
emit_insn (gen_x86_shld_1 (high[0], low[0], GEN_INT (count)));
! emit_insn (gen_ashlsi3 (low[0], low[0], GEN_INT (count)));
}
}
else
--- 9912,9925 ----
emit_move_insn (low[0], const0_rtx);
if (count > 32)
! ix86_expand_ashlsi3_const (high[0], count - 32);
}
else
{
if (!rtx_equal_p (operands[0], operands[1]))
emit_move_insn (operands[0], operands[1]);
emit_insn (gen_x86_shld_1 (high[0], low[0], GEN_INT (count)));
! ix86_expand_ashlsi3_const (low[0], count);
}
}
else
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833