[PATCH] [codegen] Don't emit implicit unreachable at the end of a non-empty block

Argyrios Kyrtzidis kyrtzidis at apple.com
Sat Mar 16 10:14:09 PDT 2013


The attached patch adds a check so that, if we flow off the end of a value-returning function, the implicit unreachable will only be emitted if the returning block is empty.
For example:

int baz(int x) {
  switch (x) {
    case 1: return 10;
    case 2: return 20;
  }
  // implicit unreachable is inserted
}

int baz2(int x) {
  switch (x) {
    case 1: return 10;
    case 2: return 20;
  }
  foo();
  // no unreachable
}

As a consequence, functions that have no returns, will not get the implicit unreachable:

int baz2(int x) {
  foo();
  // no unreachable
}


I believe this allows taking advantage of the optimization opportunities that the implicit unreachable intended, in a safer manner.

Please review!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: unreachable-on-empty.diff
Type: application/octet-stream
Size: 3412 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130316/23dbf908/attachment.obj>


More information about the cfe-commits mailing list