From patchwork Mon Nov 15 12:07:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 47667 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D08433858416 for ; Mon, 15 Nov 2021 12:08:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D08433858416 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636978121; bh=e2RVb9fnewyi9bE9QdUFLOkoMMJsFp+waVe85w81OGA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=AXpr7EHD3kefN2sOfISroZx2pLm7cAwRUWGDqNqabK+ScQM5XrQBjywOijzGtL93H A6Aq0rNyb7ULGtwFaQ/olfnD3jRV1DRiWJtvlQ+tmP7kaEXG1+IBE2E2WpfUZrpuW6 ev44em5UIZDeCMVfVwWwxn02IeeKw+13rOrPy1cE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 40BAB3857C72 for ; Mon, 15 Nov 2021 12:07:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 40BAB3857C72 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 48AB41FD6E for ; Mon, 15 Nov 2021 12:07:47 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 34E2213BDF for ; Mon, 15 Nov 2021 12:07:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ZbusC5NNkmEoWgAAMHmgww (envelope-from ) for ; Mon, 15 Nov 2021 12:07:47 +0000 Date: Mon, 15 Nov 2021 13:07:46 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/103237 - avoid vectorizing unhandled double reductions Message-ID: <5p3op5p6-60p2-q86s-np9q-8rr629q8oqo@fhfr.qr> MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Double reductions which have multiple LC PHIs in the inner loop are not handled correctly during transformation since those PHIs are not properly classified as reduction. The following disables vectorizing them. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. 2021-11-15 Richard Biener PR tree-optimization/103237 * tree-vect-loop.c (vect_is_simple_reduction): Fail for double reductions with multiple inner loop LC PHI nodes. * gcc.dg/torture/pr103237.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr103237.c | 24 ++++++++++++++++++++++++ gcc/tree-vect-loop.c | 11 +++++++++++ 2 files changed, 35 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/torture/pr103237.c diff --git a/gcc/testsuite/gcc.dg/torture/pr103237.c b/gcc/testsuite/gcc.dg/torture/pr103237.c new file mode 100644 index 00000000000..f2399f9586e --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr103237.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-additional-options "-ftree-vectorize" } */ + +int g1; +unsigned int g2 = -1U; +static void __attribute__((noipa)) +func_1() +{ + int *l_1 = &g1; + for (int g3a = 0; g3a != 4; g3a++) + for (int l_2 = 0; l_2 <= 3; l_2++) + { + unsigned int *l_3 = &g2; + *l_1 = *l_3 ^= 1; + } +} +int +main() +{ + func_1(); + if (g1 != -1) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index 1cd5dbcb6f7..73efdb96bad 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -3567,6 +3567,17 @@ vect_is_simple_reduction (loop_vec_info loop_info, stmt_vec_info phi_info, return def_stmt_info; } + /* When the inner loop of a double reduction ends up with more than + one loop-closed PHI we have failed to classify alternate such + PHIs as double reduction, leading to wrong code. See PR103237. */ + if (inner_loop_of_double_reduc && lcphis.length () != 1) + { + if (dump_enabled_p ()) + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "unhandle double reduction\n"); + return NULL; + } + /* If this isn't a nested cycle or if the nested cycle reduction value is used ouside of the inner loop we cannot handle uses of the reduction value. */