From patchwork Thu Sep 7 08:40:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 810910 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-461662-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="BV/O/YQp"; dkim-atps=neutral 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 3xnv6s55G4z9sRV for ; Thu, 7 Sep 2017 18:40:51 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=HSWpUwaapr6c1Xx83mrY0rHsz0K6u gpvt3hT1FauQ+bUc/DR5c/9B+1x2ibWyyMtFN2V39nnXNSemk/TfJ49BYjA3gtO+ /NSB72W3CqbhBQKY+FsaU+27dgdRC+bQerntwWDS+3XLO4GMObbmIUtkJFNc/mb5 5iHosQ4aSJILgc= 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=2x4UVcMkw47mc5xdk2aPv1azP4M=; b=BV/ O/YQpBdyXm/p0YuyK0pkboif8GUISSXZlTThfoRkwTeWVRN13coWnU8fLf0Q2TDn jLWd3SjKTZ+/xUT1HFKKMPi6+LdE+uEIKzpcbVqgBjHXFK3QmhxdISeE+x7vF7fa A4jJ82pxJGbm+n39zO4kMKS3e4Afpd4tTu3QtQ3s= Received: (qmail 125634 invoked by alias); 7 Sep 2017 08:40:41 -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 119737 invoked by uid 89); 7 Sep 2017 08:40:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 07 Sep 2017 08:40:36 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4265D4E4CA; Thu, 7 Sep 2017 08:40:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4265D4E4CA Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jakub@redhat.com Received: from tucnak.zalov.cz (ovpn-116-33.ams2.redhat.com [10.36.116.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DA23461B70; Thu, 7 Sep 2017 08:40:34 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id v878eWcl014576; Thu, 7 Sep 2017 10:40:32 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v878eU3Q014575; Thu, 7 Sep 2017 10:40:30 +0200 Date: Thu, 7 Sep 2017 10:40:30 +0200 From: Jakub Jelinek To: Segher Boessenkool Cc: David Edelsohn , gcc-patches@gcc.gnu.org Subject: [PATCH] Fix powerpc ICE with __builtin_vec_ld on an array (PR target/82112) Message-ID: <20170907084030.GS2323@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes Hi! The C and C++ FE handle resolve_overloaded_builtin differently, the C FE calls it when e.g. array-to-pointer and function-to-pointer conversions are already done on the arguments, while C++ FE does that only much later. The c-common code e.g. for __sync/__atomic builtins deals with that e.g. by: if (TREE_CODE (type) == ARRAY_TYPE) { /* Force array-to-pointer decay for C++. */ gcc_assert (c_dialect_cxx()); (*params)[0] = default_conversion ((*params)[0]); type = TREE_TYPE ((*params)[0]); } while the rs6000 md hook uses default_conversion only in one spot (the generic handling), but for vec_ld and vec_st does something on its own. What is even worse is that for vec_ld, it does that too late, there is a fold_convert in between for the case where the element type is qualified, and that only works if the argument is pointer, not array (in which case it ICEs). So, the following patch moves the vec_ld conversion earlier and for both vec_ld and vec_st uses what c-common as well as later altivec_resolve_overloaded_builtin uses. Bootstrapped/regtested on powerpc64-linux (regtest with {,-m32}), ok for trunk? 2017-09-07 Jakub Jelinek PR target/82112 * config/rs6000/rs6000-c.c (altivec_resolve_overloaded_builtin): For ALTIVEC_BUILTIN_VEC_LD if arg1 has array type call default_conversion on it early, rather than manual conversion late. For ALTIVEC_BUILTIN_VEC_ST if arg2 has array type call default_conversion instead of performing manual conversion. * g++.dg/ext/altivec-18.C: New test. Jakub --- gcc/config/rs6000/rs6000-c.c.jj 2017-09-01 09:26:55.000000000 +0200 +++ gcc/config/rs6000/rs6000-c.c 2017-09-06 15:43:11.719590365 +0200 @@ -6478,7 +6478,14 @@ altivec_resolve_overloaded_builtin (loca /* Strip qualifiers like "const" from the pointer arg. */ tree arg1_type = TREE_TYPE (arg1); - if (!POINTER_TYPE_P (arg1_type) && TREE_CODE (arg1_type) != ARRAY_TYPE) + if (TREE_CODE (arg1_type) == ARRAY_TYPE) + { + /* Force array-to-pointer decay for C++. */ + gcc_assert (c_dialect_cxx ()); + arg1 = default_conversion (arg1); + arg1_type = TREE_TYPE (arg1); + } + if (!POINTER_TYPE_P (arg1_type)) goto bad; tree inner_type = TREE_TYPE (arg1_type); @@ -6498,15 +6505,6 @@ altivec_resolve_overloaded_builtin (loca if (!ptrofftype_p (TREE_TYPE (arg0))) arg0 = build1 (NOP_EXPR, sizetype, arg0); - tree arg1_type = TREE_TYPE (arg1); - if (TREE_CODE (arg1_type) == ARRAY_TYPE) - { - arg1_type = TYPE_POINTER_TO (TREE_TYPE (arg1_type)); - tree const0 = build_int_cstu (sizetype, 0); - tree arg1_elt0 = build_array_ref (loc, arg1, const0); - arg1 = build1 (ADDR_EXPR, arg1_type, arg1_elt0); - } - tree addr = fold_build2_loc (loc, POINTER_PLUS_EXPR, arg1_type, arg1, arg0); tree aligned = fold_build2_loc (loc, BIT_AND_EXPR, arg1_type, addr, @@ -6563,10 +6561,10 @@ altivec_resolve_overloaded_builtin (loca tree arg2_type = TREE_TYPE (arg2); if (TREE_CODE (arg2_type) == ARRAY_TYPE) { - arg2_type = TYPE_POINTER_TO (TREE_TYPE (arg2_type)); - tree const0 = build_int_cstu (sizetype, 0); - tree arg2_elt0 = build_array_ref (loc, arg2, const0); - arg2 = build1 (ADDR_EXPR, arg2_type, arg2_elt0); + /* Force array-to-pointer decay for C++. */ + gcc_assert (c_dialect_cxx ()); + arg2 = default_conversion (arg2); + arg2_type = TREE_TYPE (arg2); } /* Find the built-in to make sure a compatible one exists; if not --- gcc/testsuite/g++.dg/ext/altivec-18.C.jj 2017-09-06 15:45:00.673295858 +0200 +++ gcc/testsuite/g++.dg/ext/altivec-18.C 2017-09-06 15:45:36.274872713 +0200 @@ -0,0 +1,14 @@ +// PR target/82112 +// { dg-do compile { target powerpc*-*-* } } +// { dg-require-effective-target powerpc_altivec_ok } +// { dg-options "-save-temps -maltivec" } + +#include + +__attribute__((aligned (16))) extern const unsigned char c[16]; + +void +foo (void) +{ + vec_ld (0, c); +}