From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by sourceware.org (Postfix) with ESMTPS id 77FC43858C20 for ; Sat, 1 Oct 2022 18:56:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 77FC43858C20 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-ej1-x633.google.com with SMTP id sd10so15143777ejc.2 for ; Sat, 01 Oct 2022 11:56:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date; bh=VD1+9mH80qh+6D67lWlBg+A+FqOQo39N11hEvv0YA1M=; b=WiW3OaCKNwYAPmNCNE7bI7dCeDB8Ttntf7HprWwhiLhZaFJ/5XEYwCZdOYsezrDmyg IGOqjfzMtEcL2YjwFLkSzDBi7yO4ryaQpIsrFZ+GDuwuIAxKcrwMKXBvAx9M0+3nhhVE JqVFyrmvG70QtXzr+j0T3MlYV6MP0HWA+I/zyewUcjrZK40lfRhofQoR7wQGEq7xPMBX BmJvAM8Jv+iCdE/4HDTniGQXwidLhnQsxlgFnIP/TG+m2kTU5HojKqcr51a1olzbXgFS KDKjOtKz32bEaWzvpcMHqfXv5FYnrGFMNosDy1KXxVF3ELwNn8iWlsCuNwc+VdjVDLnU BMLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date; bh=VD1+9mH80qh+6D67lWlBg+A+FqOQo39N11hEvv0YA1M=; b=XQ7z9zfBQx5h5rBiU3EVzmBk8WnVvQXlg6ZSRfKitbwbTNpdCopAnL3YYobgfoPeFT MlrdJCP/LlOjUChGEwD/h+pbp3zguHRgjXKuco2fcIaHBqFJ8itfcHsOK1q7L1+xlYRD 8YppGanW4d1px7Ff3QbtWO2QBqmUeP32QhZMMfXHmyubFB9bGaD0QHU/KYImLrKfJcbH 4rHaemJNniWkKC6b2Yr8mBUG/jupnF4bv8vtUfAYL6841xmKQNMU90/7eSWNEFIQed/T 51kaKKWyrfR1m6oh9IeFLLbJxbhKT/4+e5GABQxQ8GS5NFhAuBVn0QC2rnVHuKrvvHem iuiw== X-Gm-Message-State: ACrzQf3GEXOCvHThHyjZShxaRAnVDZmBujHNbcvNgMsXr6nm9tApP/Zy 8KVTLxF2AUUzfg+6nR9sNLo= X-Google-Smtp-Source: AMsMyM5WZmGNewkICAC/bdR7cw1PB1ALHPR1KgQWjFjdL/Y9Jgwekgvv7JgHBSgT7PIvDKs/PK90fw== X-Received: by 2002:a17:907:9483:b0:782:242:a364 with SMTP id dm3-20020a170907948300b007820242a364mr10203816ejc.595.1664650576734; Sat, 01 Oct 2022 11:56:16 -0700 (PDT) Received: from nbbrfq ([2001:871:227:1d92:3b3f:9f87:ac65:9ebc]) by smtp.gmail.com with ESMTPSA id p32-20020a056402502000b00457a92f8ad6sm3982923eda.28.2022.10.01.11.56.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 11:56:16 -0700 (PDT) Date: Sat, 1 Oct 2022 20:55:34 +0200 From: Bernhard Reutner-Fischer To: Jeff Law Cc: rep.dot.nop@gmail.com, "gcc-patches@gcc.gnu.org" Subject: Re: [committed] More gimple const/copy propagation opportunities Message-ID: <20221001205534.706b2024@nbbrfq> In-Reply-To: <6baf42b9-0534-dc81-7a54-11317c732a68@ventanamicro.com> References: <6baf42b9-0534-dc81-7a54-11317c732a68@ventanamicro.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.9 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 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, 30 Sep 2022 17:32:34 -0600 Jeff Law wrote: > + /* This looks good from a CFG standpoint. Now look at the guts > + of PRED. Basically we want to verify there are no PHI nodes > + and no real statements. */ > + if (! gimple_seq_empty_p (phi_nodes (pred))) > + return false; So, given the below, neither DEBUG nor labels do count towards an empty seq [coming in from any PHI that is, otherwise it's a different thing], which is a bit surprising but well, ok. It looks at PHI IL, so probably yes. Allegedly that's what it is. Neat if that's true. > + > + gimple_stmt_iterator gsi; > + for (gsi = gsi_last_bb (pred); !gsi_end_p (gsi); gsi_prev (&gsi)) > + { > + gimple *stmt = gsi_stmt (gsi); > + > + switch (gimple_code (stmt)) > + { > + case GIMPLE_LABEL: > + if (DECL_NONLOCAL (gimple_label_label (as_a (stmt)))) > + return false; > + break; > + > + case GIMPLE_DEBUG: > + break; > + > + default: > + return false; don't like, sounds odd. Are we sure there's no other garbage that can manifest here? int meow=42;, and meow unused won't survive?, pragmas neither or stuff ? > + } > + } > + > + return true; > +} > + > /* We have finished optimizing BB, record any information implied by > taking a specific outgoing edge from BB. */ > > @@ -583,6 +656,62 @@ record_edge_info (basic_block bb) > if (can_infer_simple_equiv && TREE_CODE (inverted) == EQ_EXPR) > edge_info->record_simple_equiv (op0, op1); > } > + > + /* If this block is a single block loop, then we may be able to > + record some equivalences on the loop's exit edge. */ > + if (single_block_loop_p (bb)) > + { > + /* We know it's a single block loop. Now look at the loop > + exit condition. What we're looking for is whether or not > + the exit condition is loop invariant which we can detect > + by checking if all the SSA_NAMEs referenced are defined > + outside the loop. */ > + if ((TREE_CODE (op0) != SSA_NAME > + || gimple_bb (SSA_NAME_DEF_STMT (op0)) != bb) > + && (TREE_CODE (op1) != SSA_NAME > + || gimple_bb (SSA_NAME_DEF_STMT (op1)) != bb)) > + { > + /* At this point we know the exit condition is loop > + invariant. The only way to get out of the loop is > + if never traverses the backedge to begin with. This s/if /if it / > + implies that any PHI nodes create equivalances we can that any threw me off asking for "that if any". Would have been nicer, i think? > + attach to the loop exit edge. */ attach it to > + int alternative bool > + = (EDGE_PRED (bb, 0)->flags & EDGE_DFS_BACK) ? 1 : 0; > + > + gphi_iterator gsi; > + for (gsi = gsi_start_phis (bb); > + !gsi_end_p (gsi); > + gsi_next (&gsi)) > + { > + /* If the other alternative is the same as the result, > + then this is a degenerate and can be ignored. */ > + if (dst == PHI_ARG_DEF (phi, !alternative)) > + continue; > + > + /* Now get the EDGE_INFO class so we can append > + it to our list. We want the successor edge > + where the destination is not the source of > + an incoming edge. */ > + gphi *phi = gsi.phi (); > + tree src = PHI_ARG_DEF (phi, alternative); > + tree dst = PHI_RESULT (phi); > + > + if (EDGE_SUCC (bb, 0)->dest > + != EDGE_PRED (bb, !alternative)->src) by now, alternative would be easier to grok if it would have been spelled from_backedge_p or something. IMHO. thanks, > + edge_info = (class edge_info *)EDGE_SUCC (bb, 0)->aux; > + else > + edge_info = (class edge_info *)EDGE_SUCC (bb, 1)->aux; > + > + /* Note that since this processing is done independently > + of other edge equivalency processing, we may not > + have an EDGE_INFO structure set up yet. */ > + if (edge_info == NULL) > + edge_info = new class edge_info (false_edge); > + edge_info->record_simple_equiv (dst, src); > + } > + } > + } > } > } > }