http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56982



--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> 2013-04-17 
08:48:33 UTC ---

So the questions are:

- is it desirable that uncprop does anything to SSA_NAME_VAR == NULL phis?



sure - it is all about improving out-of-SSA coalescing opportunities

and avoiding copies



- shouldn't something like that be not performed if current function calls

setjmp (or more narrowly, if there is a returns twice function somewhere in

between the considered setter and user)?



the testcase shows that uncprop extends the lifetime of an SSA name

across a setjmp call - but it can only do so because it's an SSA name.

Which means the testcase is questionable as 'n' is not declared volatile, no?



- what other optimizations might be similarly problematic across returns twice

calls?



every optimization pass that performs hosting.  PRE comes to my mind for



  if (x)

    tem = expr;

  setjmp ()

  var = expr;



which would happily eliminate the partial redundancy, moving expr to the

else arm of the if () and thus extending the lifetime of 'var' across

the setjmp call.



We do not explicitely model the abnormal control flow for setjmp / longjmp

which is the reason all these issues may appear.  So I believe the

correct fix is to either declare the testcase invalid or to model

the abnormal control flow explicitely. Add abnormal edges from all

call sites in the function that may end up calling longjmp _and_ eventually an

abnormal edge from function entry as we can call longjmp from callers

as well (though that may be invalid and thus we do not have to care?).



I don't see an "easy" fix for the issue (well, maybe the specific testcase).

That it happens only after my patch is probably pure luck because of for

example the PRE issue.  Testcase for that:



int f (int a, int flag)

{

  int tem;

  if (flag)

    tem = a + 1;

  int x = setjmp (env);

  int tem2 = a + 1;

  if (x)

    return tem2;

  return tem;

}



validity of course is questionable, but we clearly use tem only on the

normal path and tem2 on the abnormal path.  PRE does the transform

I indicated, proper abnormal edges would disable the transform.

Reply via email to