From patchwork Wed Aug 24 08:24:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 696 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp1313091wro; Wed, 24 Aug 2022 01:25:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR4gUotcNcj3rIKKr1iy/6rzhTXgOMfcHmnwPcDzdiodo9+is1d7QeKnMQqbNo2DIrDz+pCI X-Received: by 2002:a17:907:a218:b0:731:5e2c:c28a with SMTP id qp24-20020a170907a21800b007315e2cc28amr2176074ejc.472.1661329533059; Wed, 24 Aug 2022 01:25:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661329533; cv=none; d=google.com; s=arc-20160816; b=1B43UIkY0rf6KYLr09AeVp578dXTA/hmudc5TpMU6VewSZPVYVYp+xWZZVqlolfvX9 aumVyUbNQEvZBHqBaRpdHU7XSUsW4XGv3voykfpucWgLqF636PhWC599yvXtWKatq0Nj HI/uDlkvBe7W6DMfUVt34+DbVH2v3ZY7g/u1i6GQsdWwWmJvreEO742h1oWEdAlgKj0F NdQLBfW7B8TcppaPf218lOmQjv4dyLm9tlmbAUsRPteZLq7IWm18SH+nzwTDknahpzn/ 96gG2gltSwHwEoy1sTHVkGS0OBnDg6BJcLYaSmUeq9FaVes6E8JYS7YpKqAuOa7y+2Tj gTKg== 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:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=WuyUjhZomPyYXAloujF32PdiDZvtUhr4Zto01pvBma4=; b=bckWVbw6bICB6bvA0neDvsriHbAEi6eenARnrwOmTXPuhPc4NpNEGfxB2E7dN3Xs/w 5YR5cU5MvFH8yab/cBXUuFJ+O/zuWe5+3ZTB9B0Obiek5bWR/TC4H0vvaD2RfZN9K4g7 gTiluSne69W9BUF29ulxKNdBjqn9yYX1NIZhOt4AAawbL91DvhdTEOV2GBJBDcLfuLFU zmfWw5TBikXC4eSn5/NWKeNJQd01YbFlDOlfV67aJIHcFkHNrmb2DqJOiJMZsdSlPAfD J9VsEzi0uDIcaPtg/Szhk/HxucdKhcUFPxG55sn8ujAwS1LTUXi9AGCfeK5yCM8PuSAU 1f3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=voUZeBAN; 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 sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id x100-20020a50baed000000b00446cfe99cb8si3318131ede.305.2022.08.24.01.25.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 01:25:33 -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=voUZeBAN; 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 C3507385AC19 for ; Wed, 24 Aug 2022 08:25:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C3507385AC19 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661329531; bh=WuyUjhZomPyYXAloujF32PdiDZvtUhr4Zto01pvBma4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=voUZeBAN9NQ7TjP88Sw7/fOqJo+oOuJNYHS+6oiRAOohYuBILISSpbktJSmakNLKM t4AHL/Y7m846Iz/sEHLFks6wH92FG3VFR/6ooLKxLc4mLj9jGuxw20jlQFJs84T8Qe NqNuaPXYeBBkXCnmt4Z65+EfLxtYRBSstjUrpZM0= 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 A82B238582BE for ; Wed, 24 Aug 2022 08:24:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A82B238582BE 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-92-5_eV7NnkPNWEWHy2YRHi0Q-1; Wed, 24 Aug 2022 04:24:43 -0400 X-MC-Unique: 5_eV7NnkPNWEWHy2YRHi0Q-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7C2E585A589; Wed, 24 Aug 2022 08:24:43 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 387FC4010D2A; Wed, 24 Aug 2022 08:24:43 +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 27O8OejQ2513467 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 24 Aug 2022 10:24:41 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 27O8Odop2513466; Wed, 24 Aug 2022 10:24:39 +0200 Date: Wed, 24 Aug 2022 10:24:39 +0200 To: Richard Biener Subject: [PATCH] internal-fn, tree-cfg: Fix .TRAP handling and another __builtin_trap vops issue [PR106099] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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?1742030276385361927?= X-GMAIL-MSGID: =?utf-8?q?1742030276385361927?= Hi! This patch fixes 2 __builtin_unreachable/__builtin_trap related issues. One (first hunk) is that CDDCE happily removes calls to .TRAP () internal-fn as useless. The problem is that the internal-fn is ECF_CONST | ECF_NORETURN, doesn't have lhs and so DCE thinks it doesn't have side-effects and removes it. __builtin_unreachable which has the same ECF_* flags works fine, as since PR44485 we implicitly add ECF_LOOPING_CONST_OR_PURE to ECF_CONST | ECF_NORETURN builtins, but do it in flags_from_decl_or_type which isn't called for internal-fns. As IFN_TRAP is the only ifn with such flags, it seems easier to add it explicitly. The other issue (which on the testcase can be seen only with the first bug unfixed) is that execute_fixup_cfg can add a __builtin_trap which needs vops, but nothing adds it and it can appear in many passes which don't have corresponding TODO_update_ssa_only_virtuals etc. Fixed similarly as last time but emitting ifn there instead. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-08-24 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-23 12:36:03.818856327 +0200 @@ -9879,10 +9879,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); + if (DECL_FUNCTION_CODE (fndecl) != BUILT_IN_TRAP) + stmt = gimple_build_call (fndecl, 0); + else + /* Instead of __builtin_trap use .TRAP, so that it doesn't + need vops. */ + stmt = gimple_build_call_internal (IFN_TRAP, 0); gimple_stmt_iterator gsi = gsi_last_bb (bb); gsi_insert_after (&gsi, stmt, GSI_NEW_STMT); - if (!cfun->after_inlining) + if (!cfun->after_inlining + && DECL_FUNCTION_CODE (fndecl) != BUILT_IN_TRAP) { gcall *call_stmt = dyn_cast (stmt); node->create_edge (cgraph_node::get_create (fndecl), --- 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); +}