Performance booster patch (short patch, lengthly discussion)
Richard Gorton
gorton@amt.tay1.dec.com
Tue Feb 17 06:39:00 GMT 1998
[Also posted in slightly different form to gcc2]
Here's a small patch which improves performance on alpha and arm (the two
architectures I tried this on) The diffs are based upon the
egcs-980205 snapshot.
diff -c fold-const.c fold-const.c.orig
*** fold-const.c Mon Feb 16 15:29:58 1998
--- fold-const.c.orig Sun Feb 1 06:47:57 1998
***************
*** 1928,1936 ****
primother = get_narrower (other, &unsignedpo);
correct_width = TYPE_PRECISION (TREE_TYPE (arg1));
- /* Relax width constraint to permit mixing of unsigned/signed operations */
- correct_width += (TREE_UNSIGNED(arg0) | TREE_UNSIGNED(arg1)
- | TREE_UNSIGNED(other));
if (unsignedp1 == unsignedpo
&& TYPE_PRECISION (TREE_TYPE (primarg1)) < correct_width
&& TYPE_PRECISION (TREE_TYPE (primother)) < correct_width)
--- 1928,1933 ----
-----------------------------------------
This particular patch is about a 3% winner to overall SPECint95
on Alpha (when applied to my gcc-2.8.0 baseline) - here are two
specific cases (from m88ksim) which now generate better code:
-----------------------------------------
extern int m88000_time_left;
unsigned int split_minval(int x, unsigned int y)
{
m88000_time_left = (( x )<( y )?( x ):( y )) ;
return 0;
}
int original_problem(int x, unsigned int y)
{
m88000_time_left -= ( m88000_time_left < y ? m88000_time_left : y );
}
-----------------------------------------
Discussion:
When the datatypes of x and y are the same, gcc would generate good
code. But when one is unsigned, and the other is signed, the rtl
was generating branches instead of if-then-set-x-else-set-y
and specifically not hitting the relevant min/max patterns.
I did note in tree.c, that get_narrower() only sets the unsignedp_ptr
argument when a NOP_EXPR tree is fed to it. In the example case I
encountered, it was a PARM_DECL - I don't know if this is a symptom of
a front-end problem or not.
It is possible that this patch won't work on an architecture where
unsigned data types have more bits of precision than signed data types,
and instructions to do compares of signed vs. unsigned don't exist.
However, I can't think of any.
While the patch seems to work correctly on all of the code I threw
at it (SPECint95), it feels like a sledgehammer solution to me.
If anyone can think of a better solution, I'm eager to hear about it.
Regards,
Rick
Richard Gorton All standard disclaimers apply.
AMT/Digital Semiconductor Projects: DECmigrate (mx), FreePort Express,
Digital Equipment Corporation Linux/Alpha, JavaOS, StrongARM,
Reply-to: gorton@tallis.enet.dec.com Network Computers (SHARK)
http://www.digital.com/info/semiconductor/amt
More information about the Gcc
mailing list