From patchwork Thu Sep 18 12:19:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Lawrence X-Patchwork-Id: 390779 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id DD8E214012C for ; Thu, 18 Sep 2014 22:19:18 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=xqbzRkko+lvMNBUyD 79MpRVEmFt0fmAk2+QL9b0EvZjJFYnyoOyZVtBgxjCEVN+5pP7C3dbLkcFFA+2R+ a3c6Q1PSj3678xsgtjziRmZebAIldg2Ucyfw4T/9UMd5AkN7A9bdDuwvfS9qNX8V Zz5kZRgFRL2Vd2/OsRrKRxA5AY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=m3H8dECtr6kv6kbmSbLlHl+ wI7I=; b=KtyxbcyqgTTxwCq+P1X84vghSJGZBJvMFhIjli3HsUwi0yA7x2MI972 wfnfTQfjHaoMGZIWchzv4v46dkfi8Q4rAKQleKxW5E4zHuapVwe83eFUAd4OYr0Y LfTX4CaIrSO1wbYvO1ebiTKHqEdLdvArE2FNx1s//lwVlcP+cwUE= Received: (qmail 15158 invoked by alias); 18 Sep 2014 12:19:12 -0000 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 Received: (qmail 15144 invoked by uid 89); 18 Sep 2014 12:19:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: service87.mimecast.com Received: from service87.mimecast.com (HELO service87.mimecast.com) (91.220.42.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 18 Sep 2014 12:19:10 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Thu, 18 Sep 2014 13:19:06 +0100 Received: from [10.1.209.51] ([10.1.255.212]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 18 Sep 2014 13:19:04 +0100 Message-ID: <541ACDB7.2010407@arm.com> Date: Thu, 18 Sep 2014 13:19:03 +0100 From: Alan Lawrence User-Agent: Thunderbird 2.0.0.24 (X11/20101213) MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: David Edelsohn , Aldy Hernandez Subject: [PATCH 7/14][Testsuite] Add tests of reductions using whole-vector-shifts (multiplication) References: <541AC4D2.9040901@arm.com> In-Reply-To: <541AC4D2.9040901@arm.com> X-MC-Unique: 114091813190600201 X-IsSubscribed: yes For reduction operations (e.g. multiply) that don't have such a tree code ,or where the target platform doesn't define an optab handler for the tree code, we can perform the reduction using a series of log(N) shifts (where N = #elements in vector), using the VEC_RSHIFT_EXPR=whole-vector-shift tree code (if the platform handles the vec_shr_optab). First stage is to add some tests of non-(min/max/plus) reductions; here, multiplies. The first is designed to be non-foldable, so we make sure the architectural instructions line up with what the tree codes specify. The second is designed to be easily constant-propagated, to test the (currently endianness-dependent) constant folding code. In lib/target-supports.exp, I've defined a new check_effective_target_whole_vector_shift, which I intended to define to true for platforms with the vec_shr optab. However, I've not managed to make this test pass on PowerPC - even with -maltivec, -fdump-tree-vect-details gives me a message about the target not supporting vector multiplication - so I've omitted PowerPC from the whole_vector_shift. This doesn't feel right, suggestions welcomed from PowerPC maintainers? Tests passing on arm-none-eabi and x86_64-none-linux-gnu; also verified the scan-tree-dump part works on ia64-none-linux-gnu (by compiling to assembly only). (Tests are not run on AArch64, because we have no vec_shr_optab at this point; PowerPC, as above; or MIPS, as check_effective_target_vect_int_mult yields 0.) gcc/testsuite/ChangeLog: * lib/target-supports.exp (check_effective_target_whole_vector_shift): New. * gcc.dg/vect/vect-reduc-mul_1.c: New test. * gcc.dg/vect/vect-reduc-mul_2.c: New test. diff --git a/gcc/testsuite/gcc.dg/vect/vect-reduc-mul_1.c b/gcc/testsuite/gcc.dg/vect/vect-reduc-mul_1.c new file mode 100644 index 0000000000000000000000000000000000000000..44f026ff9b561bcf314224c44d51bdd19448851b --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-reduc-mul_1.c @@ -0,0 +1,36 @@ +/* { dg-require-effective-target vect_int_mult } */ +/* { dg-require-effective-target whole_vector_shift } */ + +/* Write a reduction loop to be reduced using vector shifts. */ + +extern void abort(void); + +unsigned char in[16]; + +int +main (unsigned char argc, char **argv) +{ + unsigned char i = 0; + unsigned char sum = 1; + + for (i = 0; i < 16; i++) + in[i] = i + i + 1; + + /* Prevent constant propagation of the entire loop below. */ + asm volatile ("" : : : "memory"); + + for (i = 0; i < 16; i++) + sum *= in[i]; + + if (sum != 33) + { + __builtin_printf("Failed %d\n", sum); + abort(); + } + + return 0; +} + +/* { dg-final { scan-tree-dump "Reduce using vector shifts" "vect" } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ + diff --git a/gcc/testsuite/gcc.dg/vect/vect-reduc-mul_2.c b/gcc/testsuite/gcc.dg/vect/vect-reduc-mul_2.c new file mode 100644 index 0000000000000000000000000000000000000000..414fba7a5c96c4dd89030682492edb57ebba3b16 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-reduc-mul_2.c @@ -0,0 +1,32 @@ +/* { dg-require-effective-target vect_int_mult } */ +/* { dg-require-effective-target whole_vector_shift } */ + +/* Write a reduction loop to be reduced using vector shifts and folded. */ + +extern void abort(void); + +int +main (unsigned char argc, char **argv) +{ + unsigned char in[16]; + unsigned char i = 0; + unsigned char sum = 1; + + for (i = 0; i < 16; i++) + in[i] = i + i + 1; + + for (i = 0; i < 16; i++) + sum *= in[i]; + + if (sum != 33) + { + __builtin_printf("Failed %d\n", sum); + abort(); + } + + return 0; +} + +/* { dg-final { scan-tree-dump "Reduce using vector shifts" "vect" } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ + diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index fa5137ea472e1773be60759caad32bbc7ab4c551..0f4bebd533c9268adfcd4ed250f06fca825c92b1 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -3320,6 +3320,22 @@ proc check_effective_target_vect_shift { } { return $et_vect_shift_saved } +proc check_effective_target_whole_vector_shift { } { + if { [istarget x86_64-*-*] + || [istarget ia64-*-*] + || ([check_effective_target_arm32] + && [check_effective_target_arm_little_endian]) + || ([istarget mips*-*-*] + && [check_effective_target_mips_loongson]) } { + set answer 1 + } else { + set answer 0 + } + + verbose "check_effective_target_vect_long: returning $answer" 2 + return $answer +} + # Return 1 if the target supports vector bswap operations. proc check_effective_target_vect_bswap { } {