fix -fcompare-debug regression in asm label redirection

View: New views
3 Messages — Rating Filter:   Alert me  

fix -fcompare-debug regression in asm label redirection

by Alexandre Oliva-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

When we attempt to redirect an edge outgoing from a block that ends in a
GIMPLE_ASM stmt, we create a label decl for the new destination block if
it doesn't have one.

This is a bit wasteful, if the GIMPLE_ASM stmt doesn't have any labels,
or if we're redirecting the fallthrough edge.  But it gets worse when
the GIMPLE_ASM stmt does not have any labels, and it is followed by
debug stmts in the same basic block.  In this case, -fcompare-debug
fails because decl uids go out of sync, since the label decl will only
be created in the compilation in which the debug stmt isn't there.

It would have been trivial to fix this skipping debug stmts at the end
of the block (first patch below), but I figured this wouldn't be as good
as creating the label decls only if needed.  Since there mustn't be
debug stmts after control flow instructions, such as GIMPLE_ASMs with
labels, skipping trailing debug stmts would be a waste of time.  This is
implemented in the second patch below.

While at that, I added a check to ensure that we're redirecting the
fallthrough edge if we didn't replace any of the labels in the asm stmt
(say, if it didn't have labels in the first place, or if it does but
none of them are the targets of the edge we're changing).  It is
perfectly possible that labels in the asm stmt match the dest of the
fallthrough edge, so the test doesn't exclude this possibility.

Ok to install the second patch, if it passes regstrap?  If not, should I
install the first patch?


for  gcc/ChangeLog
from  Alexandre Oliva  <aoliva@...>

        * tree-cfg.c (gimple_redirect_edge_and_branch): Skip debug stmts.

Index: gcc/tree-cfg.c
===================================================================
--- gcc/tree-cfg.c.orig 2009-10-17 02:08:13.000000000 -0300
+++ gcc/tree-cfg.c 2009-10-17 02:10:46.000000000 -0300
@@ -4590,7 +4590,7 @@ gimple_redirect_edge_and_branch (edge e,
  return ret;
     }
 
-  gsi = gsi_last_bb (bb);
+  gsi = gsi_last_nondebug_bb (bb);
   stmt = gsi_end_p (gsi) ? NULL : gsi_stmt (gsi);
 
   switch (stmt ? gimple_code (stmt) : GIMPLE_ERROR_MARK)

for  gcc/ChangeLog
from  Alexandre Oliva  <aoliva@...>

        * tree-cfg.c (gimple_redirect_edge_and_branch) <case GIMPLE_ASM>:
        Create the decl label for the new dest block on demand.  Require
        a fallthrough edge if no asm labels were redirected.

Index: gcc/tree-cfg.c
===================================================================
--- gcc/tree-cfg.c.orig 2009-10-17 02:08:13.000000000 -0300
+++ gcc/tree-cfg.c 2009-10-17 02:50:52.000000000 -0300
@@ -4651,14 +4651,23 @@ gimple_redirect_edge_and_branch (edge e,
     case GIMPLE_ASM:
       {
  int i, n = gimple_asm_nlabels (stmt);
- tree label = gimple_block_label (dest);
+ tree label = NULL;
 
  for (i = 0; i < n; ++i)
   {
     tree cons = gimple_asm_label_op (stmt, i);
     if (label_to_block (TREE_VALUE (cons)) == e->dest)
-      TREE_VALUE (cons) = label;
+      {
+ if (!label)
+  label = gimple_block_label (dest);
+ TREE_VALUE (cons) = label;
+      }
   }
+
+ /* If we didn't find any label matching the former edge in the
+   asm labels, we must be redirecting the fallthrough
+   edge.  */
+ gcc_assert (label || (e->flags & EDGE_FALLTHRU));
       }
       break;
 


--
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist      Red Hat Brazil Compiler Engineer

Re: fix -fcompare-debug regression in asm label redirection

by Alexandre Oliva-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Oct 17, 2009, Alexandre Oliva <aoliva@...> wrote:

> Ok to install the second patch, if it passes regstrap?  If not, should I
> install the first patch?

Ping?

> for  gcc/ChangeLog
> from  Alexandre Oliva  <aoliva@...>

> * tree-cfg.c (gimple_redirect_edge_and_branch): Skip debug stmts.

> for  gcc/ChangeLog
> from  Alexandre Oliva  <aoliva@...>

> * tree-cfg.c (gimple_redirect_edge_and_branch) <case GIMPLE_ASM>:
> Create the decl label for the new dest block on demand.  Require
> a fallthrough edge if no asm labels were redirected.

http://gcc.gnu.org/ml/gcc-patches/2009-10/msg01103.html

--
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist      Red Hat Brazil Compiler Engineer

Re: fix -fcompare-debug regression in asm label redirection

by Richard Henderson-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> * tree-cfg.c (gimple_redirect_edge_and_branch) <case GIMPLE_ASM>:
> Create the decl label for the new dest block on demand.  Require
> a fallthrough edge if no asm labels were redirected.

Ok.


r~