From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id 25B2E3858C30 for ; Wed, 6 Dec 2023 09:19:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 25B2E3858C30 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 25B2E3858C30 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701854358; cv=none; b=DkxN8hhkbaI4iHMKlCtrj4GFXHzCe/PXCvjPgqqnVVMoJh2Byy1+fk/ZIAO7U9fySsbeaHXFC+WswfUibR49KogA7D4u9PqbIajKNGZJRMjqaET1ohR1u5FxQyC3SolOazkxHXi3+3HnZAib6/AI14Ziu+S0U/Bcvznv/5qBXCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701854358; c=relaxed/simple; bh=YedHZ7bnNmKJGY0XZEKOJhxuAPnhG5K1f0/XOgDVcm4=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:Message-ID: MIME-Version; b=uACZ5qiz6RI5dY4GlZLOEyZS0q2I4kMF+boIiNsZPrTg62mgVafdbvCNXoJKywdARcaWkOar51RGtBECDwY75KPzKXvPtRFk8Aoam1935M6aFEW4kGGwMmZ0/27CfVgv7AyEDyT0H2PMViw9tLIQHe6MEWXd2Z+quW1bOLHRw/8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.4.150] (unknown [10.168.4.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0151B21E8B; Wed, 6 Dec 2023 09:19:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701854355; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vTry1tlfTqnhflhWu6/unQHjmpTPYn6q8zHjUuAVzLE=; b=uI0iOaXdfozucxrb5pV36gzyTZu/41RSS+wJxAkdi6Dr9nhZaYdiVpiiB20l2w/6kbPhNy 9h1jKwr3eFOXhjCBpkTVYcz6KYoS4ixb2f/ZzaNa95o1rBTySE0ErT68gVzj7lhBTFGnBW L9MW0TKZ3RojaXe46kfoqcRvI7f/AJM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701854355; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vTry1tlfTqnhflhWu6/unQHjmpTPYn6q8zHjUuAVzLE=; b=zf65PZ3mt16K+MNa7BNSjcc4E+V9H1gWjXk0TCPvmUNGvleCHJLdiYCHeZoPR9O35xoHMo EdjVNpzI4OHqQwBw== Date: Wed, 6 Dec 2023 10:15:29 +0100 (CET) From: Richard Biener To: Tamar Christina cc: "gcc-patches@gcc.gnu.org" , nd , "jlaw@ventanamicro.com" Subject: RE: [PATCH 13/21]middle-end: Update loop form analysis to support early break In-Reply-To: Message-ID: <165np7q1-007p-ps82-rss9-5q699oq7prno@fhfr.qr> References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spamd-Result: default: False [-4.30 / 50.00]; ARC_NA(0.00)[]; TO_DN_EQ_ADDR_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.993]; DBL_BLOCKED_OPENRESOLVER(0.00)[gnu.org:email,suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: -4.30 Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,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 Wed, 6 Dec 2023, Tamar Christina wrote: > > -----Original Message----- > > From: Richard Biener > > Sent: Wednesday, December 6, 2023 8:18 AM > > To: Tamar Christina > > Cc: gcc-patches@gcc.gnu.org; nd ; jlaw@ventanamicro.com > > Subject: Re: [PATCH 13/21]middle-end: Update loop form analysis to support early > > break > > > > On Mon, 6 Nov 2023, Tamar Christina wrote: > > > > > Hi All, > > > > > > This sets LOOP_VINFO_EARLY_BREAKS and does some misc changes so the other > > > patches are self contained. > > > > > > Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. > > > > > > Ok for master? > > > > > > Thanks, > > > Tamar > > > > > > gcc/ChangeLog: > > > > > > * tree-vect-loop.cc (vect_analyze_loop_form): Analyse all exits. > > > (vect_create_loop_vinfo): Set LOOP_VINFO_EARLY_BREAKS. > > > (vect_transform_loop): Use it. > > > > > > --- inline copy of patch -- > > > diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc > > > index > > 51a054c5b035ac80dfbbf3b5ba2f6da82fda91f6..f9483eff6e9606e835906fb991 > > f07cd6052491d0 100644 > > > --- a/gcc/tree-vect-loop.cc > > > +++ b/gcc/tree-vect-loop.cc > > > @@ -1700,12 +1700,12 @@ vect_compute_single_scalar_iteration_cost > > (loop_vec_info loop_vinfo) > > > loop_vinfo->scalar_costs->finish_cost (nullptr); > > > } > > > > > > - > > > /* Function vect_analyze_loop_form. > > > > > > Verify that certain CFG restrictions hold, including: > > > - the loop has a pre-header > > > - - the loop has a single entry and exit > > > + - the loop has a single entry > > > + - nested loops can have only a single exit. > > > - the loop exit condition is simple enough > > > - the number of iterations can be analyzed, i.e, a countable loop. The > > > niter could be analyzed under some assumptions. */ > > > @@ -1841,10 +1841,14 @@ vect_analyze_loop_form (class loop *loop, > > vect_loop_form_info *info) > > > "not vectorized: latch block not empty.\n"); > > > > > > /* Make sure the exit is not abnormal. */ > > > - if (exit_e->flags & EDGE_ABNORMAL) > > > - return opt_result::failure_at (vect_location, > > > - "not vectorized:" > > > - " abnormal loop exit edge.\n"); > > > + auto_vec exits = get_loop_exit_edges (loop); > > > + for (edge e : exits) > > > > Seeing this multiple times, this isn't the most efficient way to > > iterate over all exits with LOOPS_HAVE_RECORDED_EXITS. > > > > Note to myself: fix (add to) the API. > > > > > + { > > > + if (e->flags & EDGE_ABNORMAL) > > > + return opt_result::failure_at (vect_location, > > > + "not vectorized:" > > > + " abnormal loop exit edge.\n"); > > > + } > > > > > > info->conds > > > = vect_get_loop_niters (loop, exit_e, &info->assumptions, > > > @@ -1920,6 +1924,10 @@ vect_create_loop_vinfo (class loop *loop, > > vec_info_shared *shared, > > > > > > LOOP_VINFO_IV_EXIT (loop_vinfo) = info->loop_exit; > > > > > > + /* Check to see if we're vectorizing multiple exits. */ > > > + LOOP_VINFO_EARLY_BREAKS (loop_vinfo) > > > + = !LOOP_VINFO_LOOP_CONDS (loop_vinfo).is_empty (); > > > + > > > > Seeing this, s/LOOP_VINFO_LOOP_CONDS/LOOP_VINFO_LOOP_EXIT_CONDS/g > > might be good, if we in future avoid if-conversion in a separate > > pass we will have other CONDs as well. > > > > > if (info->inner_loop_cond) > > > { > > > stmt_vec_info inner_loop_cond_info > > > @@ -11577,7 +11585,7 @@ vect_transform_loop (loop_vec_info loop_vinfo, > > gimple *loop_vectorized_call) > > > /* Make sure there exists a single-predecessor exit bb. Do this before > > > versioning. */ > > > edge e = LOOP_VINFO_IV_EXIT (loop_vinfo); > > > - if (! single_pred_p (e->dest)) > > > + if (! single_pred_p (e->dest) && !LOOP_VINFO_EARLY_BREAKS (loop_vinfo)) > > > { > > > split_loop_exit_edge (e, true); > > > > Note this splitting is done to fulfil versioning constraints on CFG > > update. Do you have test coverage with alias versioning and early > > breaks? > > No, only non-alias versioning. I don't believe we can alias in the current > implementation because it's restricted to statically known objects with > a fixed size. Hm, if side-effects are all correctly in place do we still have that restriction? int x; void foo (int *a, int *b) { int local_x = x; for (int i = 0; i < 1024; ++i) { if (i % local_x == 13) break; a[i] = 2 * b[i]; } } the early exit isn't SCEV analyzable but doesn't depend on any memory and all side-effects are after the exit already. But vectorizing would require alias versioning. Richard.