From patchwork Wed Nov 20 15:28:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1198237 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514174-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Dw5nrSVO"; 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 47J66d2mX6z9sRd for ; Thu, 21 Nov 2019 02:28:57 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=FnaP6e1vh4jaCtVmpeAxzXcQLQw1L3hoyFk7seB3dhXZoztsxvlcH g92LeFjj9rTC4BLZQOQsivhZBX9fX12bXlSELDAH/biC8vMxhyoad8udhIwaXYPo GAarjZSR6CMRzCBGHZ6V++ugyql5sJ4SStsm3lq1ma+4w3t25r2u0c= 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:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=XryatYEAR8O3G9+31fxVtJd2LNA=; b=Dw5nrSVODiitb/zsCqdG czNupuL2x+YGAdXSU0svnDPPA2ZxvB34YHoWBcaMww5d107eCaGSf/qPe+g/4CBp 8QCFhq84ElEqOGv0lZtfTLiDSdQp4VesIkUu4EohuxJvKcr8M1pvN3ynKlySPJjb hed1hTERQEyLGHWugE29dSE= Received: (qmail 13760 invoked by alias); 20 Nov 2019 15:28:50 -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 13750 invoked by uid 89); 20 Nov 2019 15:28:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_PASS autolearn=ham version=3.3.1 spammy=HX-Languages-Length:2757 X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.110.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 20 Nov 2019 15:28:48 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 625E7328 for ; Wed, 20 Nov 2019 07:28:46 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0A47D3F703 for ; Wed, 20 Nov 2019 07:28:45 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Reject versioning for alignment with different masks (PR 92526) Date: Wed, 20 Nov 2019 15:28:44 +0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes Allowing mixed vector sizes broke the assumption in the following assert, since it's now possible for different accesses to require different levels of alignment: /* FORNOW: use the same mask to test all potentially unaligned references in the loop. The vectorizer currently supports a single vector size, see the reference to GET_MODE_NUNITS (TYPE_MODE (vectype)) where the vectorization factor is computed. */ gcc_assert (!LOOP_VINFO_PTR_MASK (loop_vinfo) || LOOP_VINFO_PTR_MASK (loop_vinfo) == mask); I guess we could try to over-align smaller accesses so that all of them are consistent, or try to support multiple alignment masks, but for now the easiest fix seems to be to turn the assert into a bail-out check. Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK to install? Richard 2019-11-20 Richard Sandiford gcc/ PR tree-optimization/92526 * tree-vect-data-refs.c (vect_enhance_data_refs_alignment): Reject versioning for alignment if the accesses do not have a consistent mask, rather than asserting that the masks are consistent. gcc/testsuite/ PR tree-optimization/92526 * gcc.target/aarch64/pr92526.c: New test. Index: gcc/tree-vect-data-refs.c =================================================================== --- gcc/tree-vect-data-refs.c 2019-11-16 11:40:19.105159717 +0000 +++ gcc/tree-vect-data-refs.c 2019-11-20 15:27:49.385346722 +0000 @@ -2266,13 +2266,15 @@ vect_enhance_data_refs_alignment (loop_v mask must be 15 = 0xf. */ mask = size - 1; - /* FORNOW: use the same mask to test all potentially unaligned - references in the loop. The vectorizer currently supports - a single vector size, see the reference to - GET_MODE_NUNITS (TYPE_MODE (vectype)) where the - vectorization factor is computed. */ - gcc_assert (!LOOP_VINFO_PTR_MASK (loop_vinfo) - || LOOP_VINFO_PTR_MASK (loop_vinfo) == mask); + /* FORNOW: use the same mask to test all potentially unaligned + references in the loop. */ + if (LOOP_VINFO_PTR_MASK (loop_vinfo) + && LOOP_VINFO_PTR_MASK (loop_vinfo) != mask) + { + do_versioning = false; + break; + } + LOOP_VINFO_PTR_MASK (loop_vinfo) = mask; LOOP_VINFO_MAY_MISALIGN_STMTS (loop_vinfo).safe_push (stmt_info); } Index: gcc/testsuite/gcc.target/aarch64/pr92526.c =================================================================== --- /dev/null 2019-09-17 11:41:18.176664108 +0100 +++ gcc/testsuite/gcc.target/aarch64/pr92526.c 2019-11-20 15:27:49.385346722 +0000 @@ -0,0 +1,9 @@ +/* { dg-options "-O3 -mstrict-align" } */ + +void +f (unsigned int *restrict x, unsigned int *restrict y, + unsigned char *restrict z, unsigned int n) +{ + for (unsigned int i = 0; i < n % 4; ++i) + x[i] = x[i] + y[i] + z[i]; +}