This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [wide-int] Add a fast path for multiplication by 0
- From: Richard Sandiford <rdsandiford at googlemail dot com>
- To: Richard Biener <richard dot guenther at gmail dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Kenneth Zadeck <zadeck at naturalbridge dot com>, Mike Stump <mikestump at comcast dot net>
- Date: Fri, 29 Nov 2013 15:07:29 +0000
- Subject: Re: [wide-int] Add a fast path for multiplication by 0
- Authentication-results: sourceware.org; auth=none
- References: <877gbrtq70 dot fsf at talisman dot default> <CAFiYyc27o9dYhh2cwGzas2npmiBh3NUzOTea+BvaE22YZ5MRtg at mail dot gmail dot com>
Richard Biener <richard.guenther@gmail.com> writes:
> On Fri, Nov 29, 2013 at 12:14 PM, Richard Sandiford
> <rdsandiford@googlemail.com> wrote:
>> In the fold-const.ii testcase, well over half of the mul_internal calls
>> were for multiplication by 0 (106038 out of 169355). This patch adds
>> an early-out for that.
>>
>> Tested on x86_64-linux-gnu. OK to install?
>
> Ok. Did you check how many of the remaining are multiplies by 1?
Turns out to be 9685, which is probably enough to justify a special case.
Tested on x86_64-linux-gnu. OK to install?
Thanks,
Richard
Index: gcc/wide-int.cc
===================================================================
--- gcc/wide-int.cc 2013-11-29 15:04:41.177142418 +0000
+++ gcc/wide-int.cc 2013-11-29 15:05:36.482424592 +0000
@@ -1296,6 +1296,20 @@ wi::mul_internal (HOST_WIDE_INT *val, co
return 1;
}
+ /* Handle multiplications by 1. */
+ if (op1len == 1 && op1[0] == 1)
+ {
+ for (i = 0; i < op2len; i++)
+ val[i] = op2[i];
+ return op2len;
+ }
+ if (op2len == 1 && op2[0] == 1)
+ {
+ for (i = 0; i < op1len; i++)
+ val[i] = op1[i];
+ return op1len;
+ }
+
/* If we need to check for overflow, we can only do half wide
multiplies quickly because we need to look at the top bits to
check for the overflow. */