From patchwork Fri Oct 21 16:42:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Andre Vieira (lists)" X-Patchwork-Id: 6863 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp797754wrr; Fri, 21 Oct 2022 09:43:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6GiG9krnByBXEBIKxisErv4yyk31P1R4clZtuW/c95GUJ9XrzPsxyfqNiPP38JhXCTz0lC X-Received: by 2002:a17:907:7e9a:b0:796:7a21:1520 with SMTP id qb26-20020a1709077e9a00b007967a211520mr10252039ejc.236.1666370619152; Fri, 21 Oct 2022 09:43:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666370619; cv=none; d=google.com; s=arc-20160816; b=XOJcrfiZRIk1j5OfR2gPv+ujYmqzQOACBFiJl8q5zMnGV76ociiORjKnM8ASIEM2OO La0+/uf+pdyq3zmrRKlOOQmIyXq8onEm/XK4RUKGA/uNa2BChXW7CR8vCUdX7gT7z+gj VcHWwSB1mjNtNp6213rv1ibe23V78hqEPueamLaObGmYT15DF4t0fkSe9XJYMyVBZm8C /mSITZ22/Esh5HMTA3yDOldE/Vwf5vOApp6Mz0xs/LWrDvUcmCnz4Cix/b8P5flkR/nH cyNYVtJOVUYWpJMSmNfd56v/gZBc+1YZ7J7RTCKlnHZPYDgFfDu3tHZUZudqV2iaAiqR yiSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :to:content-language:user-agent:mime-version:date:message-id :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Rb35w6DYelCYvmuVH9JtBEUzhZvRKrJGAFfKiMDB1jM=; b=rY0/6iQfP3/xo1r3NSv6NzjGFKACTLcQmlDwFBfyV+/GgwVl1KtHt3BRsxI3RnY90k dQbXGPjTq6KdQm6YdAoRTP3pn3sKy7ktrqEeu13zwxL2n96ShxCSDEKTRPm52FGf+NhG v8YAC5FW0tMl40kFDP/3aen/CIaeyWoCpPQSHxsm2gHiwLRauhXxLQ6S1dAtzEfimBqj W1zkqAUi7k8xpCCeVA9mIc1ZUUmm7pew7GxpxPgZzaUyaG/4/PS0m72Vekwjzc+vtl4h BPyggPI1RU5d5NTWRm/ZOZ32rhMdqb+Gzr4ouDKy0RfzOji+yiUMMNGLRbMkiWZ5JZjc EXLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Uj0eslNU; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id o14-20020a170906974e00b007919388d2c6si13139874ejy.357.2022.10.21.09.43.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 09:43:39 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Uj0eslNU; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 322173853562 for ; Fri, 21 Oct 2022 16:43:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 322173853562 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666370608; bh=Rb35w6DYelCYvmuVH9JtBEUzhZvRKrJGAFfKiMDB1jM=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Uj0eslNUINBJBsp2JxLT3XbSdPrpXbQSTWEbNdzY3iGaXckQKKuPErxgzXtWTQFja ge6XdEsShbf3HGsoiI2Jv5ijiFCctboc2oZ88gFS7emPw++ZTCZHrgatKepuK30/4t IPfV6+QyqK6oJArIh1rkh9+9Kr8O1f8RaJzTkx1E= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id A9D7D3856DC0; Fri, 21 Oct 2022 16:42:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A9D7D3856DC0 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 935F61063; Fri, 21 Oct 2022 09:42:44 -0700 (PDT) Received: from [10.57.6.65] (unknown [10.57.6.65]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A234D3F67D; Fri, 21 Oct 2022 09:42:37 -0700 (PDT) Message-ID: <129db1b0-0d2a-b768-bc80-9f73d665e8f8@arm.com> Date: Fri, 21 Oct 2022 17:42:31 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Content-Language: en-US To: "gcc-patches@gcc.gnu.org" Subject: vect: Make vect_check_gather_scatter reject offsets that aren't multiples of BITS_PER_UNIT [PR107346] X-Spam-Status: No, score=-18.4 required=5.0 tests=BAYES_00, BODY_8BITS, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "Andre Vieira \(lists\) via Gcc-patches" From: "Andre Vieira (lists)" Reply-To: "Andre Vieira \(lists\)" Cc: Richard Sandiford , Richard Biener , ebotcazou@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747316238185272890?= X-GMAIL-MSGID: =?utf-8?q?1747316238185272890?= Hi, The ada failure reported in the PR was being caused by vect_check_gather_scatter failing to deal with bit offsets that weren't multiples of BITS_PER_UNIT. This patch makes vect_check_gather_scatter reject memory accesses with such offsets. Bootstrapped and regression tested on aarch64 and x86_64. I wasn't sure whether I should add a new Ada test that shows the same failure without the bitfield lowering, I suspect this is such a rare form of data-structure that is why no other tests have highlighted the failure. Let me know if you would like me to add it still, the change is quite simple, just change the Int24 -> Int32 type in the structure. The 'thing' that causes the failure is the 4-bit member inside the packed structure before the field we access, giving it a 4-bit offset. I attempted but failed to create a C test using __attribute__((packed)). Kind Regards, Andre gcc/ChangeLog:         PR tree-optimization/107346         * tree-vect-data-refs.cc (vect_check_gather_scatter): Reject offsets that aren't         multiples of BITS_PER_UNIT. diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc index 4a23d6172aaa12ad7049dc626e5c4afbd5ca3f74..6c892791bd4c39f672add4e4c22a9d7835e292d6 100644 --- a/gcc/tree-vect-data-refs.cc +++ b/gcc/tree-vect-data-refs.cc @@ -4016,6 +4016,11 @@ vect_check_gather_scatter (stmt_vec_info stmt_info, loop_vec_info loop_vinfo, if (reversep) return false; + /* PR 107346. Packed structs can have fields at offsets that are not + multiples of BITS_PER_UNIT. Do not use gather/scatters in such cases. */ + if (!multiple_p (pbitpos, BITS_PER_UNIT)) + return false; + poly_int64 pbytepos = exact_div (pbitpos, BITS_PER_UNIT); if (TREE_CODE (base) == MEM_REF)