From patchwork Mon May 27 10:45:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1939840 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=AdgEzHJx; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=eL9ye+xU; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=AdgEzHJx; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=eL9ye+xU; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VnskJ41Dtz20KL for ; Mon, 27 May 2024 20:45:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9EB313858CDA for ; Mon, 27 May 2024 10:45:40 +0000 (GMT) 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 [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 016A23858D34 for ; Mon, 27 May 2024 10:45:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 016A23858D34 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 016A23858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716806724; cv=none; b=Z8emH8CyNUwH2RYEiHntJvLNSHaaQagvcjlTUyy3tHnyCRqOfXcfwdiCD45B3xUE+zah/J6cJyKxNtgaL5WCyUBqMJGuGdoagwkHtdlnjI0PaFp1IwM+hz/P4UZu1WmNMcV2ym7lXbaBDU4wS4GKpBVfIba2rnyD/M2L8ip4TX8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716806724; c=relaxed/simple; bh=JpE3VrqUwdNrW5Cdh0KfsFFm5cS/28GgnT3NMCywC0M=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=gX+/q+x+AtA/COlMLZbXc5btttnTL2JjBibc8YiW/LqRtZFu4pjZ/nucLBopSIRuw9R0+PoHaUQrk7JrCkY7R/wsmpxHkrjkn1mC/5Ul4d1tbB2SLb0UFGXerfSqAMcT528xZ//oyXATTkclWdD6Rft64/fJ336dI4huuVIuedE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from murzim.nue2.suse.org (unknown [10.168.4.243]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id CAACB21DDC for ; Mon, 27 May 2024 10:45:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1716806720; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=T0L6xPkr7SmWM+icIKLAo40xD0FtKNTIeEA2AKYG4eE=; b=AdgEzHJxMtv9SVItt2LC+7mnOzIpotHf+BPPCvHrgwO8LhamrgowgpM7g9amuSYmu3E0HZ 9BoZF62V9QvpAxZ+qfuFsr+tAaCU2gsxsgWrMvoRYIBzfUQVV5GZZAItUDgMcoi2+tmfQY zs8bnVYAVURnF02CPqS9q7/meL9KltQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1716806720; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=T0L6xPkr7SmWM+icIKLAo40xD0FtKNTIeEA2AKYG4eE=; b=eL9ye+xUkTjty3iO8jqNYmfrC30F3l3WCZ4r2zrK3QIlaCQZ/+gGfchsSi/TGJDfvhmJUi 766hiE+rshSK4XBg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1716806720; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=T0L6xPkr7SmWM+icIKLAo40xD0FtKNTIeEA2AKYG4eE=; b=AdgEzHJxMtv9SVItt2LC+7mnOzIpotHf+BPPCvHrgwO8LhamrgowgpM7g9amuSYmu3E0HZ 9BoZF62V9QvpAxZ+qfuFsr+tAaCU2gsxsgWrMvoRYIBzfUQVV5GZZAItUDgMcoi2+tmfQY zs8bnVYAVURnF02CPqS9q7/meL9KltQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1716806720; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=T0L6xPkr7SmWM+icIKLAo40xD0FtKNTIeEA2AKYG4eE=; b=eL9ye+xUkTjty3iO8jqNYmfrC30F3l3WCZ4r2zrK3QIlaCQZ/+gGfchsSi/TGJDfvhmJUi 766hiE+rshSK4XBg== Date: Mon, 27 May 2024 12:45:20 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/115220 - fix store sinking virtual operand constraints MIME-Version: 1.0 X-Spam-Score: -1.78 X-Spam-Level: X-Spamd-Result: default: False [-1.78 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MISSING_MID(2.50)[]; NEURAL_HAM_LONG(-0.98)[-0.983]; NEURAL_HAM_SHORT(-0.19)[-0.974]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_ONE(0.00)[1]; RCVD_COUNT_ZERO(0.00)[0]; ARC_NA(0.00)[]; MISSING_XM_UA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_NONE(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[] X-Spam-Status: No, score=-10.5 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, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Message-Id: <20240527104540.9EB313858CDA@sourceware.org> The following makes sure the virtual operand updating when sinking stores works for the case we ignore paths to kills. The final sink location might not post-dominate the original stmt location which would require inserting of a virtual PHI which we do not support. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/115220 PR tree-optimization/115226 * tree-ssa-sink.cc (statement_sink_location): When ignoring paths to kills when sinking stores make sure the final sink location is still post-dominated by the original one. Otherwise we'd need to insert a PHI node to merge virtual operands. * gcc.dg/torture/pr115220.c: New testcase. * gcc.dg/torture/pr115226.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr115220.c | 14 ++++++++++++++ gcc/testsuite/gcc.dg/torture/pr115226.c | 15 +++++++++++++++ gcc/tree-ssa-sink.cc | 12 +++++++++--- 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr115220.c create mode 100644 gcc/testsuite/gcc.dg/torture/pr115226.c diff --git a/gcc/testsuite/gcc.dg/torture/pr115220.c b/gcc/testsuite/gcc.dg/torture/pr115220.c new file mode 100644 index 00000000000..e7b5da6ba42 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr115220.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-additional-options "--param logical-op-non-short-circuit=0" } */ + +extern char **environ; +static char ***p_environ = &environ; +int +_setenv_r (const char *name, const char *value) +{ + register char *C; + int offset; + for (C = (*p_environ)[offset]; (*C = *name++) && *C != '='; ++C); + for (*C++ = '='; (*C++ = *value++) != 0;); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr115226.c b/gcc/testsuite/gcc.dg/torture/pr115226.c new file mode 100644 index 00000000000..9a0bc7c9b6a --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr115226.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ + +extern void c(); +int a, b; +int main() { + while (b) { + int d, e = 0, *f = &a; + *f = 1; + e = 1 >> d ? : 1 << d; + if (e) + a = 0; + c(); + } + return 0; +} diff --git a/gcc/tree-ssa-sink.cc b/gcc/tree-ssa-sink.cc index b0fe871cf1e..8c551e42a4d 100644 --- a/gcc/tree-ssa-sink.cc +++ b/gcc/tree-ssa-sink.cc @@ -467,11 +467,17 @@ statement_sink_location (gimple *stmt, basic_block frombb, if (!sinkbb) return false; - sinkbb = select_best_block (frombb, sinkbb, stmt); - if (sinkbb == frombb) + basic_block bestbb = select_best_block (frombb, sinkbb, stmt); + if (bestbb == frombb + /* When we sink a store make sure there's not a path to any of + the possibly skipped killing defs as that wrecks the virtual + operand update, requiring inserting of a PHI node. */ + || (gimple_vdef (stmt) + && bestbb != sinkbb + && !dominated_by_p (CDI_POST_DOMINATORS, bestbb, sinkbb))) return false; - *togsi = gsi_after_labels (sinkbb); + *togsi = gsi_after_labels (bestbb); return true; }