gcc-patches@gcc.gnu.org
[Top] [All Lists]

Re: [PATCH] Add new built-in: __builtin_unreachable()

Subject: Re: [PATCH] Add new built-in: __builtin_unreachable()
From: Richard Henderson
Date: Tue, 09 Jun 2009 16:11:09 -0700
David Daney wrote:
This is exactly the first version of the patch, but we fix rtl_verify_flow_info() so that it properly handles empty blocks when searching for missing barriers.
...
@@ -2041,7 +2041,7 @@ rtl_verify_flow_info (void)
          for (insn = BB_END (bb); !insn || !BARRIER_P (insn);
               insn = NEXT_INSN (insn))
            if (!insn
-               || NOTE_INSN_BASIC_BLOCK_P (insn))
+               || (NOTE_INSN_BASIC_BLOCK_P (insn) && insn != BB_END (bb)))

I'd prefer to have this section rewritten as

@@ -2045,16 +2045,18 @@ rtl_verify_flow_info (void)
        {
          rtx insn;
- /* Ensure existence of barrier in BB with no fallthru edges. */
-         for (insn = BB_END (bb); !insn || !BARRIER_P (insn);
-              insn = NEXT_INSN (insn))
-           if (!insn
-               || NOTE_INSN_BASIC_BLOCK_P (insn))
+         /* Ensure existence of barrier after BB with no fallthru edges.  */
+         for (insn = NEXT_INSN (BB_END (bb)); ; insn = NEXT_INSN (insn))
+           {
+             if (!insn || NOTE_INSN_BASIC_BLOCK_P (insn))
                {
                  error ("missing barrier after block %i", bb->index);
                  err = 1;
                  break;
                }
+             if (BARRIER_P (insn))
+               break;
+           }
        }
       else if (e->src != ENTRY_BLOCK_PTR
               && e->dest != EXIT_BLOCK_PTR)

Note that this version never checks vs BB_END.

I'd also like you to look into why gcc -O on your
builtin-unreachable-2.c test still produces a branch to next:

        cmpl    $1, %edi
        jle     .L2
.L2:
        movl    $1, %eax
        ret

If we are to use this construct with assert.h NDEBUG to give the
compiler extra information with which to optimize, we'd really
like the test itself to be optimized away as well.  At the gimple
level the __builtin_unreachable function call will still be
present, and so the gimple optimizers should be able to take
advantage of the (i > 1) test, but at the rtl level I think we'd
like the totally empty block (and the branch around it) to get
folded away.


r~

<Prev in Thread] Current Thread [Next in Thread>