From patchwork Fri Jul 22 15:38:25 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Stubbs X-Patchwork-Id: 3051 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 4E57123E52 for ; Fri, 22 Jul 2011 15:38:31 +0000 (UTC) Received: from mail-qy0-f180.google.com (mail-qy0-f180.google.com [209.85.216.180]) by fiordland.canonical.com (Postfix) with ESMTP id EE39AA18377 for ; Fri, 22 Jul 2011 15:38:30 +0000 (UTC) Received: by qyk30 with SMTP id 30so1683531qyk.11 for ; Fri, 22 Jul 2011 08:38:30 -0700 (PDT) Received: by 10.229.217.3 with SMTP id hk3mr1522817qcb.38.1311349110406; Fri, 22 Jul 2011 08:38:30 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.217.78 with SMTP id hl14cs17568qcb; Fri, 22 Jul 2011 08:38:30 -0700 (PDT) Received: by 10.151.25.15 with SMTP id c15mr1990761ybj.125.1311349109825; Fri, 22 Jul 2011 08:38:29 -0700 (PDT) Received: from mail.codesourcery.com (mail.codesourcery.com [38.113.113.100]) by mx.google.com with ESMTPS id l6si2285184ybg.29.2011.07.22.08.38.29 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 22 Jul 2011 08:38:29 -0700 (PDT) Received-SPF: pass (google.com: domain of ams@codesourcery.com designates 38.113.113.100 as permitted sender) client-ip=38.113.113.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ams@codesourcery.com designates 38.113.113.100 as permitted sender) smtp.mail=ams@codesourcery.com Received: (qmail 12849 invoked from network); 22 Jul 2011 15:38:28 -0000 Received: from unknown (HELO ?192.168.0.104?) (ams@127.0.0.2) by mail.codesourcery.com with ESMTPA; 22 Jul 2011 15:38:28 -0000 Message-ID: <4E299971.4010905@codesourcery.com> Date: Fri, 22 Jul 2011 16:38:25 +0100 From: Andrew Stubbs Organization: CodeSourcery User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20110627 Thunderbird/5.0 MIME-Version: 1.0 To: Richard Guenther CC: gcc-patches@gcc.gnu.org, patches@linaro.org Subject: Re: [PATCH (9/7)] Widening multiplies with constant inputs References: <4E034EF2.3070503@codesourcery.com> <4E282148.9080100@codesourcery.com> <4E2965A5.1080301@codesourcery.com> <4E2967FC.3090101@codesourcery.com> In-Reply-To: On 22/07/11 13:17, Richard Guenther wrote: > Ok. I found a NULL-pointer dereference bug. Fixed in the attached. I'll commit this version when the rest of my testing is complete. Thanks Andrew 2011-07-22 Andrew Stubbs gcc/ * tree-ssa-math-opts.c (is_widening_mult_rhs_p): Handle constants beyond conversions. (convert_mult_to_widen): Convert constant inputs to the right type. (convert_plusminus_to_widen): Don't automatically reject inputs that are not an SSA_NAME. Convert constant inputs to the right type. gcc/testsuite/ * gcc.target/arm/wmul-11.c: New file. * gcc.target/arm/wmul-12.c: New file. * gcc.target/arm/wmul-13.c: New file. --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/wmul-11.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-require-effective-target arm_dsp } */ + +long long +foo (int *b) +{ + return 10 * (long long)*b; +} + +/* { dg-final { scan-assembler "smull" } } */ --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/wmul-12.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-require-effective-target arm_dsp } */ + +long long +foo (int *b, int *c) +{ + int tmp = *b * *c; + return 10 + (long long)tmp; +} + +/* { dg-final { scan-assembler "smlal" } } */ --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/wmul-13.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-require-effective-target arm_dsp } */ + +long long +foo (int *a, int *b) +{ + return *a + (long long)*b * 10; +} + +/* { dg-final { scan-assembler "smlal" } } */ --- a/gcc/tree-ssa-math-opts.c +++ b/gcc/tree-ssa-math-opts.c @@ -1997,6 +1997,13 @@ is_widening_mult_rhs_p (tree type, tree rhs, tree *type_out, type1 = TREE_TYPE (rhs1); } + if (rhs1 && TREE_CODE (rhs1) == INTEGER_CST) + { + *new_rhs_out = rhs1; + *type_out = NULL; + return true; + } + if (TREE_CODE (type1) != TREE_CODE (type) || TYPE_PRECISION (type1) * 2 > TYPE_PRECISION (type)) return false; @@ -2170,6 +2177,12 @@ convert_mult_to_widen (gimple stmt, gimple_stmt_iterator *gsi) rhs2 = build_and_insert_cast (gsi, loc, tmp, rhs2); } + /* Handle constants. */ + if (TREE_CODE (rhs1) == INTEGER_CST) + rhs1 = fold_convert (type1, rhs1); + if (TREE_CODE (rhs2) == INTEGER_CST) + rhs2 = fold_convert (type2, rhs2); + gimple_assign_set_rhs1 (stmt, rhs1); gimple_assign_set_rhs2 (stmt, rhs2); gimple_assign_set_rhs_code (stmt, WIDEN_MULT_EXPR); @@ -2221,8 +2234,6 @@ convert_plusminus_to_widen (gimple_stmt_iterator *gsi, gimple stmt, if (is_gimple_assign (rhs1_stmt)) rhs1_code = gimple_assign_rhs_code (rhs1_stmt); } - else - return false; if (TREE_CODE (rhs2) == SSA_NAME) { @@ -2230,8 +2241,6 @@ convert_plusminus_to_widen (gimple_stmt_iterator *gsi, gimple stmt, if (is_gimple_assign (rhs2_stmt)) rhs2_code = gimple_assign_rhs_code (rhs2_stmt); } - else - return false; /* Allow for one conversion statement between the multiply and addition/subtraction statement. If there are more than @@ -2379,6 +2388,12 @@ convert_plusminus_to_widen (gimple_stmt_iterator *gsi, gimple stmt, add_rhs = build_and_insert_cast (gsi, loc, create_tmp_var (type, NULL), add_rhs); + /* Handle constants. */ + if (TREE_CODE (mult_rhs1) == INTEGER_CST) + rhs1 = fold_convert (type1, mult_rhs1); + if (TREE_CODE (mult_rhs2) == INTEGER_CST) + rhs2 = fold_convert (type2, mult_rhs2); + gimple_assign_set_rhs_with_ops_1 (gsi, wmult_code, mult_rhs1, mult_rhs2, add_rhs); update_stmt (gsi_stmt (*gsi));