From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id EB5113858D37 for ; Fri, 23 Jun 2023 11:11:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EB5113858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2b475b54253so8642861fa.2 for ; Fri, 23 Jun 2023 04:11:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687518673; x=1690110673; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=+hLFPZDPZ0gI0XtOFDQEPz3lIWaqgO4rr6Z2KJLelIY=; b=JJ7PZXpCYhZt5fvSsjyWVdnB3Z3P9HcZmG6gm2kO8gdYCjOkRLMl3l+VrTUBfuQWJK TwWuDVTibl1FFARadiBdLblqz9kNaIDGTXiPsFS5nOMcklxkFsOHGRtMnu9lDrzlgxxw j4fhxPGrtegaIFcueonLY57lvoT6WdBnj2Q4aPdrq1yV/ZtXISvYieotSAa903t2DfEp bOgMTynIR2/YsvyJTcuBOy5lggvrDhRRDlfWWUq7wa0YvBybsrcS5GpV+gdq1+WpvvR+ 2mCHl/yneXXarwTbpOX8t910k0APXhNBWNELqtMDCMUWFvZmDkDhL+O8SIkWVqvnXuIW ZmBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687518673; x=1690110673; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+hLFPZDPZ0gI0XtOFDQEPz3lIWaqgO4rr6Z2KJLelIY=; b=iOWViFfrmZ50Wj/NpZ0I9YI3NZnGTdHQnzwhxShPAAf4hwuwMDf08ehnOMOPhGBawO nVHgG7Yy1wu8XiUXWdSE7U1Hhv7RlKNg+kilVOCwXPWIDY6owMK6BwUKLgTUq8CFsMWE iT7M7j2luziXubdsrED48XaHzyxovg1CLp/kZCsH+iS0lIYrq2MS5zGeWrantc9RWGOu GhBe/oJVStQodgwhyxAxb3TBK/GueZq96aZHm9L3EYxqSwwteJNy5aMetaiCwZFouzFK 4VvntOi+PFvINQsB/bMkEjeXf+G2/Co2Th5Dc4G5mQJtWL9iGmkkLEH+8oC5udMKLYwR NNtQ== X-Gm-Message-State: AC+VfDwwEyFt2PzDJBMM5UdzWfWlLdbY2L1hyAAel/B0FyUQdtdodAZE B/IDI8VtAALvVKHom2Ge4tGw6ioGW1dXbNFDQnKLu+62dC0= X-Google-Smtp-Source: ACHHUZ6JVNIvI114kj9KZcdcsBFdux+BYjpNQTdPmspdyJUigyBkrHzKDcvcBc0I3e2wW2VAgkHC3KO9trFAk9yLok0= X-Received: by 2002:a2e:9e44:0:b0:2a7:7055:97f5 with SMTP id g4-20020a2e9e44000000b002a7705597f5mr14468535ljk.0.1687518672773; Fri, 23 Jun 2023 04:11:12 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Richard Biener Date: Fri, 23 Jun 2023 13:11:00 +0200 Message-ID: Subject: Re: Do not account __builtin_unreachable guards in inliner To: Jan Hubicka Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,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 List-Id: On Fri, Jun 23, 2023 at 12:11=E2=80=AFPM Jan Hubicka wrote= : > > > On Mon, Jun 19, 2023 at 12:15=E2=80=AFPM Jan Hubicka w= rote: > > > > > > > On Mon, Jun 19, 2023 at 9:52=E2=80=AFAM Jan Hubicka via Gcc-patches > > > > wrote: > > > > > > > > > > Hi, > > > > > this was suggested earlier somewhere, but I can not find the thre= ad. > > > > > C++ has assume attribute that expands int > > > > > if (conditional) > > > > > __builtin_unreachable () > > > > > We do not want to account the conditional in inline heuristics si= nce > > > > > we know that it is going to be optimized out. > > > > > > > > > > Bootstrapped/regtested x86_64-linux, will commit it later today i= f > > > > > thre are no complains. > > > > > > > > I think we also had the request to not account the condition feedin= g > > > > stmts (if they only feed it and have no side-effects). libstdc++ h= as > > > > complex range comparisons here. Also ... > > > > > > I was thinking of this: it depends on how smart do we want to get. > > > We also have dead conditionals guarding clobbers, predicts and other > > > stuff. In general we can use mark phase of cd-dce telling it to igno= re > > > those statements and then use its resut in the analysis. > > > > Hmm, possible but a bit heavy-handed. There's simple_dce_from_worklist > > which might be a way to do this (of course we cannot use that 1:1). Al= so > > then consider > > > > a =3D a + 1; > > if (a > 10) > > __builtin_unreachable (); > > if (a < 5) > > __builtin_unreachable (); > > > > and a has more than one use but both are going away. So indeed a > > more global analysis would be needed to get the full benefit. > > I was looking into simple_dce_from_worklist and if I understand it > right, it simply walks list of SSA names which probably lost some uses > by the consuming pass. If they have zero non-debug uses and defining stat= ement has > no side effects, then they are removed. > > I think this is not really fitting the bill here since the example above > is likely to be common and also if we want one assign filling > conditional optimized out, we probably want to handle case with multiple > assignments. What about > 1) walk function body and see if there are conditionals we know will be > optimized out (at the begining those can be only those which has one > arm reaching __bulitin_unreachable > 2) if there are none, just proceed with fnsummary construction > 3) if there were some, do non-cd-dce mark stage which will skip those > dead conditional identified in 1 > and proceed to fnsummary construction with additional bitmap of > marked stmts. So you need to feed it with extra info on the optimized out stmts because as-is it will not remove __builtin_unreachable (). That means you're doing the find_obviously_necessary_stmts manually, skipping the conditional and all stmts it controls to the __builtin_unreachable () path? I also think you want something cheaper than non-cd-dce mark, you also don'= t want to bother with stores/loads? Also when you only do this conditional how do you plan to use the result? Richard. > > This should be cheaper than unconditionally doing cd-dce and should > handle common cases? > Honza