diff mbox

[wide-int] Add a fast path for multiplication by 0

Message ID 877gbrtq70.fsf@talisman.default
State New
Headers show

Commit Message

Richard Sandiford Nov. 29, 2013, 11:14 a.m. UTC
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?

Thanks,
Richard

Comments

Richard Biener Nov. 29, 2013, 11:40 a.m. UTC | #1
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?

Thanks,
Richard.

> Thanks,
> Richard
>
>
> Index: gcc/wide-int.cc
> ===================================================================
> --- gcc/wide-int.cc     2013-11-29 10:50:46.594705157 +0000
> +++ gcc/wide-int.cc     2013-11-29 11:06:50.052557006 +0000
> @@ -1289,6 +1289,13 @@ wi::mul_internal (HOST_WIDE_INT *val, co
>    if (needs_overflow)
>      *overflow = false;
>
> +  /* This is a surprisingly common case, so do it first.  */
> +  if ((op1len == 1 && op1[0] == 0) || (op2len == 1 && op2[0] == 0))
> +    {
> +      val[0] = 0;
> +      return 1;
> +    }
> +
>    /* 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.  */
>
diff mbox

Patch

Index: gcc/wide-int.cc
===================================================================
--- gcc/wide-int.cc	2013-11-29 10:50:46.594705157 +0000
+++ gcc/wide-int.cc	2013-11-29 11:06:50.052557006 +0000
@@ -1289,6 +1289,13 @@  wi::mul_internal (HOST_WIDE_INT *val, co
   if (needs_overflow)
     *overflow = false;
 
+  /* This is a surprisingly common case, so do it first.  */
+  if ((op1len == 1 && op1[0] == 0) || (op2len == 1 && op2[0] == 0))
+    {
+      val[0] = 0;
+      return 1;
+    }
+
   /* 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.  */