On 12/18/20 2:19 PM, Martin Liška wrote:
The patch covers 2 cases mentioned in the PR.

I've got a discussion with Jakub on IRC about the patch and he sees
2 more optimizations:

1) using VRP information (from ranger) - I'm leaving that to him, or I can 
return
to it in the next stage 1

2) considering 'return;' (in non-void function) for other cases that default
and __builtin_unreachable for other case than the default one

Let's consider:

unsigned
f1(unsigned x) {
  switch (x) {
    case 0:
      return 10;
    case 1:
      __builtin_unreachable ();
    case 2:
      return;
    case 4:
      return;
    case 10:
      return 23;
    case 13:
      return;
  }

  return 2222;
}

2a) that can be possible, but to be honest I don't see many cases where it can 
help:
    - one can see the warning that is quite obvious:

/home/marxin/Programming/testcases/s.c:9:7: warning: ‘return’ with no value, in 
function returning non-void
    9 |       return;
      |       ^~~~~~
/home/marxin/Programming/testcases/s.c:2:1: note: declared here
    2 | f1(unsigned x) {
      | ^~

    - we can leverage the information and return any value; there's so work 
that needs to be done
      in contains_linear_function_p where we need to skip the "random" values 
and the CFG checking
      code must be adjusted to ignore such cases

2b) the __builtin_unreachable in 'case 1' is removed by unreachable block 
removal and we can't see it:

  switch (x_2(D)) <default: <L6> [INV], case 0: <L10> [INV], case 2: <L9> [INV], case 4: <L9> 
[INV], case 10: <L4> [INV], case 13: <L9> [INV]>

Overall, I tend to leave to the next stage1. The pass needs some bigger 
refactoring and I don't feel
familiar enough to modify it now.

Thanks for understanding,
Martin

Reply via email to