From patchwork Tue Jul 4 12:16:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 115741 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp1176331vqx; Tue, 4 Jul 2023 05:17:24 -0700 (PDT) X-Google-Smtp-Source: APBJJlG/gDNd//G8VmTPnPLsf9HoWfnrbfQ41luQAlE3rjav8JPeLGZq3bZ3Uq/wMiSBFtHFDW6q X-Received: by 2002:a05:6512:3150:b0:4fb:9105:58b0 with SMTP id s16-20020a056512315000b004fb910558b0mr8217132lfi.20.1688473043918; Tue, 04 Jul 2023 05:17:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688473043; cv=none; d=google.com; s=arc-20160816; b=PHDHG/23Jl6oiP4zMofWVPd+YVIQAfYE1WLcen9oqCe8iJQhgfbBSJetlOzwRbfoaQ WfcWnu7D4z+5d9ePQ5ha8YNd4eJXCfrFGYC5CxM/zbq+CaVCgcrVZArOFMnrkufaevw/ Wp3XwWbN/KktqH0XN2TRE9iMHjTuk0nmWn1v/NmdWrEmji2oP1kIoX7qiAbl5w3MfwYD kRVnlJl7oUAxKMcUwerLdyJbQMhwvOERApHVFLWqelckLujkHyutU+LwpLOuwWnCmHYx pqJIBavAZdbQ2cpFCkq+Ggfxq/bAJIblbk/Be2aRw7Am62X/MT1trh6boP1q7cRVwfbu aO6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:cc:to:date:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=RfbeLGrAv6+j67a0gJog1y0MTbF1vUw6mPkVF5Ym+cw=; fh=xhkLBVrfamW3D9oHP0ZGbkfs+/umOfyxpoLuXSj960g=; b=G+qmzUaYhgmteKUbTqdmfyfbvcgudxZhk2VWwIsnp3jxiM4sTQOjMkTIg/ZxeP9Ftu y/a84BFSbE28OHdTIUcDIL5xUlsy6MUS4Eg1DAFszL3fDE8nar2igsW4MO4TxPiHwc1Y /1tPReQyD+qGZZxYkxZLP26g+TLeGVd/6bQVn/IfNPeZZgdwVVedAubjvqcVJbpU5lg7 fP+JND0bxBRmwnT4LdpOMsmCvX7YbFwmSWrF2HQbs+8rmkI/cATryItFTIr6NBncZwDl M/I85q4oICQTiusTyb9KTL/P3hWLuOr96Bzfe9Eg2C6fViXAUPDloDabjbunmOZsD56d NQ5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=IBg+X9jF; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id i3-20020aa7c703000000b0051dd4e2847csi7164823edq.660.2023.07.04.05.17.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jul 2023 05:17:23 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=IBg+X9jF; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 BE6E73856DDC for ; Tue, 4 Jul 2023 12:17:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE6E73856DDC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688473034; bh=RfbeLGrAv6+j67a0gJog1y0MTbF1vUw6mPkVF5Ym+cw=; h=Date:To:cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=IBg+X9jFGZxk27RHhJzNaEnCwSQo0noj/NaiCnhY8FIGtrLtr6HEKjTl1ZoK+N6W6 wSGDKeQEheHl0loJX7iDy+BN/j+rbs5c+AUrfImFQbd86EzfalpoOzLy/1IwULyfe+ wqQ/bxrMhaO/ReL9ZdlVqUP1O7PP89KMFSAZr6DY= 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.220.28]) by sourceware.org (Postfix) with ESMTPS id 288503858D35 for ; Tue, 4 Jul 2023 12:16:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 288503858D35 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 5DB902284D; Tue, 4 Jul 2023 12:16:31 +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 4C7C62C141; Tue, 4 Jul 2023 12:16:31 +0000 (UTC) Date: Tue, 4 Jul 2023 12:16:31 +0000 (UTC) To: gcc-patches@gcc.gnu.org cc: pinskia@gmail.com Subject: [PATCH] tree-optimization/110491 - PHI-OPT and undefs User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 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.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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230704121714.BE6E73856DDC@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770492310396217908?= X-GMAIL-MSGID: =?utf-8?q?1770492310396217908?= The following makes sure to not make conditional undefs in PHI arguments unconditional by folding cond ? arg1 : arg2. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. This might become redundant with the pending fix to reset flow-sensitive info. Richard. PR tree-optimization/110491 * tree-ssa-phiopt.cc (match_simplify_replacement): Check whether the PHI args are possibly undefined before folding the COND_EXPR. * gcc.dg/torture/pr110491.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr110491.c | 29 +++++++++++++++++++++++++ gcc/tree-ssa-phiopt.cc | 7 ++++++ 2 files changed, 36 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/torture/pr110491.c diff --git a/gcc/testsuite/gcc.dg/torture/pr110491.c b/gcc/testsuite/gcc.dg/torture/pr110491.c new file mode 100644 index 00000000000..00b3bdfc122 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr110491.c @@ -0,0 +1,29 @@ +/* { dg-do run } */ + +int a, c, d, e; +short b; +void f(int *g) { c &= *g; } +void h(void); +void i() { + a = 1; + h(); + f(&a); +} +void h() { + int *j = &c; + *j = 5; +k: + for (; 4 + b <= 0;) + ; + for (; d;) { + c = e == 0; + goto k; + } +} +int main() +{ + i(); + if (c != 1) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index 31a7c39e405..467c9fd108a 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -785,6 +785,13 @@ match_simplify_replacement (basic_block cond_bb, basic_block middle_bb, arg_false = arg0; } + /* Do not make conditional undefs unconditional. */ + if ((TREE_CODE (arg_true) == SSA_NAME + && ssa_name_maybe_undef_p (arg_true)) + || (TREE_CODE (arg_false) == SSA_NAME + && ssa_name_maybe_undef_p (arg_false))) + return false; + tree type = TREE_TYPE (gimple_phi_result (phi)); result = gimple_simplify_phiopt (early_p, type, stmt, arg_true, arg_false,