[Bug rtl-optimization/66614] LRA might fail to eliminate dead code

bernd.edlinger at hotmail dot de gcc-bugzilla@gcc.gnu.org
Sun Jun 28 07:18:00 GMT 2015


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66614

--- Comment #3 from Bernd Edlinger <bernd.edlinger at hotmail dot de> ---
I checked a few apps, and have not yet found any impact of the return
value of rtx_addr_can_trap_p_1 on the final code so far.

That means that this is probably only a low prio bug...

Regarding the LRA, I think there are two different "may trap":

One is an instruction that may trap in a predictable way, like integer-div:

Example:

  try {

     int unused = a/b;

   } catch (...)

here it would not be OK to remove the division, although the result will not
be used directly.  (may_trap_p returns 1)

However there are other instructions that may trap in an unpredictable way,
but they invoke undefined behaviour first, like accessing an array
out-of-bounds:

Example:

   try {
     int a[1];
     int unused = a[1234];
   }  catch (...)

here it would be OK to remove the array access, because it invokes undefined
behavour.  (rtx_addr_can_trap_p_1 returns 1)

It is impossible to predict, if the catch block will be executed anyway, so
it is no big deal to remove this instruction.


My conclusion would be that LRA might need something like
"may_trap_without_undefined_behaviour_p()"
which does most things like may_trap_p but does not care about
array bounds for instance.



More information about the Gcc-bugs mailing list