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: Paolo Bonzini
Date: Tue, 09 Jun 2009 08:27:06 +0200
Paul Brook wrote:
The new __builtin_unreachable() is meant to be placed directly after
an asm that never returns.  I cannot think of any other valid uses for
it

gcc_unreachable and gcc_assert are obvious candidates.

For gcc_unreachable I agree. For gcc_assert the problem is that sometimes turning

  gcc_assert (*f);

into

  if (*f)
    __builtin_unreachable ();

is not a no-op, and it may introduce additional dereferences or additional register pressure that offset any optimization possibilities stemming from knowledge that "f && *f".

Besides, even in the second version there are two problems. First, the builtin only works on RTL. Until RTL, it does not act as it should---there is no optimization done on trees on

  if (*f)
    __builtin_unreachable ();
  return f != NULL;

(should optimize to return 1). Second, once in RTL I'm not sure how it behaves in cfglayout mode.

Paolo

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