public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR tree-optimization/109462 - Don't use ANY PHI equivalences in range-on-entry.
@ 2023-04-11 23:52 Andrew MacLeod
  2023-04-12  8:20 ` Jakub Jelinek
  2023-04-12  9:12 ` Richard Biener
  0 siblings, 2 replies; 11+ messages in thread
From: Andrew MacLeod @ 2023-04-11 23:52 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek, Richard Biener, hernandez, aldy

[-- Attachment #1: Type: text/plain, Size: 1541 bytes --]

This is a carry over from PR 108139.

When we have a PHI node which has 2 arguments and one is undefined, we 
create an equivalence between the LHS and the non-undefined PHI 
argument.  THis allows us to perform certain optimizations.

The problem is, when we are evaluating range-on-entry in the cache, its 
depends on where that equivalence is made, from where we have no context.

a_3 = <b_2 (3), c_3 (4)>

if c_3 is undefined,  then a_3 is equivalent to b_2... but b_2 is not 
equivalence to a_3 everywhere..   its a one way thing.

108139 fixed this by not evaluating any equivalences if the equivalence 
was the LHS.

What it missed, was it possible we are calculating the range of a_3.   
b_2 is not defined in a phi node, so it happily used the equivalence.  
This PR demonstrates that we can't always use that equivlence either 
without more context.  There can be places in the IL where a_3 is used, 
but b_2 has moved to a new value within a loop.

So we can't do this if either NAME or the equivalence is equal via a PHI 
node with an undefined argument.

Unfortunately, this unsafe assumption is why PR 101912 is fixed.   
Fixing this issue properly is going to cause that to reopen as it is 
unsafe. (That PR is  a false uninitialized warning issue, rather than an 
wrong-code issue)

This bootstraps on x86_64-pc-linux-gnu  with that single regression, 
which I have XFAILed for now.  OK for trunk?   Once Jakub verifies it 
actually fixes the execution problem.   we have no executable test . yet.

Andrew




[-- Attachment #2: 462.patch --]
[-- Type: text/x-patch, Size: 2165 bytes --]

commit 90848fb75cf91a45edd355d2b1485ef835099609
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Tue Apr 11 17:29:03 2023 -0400

    Don't use ANY PHI equivalences in range-on-entry.
    
    PR 108139 dissallows PHI equivalencies in the on-entry calculator, but
    it was only checking if the equivlaence was a PHI.  In this case, NAME
    itself is a PHI with an equivlaence caused by an undefined value, so we
    also need to check that case.  Unfortunately this un-fixes 101912.
    
            PR tree-optimization/109462
            gcc/
            * gimple-range-cache.cc (ranger_cache::fill_block_cache): Don't
            check for equivalences if NAME is a phi node.
    
            gcc/testsuite/
            * gcc.dg/uninit-pr101912.c: XFAIL the warning.

diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc
index 6a098d8ec28..3b52f1e734c 100644
--- a/gcc/gimple-range-cache.cc
+++ b/gcc/gimple-range-cache.cc
@@ -1218,7 +1218,9 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb)
 	  fprintf (dump_file, "\n");
 	}
       // See if any equivalences can refine it.
-      if (m_oracle)
+      // PR 109462, like 108139 below, a one way equivalence introduced
+      // by a PHI node can also be through the definition side.  Disallow it.
+      if (m_oracle && !is_a<gphi *> (SSA_NAME_DEF_STMT (name)))
 	{
 	  tree equiv_name;
 	  relation_kind rel;
diff --git a/gcc/testsuite/gcc.dg/uninit-pr101912.c b/gcc/testsuite/gcc.dg/uninit-pr101912.c
index 1550c03436d..62cd2a0c73e 100644
--- a/gcc/testsuite/gcc.dg/uninit-pr101912.c
+++ b/gcc/testsuite/gcc.dg/uninit-pr101912.c
@@ -11,7 +11,7 @@ tzloadbody (void)
   for (int i = 0; i < n; i++)
     {
       int corr = getint ();
-      if (corr < 1 || (corr == 1 && !(leapcnt == 0 || (prevcorr < corr ? corr == prevcorr + 1 : (corr == prevcorr || corr == prevcorr - 1))))) /* { dg-bogus "uninitialized" } */
+      if (corr < 1 || (corr == 1 && !(leapcnt == 0 || (prevcorr < corr ? corr == prevcorr + 1 : (corr == prevcorr || corr == prevcorr - 1))))) /* { dg-bogus "uninitialized" "pr101912" { xfail *-*-* } } */
 	return -1;
 
       prevcorr = corr;

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-04-13 16:20 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-11 23:52 [PATCH] PR tree-optimization/109462 - Don't use ANY PHI equivalences in range-on-entry Andrew MacLeod
2023-04-12  8:20 ` Jakub Jelinek
2023-04-12 13:12   ` Andrew MacLeod
2023-04-12  9:12 ` Richard Biener
2023-04-12 10:58   ` Jakub Jelinek
2023-04-12 11:01     ` Richard Biener
2023-04-12 20:55       ` Andrew MacLeod
2023-04-13 13:56         ` Richard Biener
2023-04-13 15:48           ` Andrew MacLeod
2023-04-13 16:18             ` Richard Biener
2023-04-13 16:20             ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).