From patchwork Thu Dec 9 16:19:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Stubbs X-Patchwork-Id: 74928 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 6790CB70DA for ; Fri, 10 Dec 2010 03:19:43 +1100 (EST) Received: (qmail 19699 invoked by alias); 9 Dec 2010 16:19:40 -0000 Received: (qmail 19684 invoked by uid 22791); 9 Dec 2010 16:19:37 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 09 Dec 2010 16:19:32 +0000 Received: (qmail 30734 invoked from network); 9 Dec 2010 16:19:31 -0000 Received: from unknown (HELO ?192.168.0.104?) (ams@127.0.0.2) by mail.codesourcery.com with ESMTPA; 9 Dec 2010 16:19:31 -0000 Message-ID: <4D01018F.3020108@codesourcery.com> Date: Thu, 09 Dec 2010 16:19:27 +0000 From: Andrew Stubbs User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.12) Gecko/20101027 Lightning/1.0b2 Thunderbird/3.1.6 MIME-Version: 1.0 To: gcc-patches@gcc.gnu.org Subject: [patch][ARM] Fix 16-bit -> 64-bit multiply and accumulate Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org The attached patch fixes a bug that prevented smlalbb being generated, even though it was present in the machine description. The problem was that the MULT portion of the maddhidi4 pattern did not match the mulhisi3 pattern, and so combine could not build matching patterns. My patch simply adjusts the (internal) modes and extends in the maddhidi4 pattern so that they match. The externally visible modes remain unaltered. Test case: long long foolong (long long x, short *a, short *b) { return x + *a * *b; } Before, compiled with "-O2 -mcpu=cortex-a8 -mthumb": ldrh r2, [r2, #0] ldrh r3, [r3, #0] smulbb r3, r2, r3 adds r0, r0, r3 adc r1, r1, r3, asr #31 bx lr The compiler is forced to do the multiply and addition operation separately. After: ldrh r2, [r2, #0] ldrh r3, [r3, #0] smlalbb r0, r1, r2, r3 bx lr OK to commit, once stage 1 opens again? Andrew 2010-12-09 Andrew Stubbs gcc/ * config/arm/arm.md (*maddhidi4): Make mult mode match mulhisi3 for combine. gcc/testsuite/ * gcc.target/arm/smlalbb.c: New file. --- src/gcc-mainline/gcc/config/arm/arm.md | 9 +++++---- .../gcc/testsuite/gcc.target/arm/smlalbb.c | 8 ++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 src/gcc-mainline/gcc/testsuite/gcc.target/arm/smlalbb.c diff --git a/src/gcc-mainline/gcc/config/arm/arm.md b/src/gcc-mainline/gcc/config/arm/arm.md index c816126..dc9da52 100644 --- a/src/gcc-mainline/gcc/config/arm/arm.md +++ b/src/gcc-mainline/gcc/config/arm/arm.md @@ -1814,10 +1814,11 @@ (define_insn "*maddhidi4" [(set (match_operand:DI 0 "s_register_operand" "=r") (plus:DI - (mult:DI (sign_extend:DI - (match_operand:HI 1 "s_register_operand" "%r")) - (sign_extend:DI - (match_operand:HI 2 "s_register_operand" "r"))) + (sign_extend:DI + (mult:SI (sign_extend:SI + (match_operand:HI 1 "s_register_operand" "%r")) + (sign_extend:SI + (match_operand:HI 2 "s_register_operand" "r")))) (match_operand:DI 3 "s_register_operand" "0")))] "TARGET_DSP_MULTIPLY" "smlalbb%?\\t%Q0, %R0, %1, %2" diff --git a/src/gcc-mainline/gcc/testsuite/gcc.target/arm/smlalbb.c b/src/gcc-mainline/gcc/testsuite/gcc.target/arm/smlalbb.c new file mode 100644 index 0000000..0e4dd70 --- /dev/null +++ b/src/gcc-mainline/gcc/testsuite/gcc.target/arm/smlalbb.c @@ -0,0 +1,8 @@ +/* Ensure the smlalbb pattern works. */ +/* { dg-options "-O2 -march=armv7-a" } */ +/* { dg-final { scan-assembler "smlalbb" } } */ + +long long foolong (long long x, short *a, short *b) +{ + return x + *a * *b; +}