From patchwork Tue Jul 18 12:50:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lyon X-Patchwork-Id: 108130 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp5877768qge; Tue, 18 Jul 2017 05:51:15 -0700 (PDT) X-Received: by 10.101.90.75 with SMTP id z11mr1631113pgs.58.1500382275117; Tue, 18 Jul 2017 05:51:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500382275; cv=none; d=google.com; s=arc-20160816; b=TWBCkW0Zm/qZNP6uQ91BPL0dJWpwlSa9etdXSjr4oB5sK4yuNyFb6xU2Uyw54Ibuc0 3dRdMYpAY6sWe5qy4JcWIvQYfggjxV4RJwoTMG2cfN25XyrLuo9L/aKxCw7WsKbgo9u7 2kQoXGQMLETEp8UMUc4dtq/Hfq8SOQtt3kORwImXHXBniC/aVmWU8QnxPPMKTHd/aiKn 2jw0oqXzoiW+gRLSVESVCe81eK6BJxKts3i/V3XJ1E8fCv8Fa/nigiXSRXh6iKE3wcRb La0ZuuYwSBROQIF5nb0jksoG/hjQ0ZF6XrKaK/ZEtb1+GtYGzGAGvMbGd4NBBITjRGOH jWVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:mime-version:delivered-to:sender :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=IuXEl3zFOMGMUfRatXIs5LHLSIMKD4SwvwdrxBT0mnk=; b=jOFm6QlqV+OUvgM2Jaqp7KK5vVbVp3VhYZDxDMa/jqcE+YaW5xlp9lTlI+75uQLG3E qZ4LOITqMOtcsSNyGy2qoNxIHLq11q4TQ/7Q00UfpMBfgoSgPcLGcom6XVSh0rwtewYo +nb80fOGVBVUwpMvk02PxWDk9JgaeKDjATY42IGb0ndfmSImxAXdBoSVXGHT06DA94dG u4Nl8PE/7tPXKq3AII9n623b9lAZrPbELg9UAkEquBKgAk3cgUjb1tb5FHHRnh1v0lH/ Q0pPiS9Ey5PFEhVbGhl3CAS3cyhGlvXTsRAj+0Led6f0mnOC6feT+C4DjmqR1g8SCHPx WJxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.b=qr8/a+Sz; spf=pass (google.com: domain of gcc-patches-return-458414-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-458414-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id e4si1752463plk.618.2017.07.18.05.51.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Jul 2017 05:51:15 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-458414-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.b=qr8/a+Sz; spf=pass (google.com: domain of gcc-patches-return-458414-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-458414-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=PrZc+vv8e3xETYuhE+mpwRGuoz/ZB0E79h38kpCaGhCcaM J8QxQ3d2j3A6jX5xBAqxpWcHPyiM29l56TLk0xphnKWeBJ5Vxykup8GgrT3NWlZm nkY2rP60Ongb3K4zT6Oq4la/xyaw5K/AjvALOBW1HLmjxsqWIqP0p1L1Q58gA= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=k0A/loQyHJUilppm+G1Yvx0ZYaA=; b=qr8/a+SzqYeHxwl9kNSR IINpTI5cXkxLEqIh4FGBFpebj1ZircBhGKd0N4DH7W5bp/QtsT01t+A8Zzpvg2S9 r44xPofFlxZZhgMfN1KV0kaM24RJ7+8qiq97R8CVqrJZK6x9s+mtXvQw5MDY+8g+ tqWF4Zxue5gFOywHntoJsTs= Received: (qmail 95166 invoked by alias); 18 Jul 2017 12:51:00 -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 95154 invoked by uid 89); 18 Jul 2017 12:50:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=sum X-HELO: mail-ua0-f171.google.com Received: from mail-ua0-f171.google.com (HELO mail-ua0-f171.google.com) (209.85.217.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 18 Jul 2017 12:50:57 +0000 Received: by mail-ua0-f171.google.com with SMTP id y47so6584571uag.0 for ; Tue, 18 Jul 2017 05:50:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=NI67SCis4SO4c7A7JdQkRBAaafdes5RcLAUE7WdzOYY=; b=TtD7MQ9ZjW5dYdt9ZslCgLy3NWYildlveFIOil4p+XNzwq2rfJ4+fNjwd32NTFAT5F M6uv1I8XPgnXEKmxLnhEChrVvUq4G6a/yoJ1VfEjVcqZtb+lk+VkoUrA+SzT9J9LYsI4 EPMRHZM8bPm6VXTAyAZXG0qOsPdzH59AN72hzX5fAWeiAu5Z5mK+l/qERDraGLhwCnaq RIx379dIyNyc1yjAyOF4PWVXmh9nuRf3yoy8CCe/JYo02qBZJB29DbkWJc3V+yc4w+xr GNSrhpJI3MEj7YKoUbnsOeh3PsGxpFWy5KEgORxOgWxXmzg7CZyp9KoHwABj2c1kWZef Z6Ig== X-Gm-Message-State: AIVw110EnucNuZmAzKTvVHgmurqPr8eIsU1uA/psasHAcQjeKvXtIMQ4 JYs7OCkaRbSS/TuNgXc6XgodMkJuSjG/OZflug== X-Received: by 10.31.3.135 with SMTP id f7mr782099vki.120.1500382255204; Tue, 18 Jul 2017 05:50:55 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.153.196 with HTTP; Tue, 18 Jul 2017 05:50:54 -0700 (PDT) From: Christophe Lyon Date: Tue, 18 Jul 2017 14:50:54 +0200 Message-ID: Subject: [AArch64], patch] PR71727 fix -mstrict-align To: "gcc-patches@gcc.gnu.org" X-IsSubscribed: yes Hello, I've received a complaint that GCC for AArch64 would generate vectorized code relying on unaligned memory accesses even when using -mstrict-align. This is a problem for code where such accesses lead to memory faults. A previous patch (r243333) introduced aarch64_builtin_support_vector_misalignment, which rejects such accesses when the element size is 64 bits, and accept them otherwise, which I think it shouldn't. The testcase added at that time only used 64 bits elements, and therefore didn't fully test the patch. The report I received is about vectorized accesses to an array of unsigned chars, whose start address is not aligned on a 128 bits boundary. The attached patch fixes the problem by making aarch64_builtin_support_vector_misalignment always return false when the misalignment is not known at compile time. I've also added a testcase, which tries to check if the array start address alignment is checked (using %16, and-ing with #15), so that loop peeling is performed *before* using vectorized accesses. Without the patch, vectorized accesses are used at the beginning of the array, and byte accesses are used for the remainder at the end, and there is not such 'and wX,wX,15'. BTW, I'm not sure about the same hook for arm... it seems to me it has a similar problem. OK? Thanks, Christophe 2017-07-18 Christophe Lyon PR target/71727 gcc/ * config/aarch64/aarch64.c (aarch64_builtin_support_vector_misalignment): Always return false when misalignment is unknown. gcc/testsuite/ * gcc.target/aarch64/pr71727-2.c: New test. Reviewed-by: James Greenhalgh diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 799989a..12a9fbe 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -11758,18 +11758,7 @@ aarch64_builtin_support_vector_misalignment (machine_mode mode, return false; if (misalignment == -1) - { - /* Misalignment factor is unknown at compile time but we know - it's word aligned. */ - if (aarch64_simd_vector_alignment_reachable (type, is_packed)) - { - int element_size = TREE_INT_CST_LOW (TYPE_SIZE (type)); - - if (element_size != 64) - return true; - } - return false; - } + return false; } return default_builtin_support_vector_misalignment (mode, type, misalignment, is_packed); diff --git a/gcc/testsuite/gcc.target/aarch64/pr71727-2.c b/gcc/testsuite/gcc.target/aarch64/pr71727-2.c new file mode 100644 index 0000000..8935a72 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/pr71727-2.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-mstrict-align -O3" } */ + +unsigned char foo(const unsigned char *buffer, unsigned int length) +{ + unsigned char sum; + unsigned int count; + + for (sum = 0, count = 0; count < length; count++) { + sum = (unsigned char) (sum + *(buffer + count)); + } + + return sum; +} + +/* { dg-final { scan-assembler-times "and\tw\[0-9\]+, w\[0-9\]+, 15" 1 } } */