From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by sourceware.org (Postfix) with ESMTPS id 3E7573858418 for ; Wed, 13 Jul 2022 07:13:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3E7573858418 Received: by mail-qk1-x729.google.com with SMTP id 20so8044299qky.5 for ; Wed, 13 Jul 2022 00:13:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=CE1QRV4ZY8fh3DEdkpP7PxG1yGukyCKznvxPRoRFIyA=; b=ucHtd4a8CAq2PBc1IlJzJcxhH9naDc2Zk5ap9GGNxcCGQbU6hzuzJfsR1W7k3CMmTr q7yi8xsAhLvbygk//4xgoCvRXvxHRrDZQq4MR4qMA1vKVxGjsp/nQo4pNbYoyZnPeO/C xbHhHYpHs8YDAmh1Muq0UzrLNPmTObKFrwR2s2dz0jB+7qFw639xPH0OrvSQNMFNJh1t bAkX5NmTqCfHZd8cxOMjfLM5M2RDsG5vEnLARC3O8i7ZP/rl3hNda8CkXQv9LhzbEglB 609WHtxviaHplaX8llKGz4sk57+1fpDU4G1OCkUHiSKcKmcDa8AHrrfxlJKNM6jJzZvS 1CDw== X-Gm-Message-State: AJIora83g6oQfLmqf2NoUaVFEytPf5O216N+upBWMGXJjGnF8WDRtw7g nhh3G/1x2+epXO2pU9IhwQgWeqOH6ed7wNOYTPpqYQCG X-Google-Smtp-Source: AGRyM1uhnMY9qwY9XeWq0bS7b1RleuD3igXs9OvPvzb/uOJYSXnK0kvW02bXx+CJd8g2aIhzYXDR4p8KxSQ54vVcAgg= X-Received: by 2002:a05:620a:190f:b0:6b5:9bf7:60d with SMTP id bj15-20020a05620a190f00b006b59bf7060dmr1391879qkb.627.1657696402431; Wed, 13 Jul 2022 00:13:22 -0700 (PDT) MIME-Version: 1.0 References: <20220114182047.6270-3-amonakov@ispras.ru> In-Reply-To: From: Richard Biener Date: Wed, 13 Jul 2022 09:13:11 +0200 Message-ID: Subject: Re: [PATCH 2/3] tree-cfg: do not duplicate returns_twice calls To: Alexander Monakov Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, 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 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-List-Received-Date: Wed, 13 Jul 2022 07:13:25 -0000 On Tue, Jul 12, 2022 at 10:10 PM Alexander Monakov wrote: > > > Apologies for the prolonged silence Richard, it is a bit of an obscure topic, > and I was unsure I'd be able to handle any complications in a timely manner. > I'm ready to revisit it now, please see below. > > On Mon, 17 Jan 2022, Richard Biener wrote: > > > On Fri, Jan 14, 2022 at 7:21 PM Alexander Monakov wrote: > > > > > > A returns_twice call may have associated abnormal edges that correspond > > > to the "second return" from the call. If the call is duplicated, the > > > copies of those edges also need to be abnormal, but e.g. tracer does not > > > enforce that. Just prohibit the (unlikely to be useful) duplication. > > > > The general CFG copying routines properly duplicate those edges, no? > > No (in fact you say so in the next paragraph). In general I think they cannot, > abnormal edges are a special case, so it should be the responsibility of the > caller. > > > Tracer uses duplicate_block so it should also get copies of all successor > > edges of that block. It also only traces along normal edges. What it might > > miss is abnormal incoming edges - is that what you are referring to? > > Yes (I think its entire point is to build a "trace" of duplicated blocks that > does not have incoming edges in the middle, abnormal or not). > > > That would be a thing we don't handle in duplicate_block on its own but > > that callers are expected to do (though I don't see copy_bbs doing that > > either). I wonder if we can trigger this issue for some testcase? > > Oh yes (in fact my desire to find a testcase delayed this quite a bit). > When compiling the following testcase with -O2 -ftracer: > > __attribute__((returns_twice)) > int rtwice_a(int), rtwice_b(int); > > int f(int *x) > { > volatile unsigned k, i = (*x); > > for (k = 1; (i = rtwice_a(i)) * k; k = 2); > > for (; (i = rtwice_b(i)) * k; k = 4); > > return k; > } > > tracer manages to eliminate the ABNORMAL_DISPATCHER block completely, so > the possibility of transferring control back to rtwice_a from rtwice_b > is no longer modeled in the IR. I could spend some time "upgrading" this > to an end-to-end miscompilation, but I hope you agree this is quite broken > already. > > > The thing to check would be incoming abnormal edges in > > can_duplicate_block_p, not (only) returns twice functions? > > Unfortunately not, abnormal edges are also used for computed gotos, which are > less magic than returns_twice edges and should not block tracer I think. I think computed gotos should use regular edges, only non-local goto should use abnormals... I suppose asm goto also uses abnormal edges? Btw, I don't see how they in general are "less magic". Sure, we have an explicit receiver (the destination label), but we can only do edge inserts if we have a single computed goto edge into a block (we can "move" the label to the block created when splitting the edge). > This implies patch 1/3 [1] unnecessary blocks sinking to computed goto targets. > [1] https://gcc.gnu.org/pipermail/gcc-patches/2022-January/588498.html > > How would you like to proceed here? Is my initial patch ok? Hmm, so for returns twice calls duplicate_block correctly copies the call and redirects the provided incoming edge to it. The API does not handle adding any further incoming edges - the caller would be responsible for this. So I still somewhat fail to see the point here. If tracer does not handle extra incoming edges properly then we need to fix tracer? This also includes non-local goto (we seem to copy non-local labels just fine - wasn't there a bugreport about this!?). So I think can_duplicate_block_p is the wrong place to fix (the RTL side would need a similar fix anyhow?) Richard. > Alexander > > > > > Richard. > > > > > gcc/ChangeLog: > > > > > > * tree-cfg.c (gimple_can_duplicate_bb_p): Reject blocks with > > > calls that may return twice. > > > --- > > > gcc/tree-cfg.c | 7 +++++-- > > > 1 file changed, 5 insertions(+), 2 deletions(-) > > > > > > diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c > > > index b7fe313b7..a99f1acb4 100644 > > > --- a/gcc/tree-cfg.c > > > +++ b/gcc/tree-cfg.c > > > @@ -6304,12 +6304,15 @@ gimple_can_duplicate_bb_p (const_basic_block bb) > > > { > > > gimple *g = gsi_stmt (gsi); > > > > > > - /* An IFN_GOMP_SIMT_ENTER_ALLOC/IFN_GOMP_SIMT_EXIT call must be > > > + /* Prohibit duplication of returns_twice calls, otherwise associated > > > + abnormal edges also need to be duplicated properly. > > > + An IFN_GOMP_SIMT_ENTER_ALLOC/IFN_GOMP_SIMT_EXIT call must be > > > duplicated as part of its group, or not at all. > > > The IFN_GOMP_SIMT_VOTE_ANY and IFN_GOMP_SIMT_XCHG_* are part of such a > > > group, so the same holds there. */ > > > if (is_gimple_call (g) > > > - && (gimple_call_internal_p (g, IFN_GOMP_SIMT_ENTER_ALLOC) > > > + && (gimple_call_flags (g) & ECF_RETURNS_TWICE > > > + || gimple_call_internal_p (g, IFN_GOMP_SIMT_ENTER_ALLOC) > > > || gimple_call_internal_p (g, IFN_GOMP_SIMT_EXIT) > > > || gimple_call_internal_p (g, IFN_GOMP_SIMT_VOTE_ANY) > > > || gimple_call_internal_p (g, IFN_GOMP_SIMT_XCHG_BFLY) > > > -- > > > 2.33.1 > > > > >