From patchwork Wed Apr 12 14:36:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 82513 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp374669vqo; Wed, 12 Apr 2023 07:37:41 -0700 (PDT) X-Google-Smtp-Source: AKy350Z/KxsFH2j6bcaXjKfyvpZ9OHty5+26LaLOjmmlUNCdlrxk3+GnCPYOg/TcU3WAuHS+6IK8 X-Received: by 2002:a17:907:849:b0:8b1:2eef:154c with SMTP id ww9-20020a170907084900b008b12eef154cmr3200729ejb.0.1681310261292; Wed, 12 Apr 2023 07:37:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681310261; cv=none; d=google.com; s=arc-20160816; b=ARyuv6ihjQA3ol+Du0JD75JszVWwcjbqnnGgIYQdNHvz4mehoup97IF3iUybtucZKV /B5CVOuBV9P3ETosRDzBWK4KmI1zw3YZE5Z+6FRcYyb68MeraNOkNIXs0I6gI3RpsBuJ nNh866xN2OB29n7zE1pjkCWDWwDR7yD1h6PW5yuZff96pkU3qvDahkDBVymAv0ia0+f3 gGY6j7wYXbMbNBrxjYxciSMP5lwOsGxUgeg4nvqFIM9P00CrFkzVEPNw6fis3nwFmzWX EkOHUvMC6RohJuO37CrJ1WDtHQlgi9Nx2wOtCmDmwRIovqwMgQVfjpXiYAAKTJPDOnr8 qxqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=MdJmBxQ4ZZEdoceQU1SDPu9TWJZt+T5Y/gx8BDzCYW4=; b=sBnHlxroUCtgXHvdXmDaLk6BdZfqMMijK+pb9Hu+p3/34+ru11pZoSJqVikw/1P4Vq B7zhffqvSJGWSpSe1fJ7dU/rU+j4lVgPk5zRQWirYuNunqt2rBJ1CQnP/+YCJIq5p6To MjpfK9Wyea856k1vWmTuBK/nWn3nrL0V23z6vWmgXm5AbwchGSWXtEs/AYYmBkKKYZK6 CgLSAbpcTbcEPer7PE5a9ohnvo1L7iykNW+ovl1CowwmX2xAg2mh/aqk+H7NFiXYHfHH PhrN1Vgi7/ELEcgEK1XwZ6DrUZgEzrYMHptwlfg7ZWRE972nuI19XMm+jw2J4AxyrhNN 8vyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=y3Hw8xIn; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id js5-20020a17090797c500b00947b33a9657si1903849ejc.629.2023.04.12.07.37.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 07:37:41 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=y3Hw8xIn; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 268883858439 for ; Wed, 12 Apr 2023 14:37:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 268883858439 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681310251; bh=MdJmBxQ4ZZEdoceQU1SDPu9TWJZt+T5Y/gx8BDzCYW4=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=y3Hw8xInBKe19WhV8BDA7ouT/qMuacmsXCDycpL1DkGPdNhuHzrkKx/1D/wr1W1J9 Z+OfVIX+giVuUVNfwitf69q4mcZZN8v7oVCMSOq3iRUwlGg+sNoIKEYTrWVuPeD4ID Glc9FOYFNeMMCBaxEYQApjlBbpRKHWiuUoxCwtmE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 628643858417 for ; Wed, 12 Apr 2023 14:36:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 628643858417 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-302-AI_NXf-iPhuZtJABWRnpKQ-1; Wed, 12 Apr 2023 10:36:46 -0400 X-MC-Unique: AI_NXf-iPhuZtJABWRnpKQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A17BA884EC6; Wed, 12 Apr 2023 14:36:46 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6545540CF8F1; Wed, 12 Apr 2023 14:36:46 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 33CEahjq3886937 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 12 Apr 2023 16:36:44 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 33CEagSh3886936; Wed, 12 Apr 2023 16:36:42 +0200 Date: Wed, 12 Apr 2023 16:36:42 +0200 To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] reassoc: Fix up another ICE with returns_twice call [PR109410] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762981588500845596?= X-GMAIL-MSGID: =?utf-8?q?1762981588500845596?= Hi! The following testcase ICEs in reassoc, unlike the last case I've fixed there here SSA_NAME_USED_IN_ABNORMAL_PHI is not the case anywhere. build_and_add_sum places new statements after the later appearing definition of an operand but if both operands are default defs or constants, we place statement at the start of the function. If the very first statement of a function is a call to returns_twice function, this doesn't work though, because that call has to be the first thing in its basic block, so the following patch splits the entry successor edge such that the new statements are added into a different block from the returns_twice call. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? I think we should in stage1 reconsider such placements, I think it unnecessarily enlarges the lifetime of the new lhs if its operand(s) are used more than once in the function. Unless something sinks those again. Would be nice to place it closer to the actual uses (or where they will be placed). 2023-04-12 Jakub Jelinek PR tree-optimization/109410 * tree-ssa-reassoc.cc (build_and_add_sum): Split edge from entry block if first statement of the function is a call to returns_twice function. * gcc.dg/pr109410.c: New test. Jakub --- gcc/tree-ssa-reassoc.cc.jj 2023-02-18 12:40:42.739131728 +0100 +++ gcc/tree-ssa-reassoc.cc 2023-04-12 13:23:49.083979843 +0200 @@ -1564,6 +1564,15 @@ build_and_add_sum (tree type, tree op1, && (!op2def || gimple_nop_p (op2def))) { gsi = gsi_after_labels (single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun))); + if (!gsi_end_p (gsi) + && is_gimple_call (gsi_stmt (gsi)) + && (gimple_call_flags (gsi_stmt (gsi)) & ECF_RETURNS_TWICE)) + { + /* Don't add statements before a returns_twice call at the start + of a function. */ + split_edge (single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun))); + gsi = gsi_after_labels (single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun))); + } if (gsi_end_p (gsi)) { gimple_stmt_iterator gsi2 --- gcc/testsuite/gcc.dg/pr109410.c.jj 2023-04-12 13:42:41.759751843 +0200 +++ gcc/testsuite/gcc.dg/pr109410.c 2023-04-12 13:42:27.249959585 +0200 @@ -0,0 +1,19 @@ +/* PR tree-optimization/109410 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +__attribute__((returns_twice)) int baz (int, int); + +int +bar (int x) +{ + return x; +} + +int +foo (int x, int y) +{ + baz (x, y); + int a = bar (x); + return y || a == 42 || a > 42; +}