From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id C2891396E400 for ; Thu, 1 Jul 2021 10:31:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C2891396E400 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 05D3022867 for ; Thu, 1 Jul 2021 10:31:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1625135476; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=Rp3H4CX27nRn4gNj+jO52hKXZSnTsV+ftRPaJgC46U0=; b=lR7z0AWy7LeecmtOCeqW2RgjCANYXW9u9AT8bnen3mdac3k/M/8QHWxZmgGNklruo3YHp+ y3+fxV1q2htHLTt5sRACdJ+dOZoDsf9rgORf9vDN2KcPuF+7AgOCEx/uxI4Q59SbeEsCeo G8IEJ4QZPvg9VQQqgwsl4DpimwVFQS0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1625135476; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=Rp3H4CX27nRn4gNj+jO52hKXZSnTsV+ftRPaJgC46U0=; b=TgHym2h9FEsx11H1hGIQqdPY6r3vRPhajmdsIS0zagZ/ln3jOLa97vMXKZ0spVn67o2PNR mjoJWn8Y5zlLcWCg== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id CF8CF11CC0 for ; Thu, 1 Jul 2021 10:31:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1625135475; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=Rp3H4CX27nRn4gNj+jO52hKXZSnTsV+ftRPaJgC46U0=; b=hg2aN/DhgkSPNwqVz7gEE981VjlmLxKVRw4MXdOvt8SXtp7iilwMl+8shKpB71EAJRU9g3 zSv72U1Oxn08dYOBMhHzIqeED56551oqH1mVc0hbC7xruRIXr865nxVYzLgtO5jhyNAzdI seI5kTQN0pJ1fB5XiGl0L8m2cTd9X3Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1625135475; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=Rp3H4CX27nRn4gNj+jO52hKXZSnTsV+ftRPaJgC46U0=; b=x2qfQ0Q5Z0MOIQ4drT1L/iu3nCsXHwwXwXk1oTvhnekeLfW7mAiiHdOkBT0EPdDoitZk62 dA89NTZfOVsqZpAQ== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id B5qNMHOZ3WDRWgAALh3uQQ (envelope-from ) for ; Thu, 01 Jul 2021 10:31:15 +0000 Date: Thu, 1 Jul 2021 12:31:15 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/100778 - fix placement of trapping vectorized ops Message-ID: <6n97rrso-7q82-s5n-71s1-os9n4q2or2so@fhfr.qr> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-10.8 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-List-Received-Date: Thu, 01 Jul 2021 10:31:18 -0000 This avoids placing possibly trapping vectorized operations where the corresponding scalar operation was possibly not executed. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed to trunk sofar. 2021-01-07 Richard Biener PR tree-optimization/100778 * tree-vect-slp.c (vect_schedule_slp_node): Do not place trapping vectorized ops ahead of their scalar BB. * gcc.dg/torture/pr100778.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr100778.c | 31 +++++++++++++++++++++++++ gcc/tree-vect-slp.c | 15 ++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/torture/pr100778.c diff --git a/gcc/testsuite/gcc.dg/torture/pr100778.c b/gcc/testsuite/gcc.dg/torture/pr100778.c new file mode 100644 index 00000000000..7997f2f2bcd --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr100778.c @@ -0,0 +1,31 @@ +/* { dg-do run { target *-*-*gnu* } } */ +/* { dg-additional-options "-fno-tree-sink -fno-math-errno -ftree-vectorize -D_GNU_SOURCE" } */ +/* { dg-require-effective-target fenv_exceptions } */ + +#include + +double a[2]; +void __attribute__((noipa)) foo () +{ + double x = a[0]; + double y = a[1]; + double norm = __builtin_sqrt (x*x + y*y); + if (norm > 1.) + { + x = x / norm; + y = y / norm; + } + a[0] = x; + a[1] = y; +} + +int main() +{ + feenableexcept (FE_INVALID); + a[0] = 0.; + a[1] = 0.; + foo (); + if (a[0] != 0. || a[1] != 0.) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c index 966b281ffae..f08797c2bc0 100644 --- a/gcc/tree-vect-slp.c +++ b/gcc/tree-vect-slp.c @@ -7100,6 +7100,21 @@ vect_schedule_slp_node (vec_info *vinfo, gcc_assert (seen_vector_def); si = gsi_after_labels (as_a (vinfo)->bbs[0]); } + else if (is_a (vinfo) + && gimple_bb (last_stmt) != gimple_bb (stmt_info->stmt) + && gimple_could_trap_p (stmt_info->stmt)) + { + /* We've constrained possibly trapping operations to all come + from the same basic-block, if vectorized defs would allow earlier + scheduling still force vectorized stmts to the original block. + This is only necessary for BB vectorization since for loop vect + all operations are in a single BB and scalar stmt based + placement doesn't play well with epilogue vectorization. */ + gcc_assert (dominated_by_p (CDI_DOMINATORS, + gimple_bb (stmt_info->stmt), + gimple_bb (last_stmt))); + si = gsi_after_labels (gimple_bb (stmt_info->stmt)); + } else if (is_a (last_stmt)) si = gsi_after_labels (gimple_bb (last_stmt)); else -- 2.26.2