This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Richard Guenther wrote:
On Thu, Jun 11, 2009 at 6:24 PM, David Daney<ddaney@caviumnetworks.com> wrote:
Richard Henderson wrote:
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.

Ok, that is cleaner.

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
It was jumping around the empty block with a barrier.  I modified the patch
to delete such blocks in try_optimize_cfg().  The resulting code omits the
useless comparison and jump.

Does that then still work for the original intent to mark asms that never return as such?

If I understand the question correctly (which is not certain), yes. I only delete empty blocks. Non-empty blocks such as those containing an asm shouldn't be affected.



Thus, does the patch now delete all blocks that the block with the __builtin_unreachable () call post-dominates?

Not directly, but we have such good data-flow/DCE that the simple cases I examined are taken care of. The builtin-unreachable-2.c test tries to check for this


If not, isn't that what we want to do?

Certainly a __builtin_unreachable statement could imply that there is dead code. And of course, we would want any such dead code eliminated. In the specific case of builtin-unreachable-2.c, we generate optimal code at -O2 on x86_64.


For the general case, we rely on the infallibility of GCC and the fact that a single example proves the general case :-)

David Daney


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]