From patchwork Thu Aug 25 07:48:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 747 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp124468wro; Thu, 25 Aug 2022 00:49:42 -0700 (PDT) X-Google-Smtp-Source: AA6agR5QdfNzkylO5tHQaQziPsHt6zpEh8IZZrNeva1ONJd/R2K4prHs/3UgU/1l7TzWJbtMm2iM X-Received: by 2002:a17:907:970b:b0:73d:5a29:959 with SMTP id jg11-20020a170907970b00b0073d5a290959mr1712633ejc.183.1661413782674; Thu, 25 Aug 2022 00:49:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661413782; cv=none; d=google.com; s=arc-20160816; b=T3zfe4QVuRprSa6U7Ui/VJ5b2dd0y6IqWRw6bH1tVTqvtFJWi3Soj32ctSUhMjrJwJ 8Z52MS7ezcGi4f7v5JxXXunqIg+nXDan7RXu1r5hVCzfvGbsfPSOhwxvfLMigsy53l2g WzlZBPwJhcNzhoMz/LN07H8gxp7hUqxrslTIXDza5XKqelCt1GgHYsfl6VMckNI2KurX fYMpl103BVfgCvEFzuH0QAa8GahBDabmsBgYGf69X5cMp2MdqeS9f0/KbB1TxmuwltXB DpM8N0aPuk5UZhOEBW81BB1vpnVEfSR/F+amZ8SJXlSz92K1sTTH7Lpp+DLy/EBtREbr d3pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:in-reply-to:mime-version:references:message-id :subject:to:date:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=svegAD4+M9ibcD3sqkUkLQCce9EH/oYrTMpmnGhHfu8=; b=eAH+/LkD9BhHWFJ0w1Z60AJhiks3wAsI+X4OjRF/wFlsgp5o+w057xt93bXOKtq6pM lkMdK5BA1IN14XF6IVJfUU8b3hfHxwc1gRlidFv8zwdi5xhW3mCn6aAfKIxMbZA1d1t9 d63hcxstlJc2kiBFZR475D49O2cZKbA1OeNdKCqmLADBNuwfCB4MRe45DakZGGaGn4Vw zy4Y6BObXg/gOuIozociynTJfXrU/zVMsHfhuE3GJbii+705kuldjBuzNhc9YQmwFYD7 zPWT0KG3IfzA009kWFlnrX14ncdeH+kudA99gGYqJYv1JTFUrsJ9BeQMR0onCnP7t+Sd 5rnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=sAs3krxd; 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 ji15-20020a170907980f00b007387740b9c5si3601627ejc.22.2022.08.25.00.49.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 00:49:42 -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=sAs3krxd; 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 2DE28385085C for ; Thu, 25 Aug 2022 07:49:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2DE28385085C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661413749; bh=svegAD4+M9ibcD3sqkUkLQCce9EH/oYrTMpmnGhHfu8=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=sAs3krxdi1uLXOYYV6m09dkd1hZPE9mraFYSJl4w+ILZch0WVNjjzNiVRCF1PrfEA +xR05ruAWis2KTxO8RjXIU0mNJFTS1LCC/9eeS6Xkkqe5I9WrPeYn9PRNwKiZmW4Om 70J13ZA/g3US9RfWtjC0rUyPNoSCB85mwsByLSDw= 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 E27A0385357A for ; Thu, 25 Aug 2022 07:48:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E27A0385357A 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-292-UWPX3_kAOOWxJ1IqU_MTIg-1; Thu, 25 Aug 2022 03:48:18 -0400 X-MC-Unique: UWPX3_kAOOWxJ1IqU_MTIg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 10B1F805AF5; Thu, 25 Aug 2022 07:48:18 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C4673492CA5; Thu, 25 Aug 2022 07:48:17 +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 27P7mExQ2541580 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 25 Aug 2022 09:48:15 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 27P7mEHD2541579; Thu, 25 Aug 2022 09:48:14 +0200 Date: Thu, 25 Aug 2022 09:48:13 +0200 To: Richard Biener Subject: [PATCH] internal-fn, tree-cfg, v2: Fix .TRAP handling and another __builtin_trap vops issue [PR106099] Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org 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?1742118618500893444?= X-GMAIL-MSGID: =?utf-8?q?1742118618500893444?= On Wed, Aug 24, 2022 at 10:20:45AM +0000, Richard Biener wrote: > So > > combined_fn cfn = builtin_cfn_unreachable (); > gimple_build (&gsi, false, GSI_NEW_STMT, cfn, void_type_node); > > ? So what about just using existing call that creates the GIMPLE call, whether it is builtin call or internal call? I didn't use that initially because the code then wants to add a cgraph edge for the fndecl, but in fact it is quite easy to gimple_call_fndecl afterwards: 2022-08-25 Jakub Jelinek PR tree-optimization/106099 * internal-fn.def (TRAP): Add ECF_LOOPING_CONST_OR_PURE flag. * tree-cfg.cc (execute_fixup_cfg): Add IFN_TRAP instead of __builtin_trap to avoid the need of vops. * gcc.dg/pr106099.c: New test. Jakub --- gcc/internal-fn.def.jj 2022-07-28 12:43:12.876295553 +0200 +++ gcc/internal-fn.def 2022-08-23 14:21:49.559364691 +0200 @@ -458,7 +458,8 @@ DEF_INTERNAL_FN (SPACESHIP, ECF_CONST | /* __builtin_trap created from/for __builtin_unreachable. */ DEF_INTERNAL_FN (TRAP, ECF_CONST | ECF_LEAF | ECF_NORETURN - | ECF_NOTHROW | ECF_COLD, NULL) + | ECF_NOTHROW | ECF_COLD | ECF_LOOPING_CONST_OR_PURE, + NULL) #undef DEF_INTERNAL_INT_FN #undef DEF_INTERNAL_FLT_FN --- gcc/tree-cfg.cc.jj 2022-07-26 10:32:23.998267698 +0200 +++ gcc/tree-cfg.cc 2022-08-25 09:42:19.013039869 +0200 @@ -9878,16 +9878,16 @@ execute_fixup_cfg (void) { if (stmt && is_gimple_call (stmt)) gimple_call_set_ctrl_altering (stmt, false); - tree fndecl = builtin_decl_unreachable (); - stmt = gimple_build_call (fndecl, 0); + stmt = gimple_build_builtin_unreachable (UNKNOWN_LOCATION); gimple_stmt_iterator gsi = gsi_last_bb (bb); gsi_insert_after (&gsi, stmt, GSI_NEW_STMT); if (!cfun->after_inlining) - { - gcall *call_stmt = dyn_cast (stmt); - node->create_edge (cgraph_node::get_create (fndecl), - call_stmt, bb->count); - } + if (tree fndecl = gimple_call_fndecl (stmt)) + { + gcall *call_stmt = dyn_cast (stmt); + node->create_edge (cgraph_node::get_create (fndecl), + call_stmt, bb->count); + } } } } --- gcc/testsuite/gcc.dg/pr106099.c.jj 2022-08-23 14:30:51.992057144 +0200 +++ gcc/testsuite/gcc.dg/pr106099.c 2022-08-23 14:29:04.271508337 +0200 @@ -0,0 +1,10 @@ +/* PR tree-optimization/106099 */ +/* { dg-do compile } */ +/* { dg-options "-O -fharden-compares -fno-tree-forwprop -fno-tree-ch -fno-tree-dominator-opts -fno-tree-ccp -funreachable-traps --param=scev-max-expr-size=1" } */ + +void +foo (void) +{ + for (unsigned i = 0; i == 0; i++) + __builtin_printf ("%d", i); +}