From patchwork Wed Apr 12 10:23:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1768018 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=CYcVYdEY; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PxJhc0gTlz1yZk for ; Wed, 12 Apr 2023 20:23:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E1D113858C53 for ; Wed, 12 Apr 2023 10:23:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E1D113858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681295020; bh=HGDyFHZO+I6oilh0pND3hJPUqcZSQIfrMEWsuCuBEAc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=CYcVYdEYfmrw7L3rgWC4Sa4xm7hn/f8J0XvNXX444mwrpruMqQeTQJwOs5JgF8F1J k6C8VF/ykAoqpUYpSSTdmBFqxalPwOd/FR2n8tU7uFPSbYlOA28g0mN80Cqm61VFfN SS9tnZiyZgAkur3JMuEs0eJadSaNKujl3nIcgMGM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 7359F3858D32 for ; Wed, 12 Apr 2023 10:23:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7359F3858D32 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 99E022193C for ; Wed, 12 Apr 2023 10:23:20 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 8F89B2C143 for ; Wed, 12 Apr 2023 10:23:20 +0000 (UTC) Date: Wed, 12 Apr 2023 10:23:20 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/109473 - ICE with reduction epilog adjustment op User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230412102340.E1D113858C53@sourceware.org> The following makes sure to carry out the reduction epilog adjustment in the original computation type which for pointers is an unsigned integer type. There's a similar issue with signed vs. unsigned ops and overflow which is fixed by this as well. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/109473 * tree-vect-loop.cc (vect_create_epilog_for_reduction): Convert scalar result to the computation type before performing the reduction adjustment. * gcc.dg/vect/pr109473.c: New testcase. --- gcc/testsuite/gcc.dg/vect/pr109473.c | 16 ++++++++++++++++ gcc/tree-vect-loop.cc | 7 +++++-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vect/pr109473.c diff --git a/gcc/testsuite/gcc.dg/vect/pr109473.c b/gcc/testsuite/gcc.dg/vect/pr109473.c new file mode 100644 index 00000000000..9dee5515dc6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr109473.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-O" } */ + +struct spa_buffer { + __UINT32_TYPE__ *metas; +}; +void do_port_use_buffers(struct spa_buffer **buffers, void *endptr, void *mem) +{ + for (int i = 0; i < 128; i++) + { + for (int j = 0; j < 128; j++) + endptr = (void *)((__UINTPTR_TYPE__)endptr + buffers[i]->metas[j]); + if (endptr > mem) + return; + } +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 1ba9f18d73e..ba28214f09a 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -6297,9 +6297,12 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo, { new_temp = scalar_results[0]; gcc_assert (TREE_CODE (TREE_TYPE (adjustment_def)) != VECTOR_TYPE); - adjustment_def = gimple_convert (&stmts, scalar_type, adjustment_def); - new_temp = gimple_build (&stmts, code, scalar_type, + adjustment_def = gimple_convert (&stmts, TREE_TYPE (vectype), + adjustment_def); + new_temp = gimple_convert (&stmts, TREE_TYPE (vectype), new_temp); + new_temp = gimple_build (&stmts, code, TREE_TYPE (vectype), new_temp, adjustment_def); + new_temp = gimple_convert (&stmts, scalar_type, new_temp); } epilog_stmt = gimple_seq_last_stmt (stmts);