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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |aoliva at gcc dot gnu.org,
                   |                            |jakub at gcc dot gnu.org,
                   |                            |krebbel at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Started with r9-2592-g62852194225ed2df31ff6a600659e5cefbb1e8c0 on this
testcase.
But changing the testcase to:
unsigned a, b, c;

void
foo (void)
{
  if (a <= 65535)
    __builtin_trap ();
  b = 0;
}
again with -O2 -fno-if-conversion it ICEs even earlier, with my
r7-6861-gada61c3d4774b98d42b53e99836abd695969fbc6 change.
And with
unsigned a, b;

void
foo (void)
{
  if (a > 65535)
    b = 0;
  else
    __builtin_trap ();
}
it started even much earlier than that (before svn r200000).

Seems to be similar to PR103028 where Andreas was already suggesting what you
suggest here.
Changing those prepare_cmp_insn:
  /* If we are optimizing, force expensive constants into a register.  */
  if (CONSTANT_P (x) && optimize
      && (rtx_cost (x, mode, COMPARE, 0, optimize_insn_for_speed_p ())
          > COSTS_N_INSNS (1)))
    x = force_reg (mode, x);

  if (CONSTANT_P (y) && optimize
      && (rtx_cost (y, mode, COMPARE, 1, optimize_insn_for_speed_p ())
          > COSTS_N_INSNS (1)))
    y = force_reg (mode, y);
which are purely an optimization to add && !reload_completed
after && optimize would work too, the question is what other
force_reg/copy_to_reg calls in prepare_cmp_insn could be a problem.
The BLKmode case certainly, the VOIDmode case as well (but both of those
shouldn't trigger for the cond_trap cases, then there is
  if (cfun->can_throw_non_call_exceptions)
    {
      if (may_trap_p (x))
        x = copy_to_reg (x);
      if (may_trap_p (y))
        y = copy_to_reg (y);
    }
not really sure about that one.

Reply via email to