public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/59559] New: ICE: invalid RTX sharing in expmed.c:expand_divmod
@ 2013-12-19 12:57 gjl at gcc dot gnu.org
  2013-12-19 15:32 ` [Bug middle-end/59559] " ebotcazou at gcc dot gnu.org
  2023-11-14  7:03 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: gjl at gcc dot gnu.org @ 2013-12-19 12:57 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 59559
           Summary: ICE: invalid RTX sharing in expmed.c:expand_divmod
           Product: gcc
           Version: 4.8.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gjl at gcc dot gnu.org

In expmed.c:expand_divmod() we have the following code:

    t1 = expmed_mult_highpart
      (compute_mode, op0,
       gen_int_mode (ml, compute_mode),
       NULL_RTX, 1, max_cost - extra_cost);
    if (t1 == 0)
      goto fail1;
    t2 = force_operand (gen_rtx_MINUS (compute_mode,
                       op0, t1),
            NULL_RTX);
    t3 = expand_shift (RSHIFT_EXPR, compute_mode,
               t2, 1, NULL_RTX, 1);
    t4 = force_operand (gen_rtx_PLUS (compute_mode,
                      t1, t3),
            NULL_RTX);

This code produces invalid RTX sharing for t1 if some conditions are met:

- The code is used after tree->RTL lowering which can happen in
  some loop optimizations.  A possible call chain is from
  loop_doloop.c:doloop_modify() and if the force_operand there
  operates on a UDIV or DIV expression and finally ends up with the
  expmed.c code from above.

- The value for t1 is a SUBREG like (subreg:SI (reg:DI xxx) 4)
  This depends on the backend and if and how it implements
  (widening) multiplication and mul_highpart insns.

- The ICE will depend on the cost model of the target.

- The ICE will only pop up if RTL checking is enabled.

I could not reproduce this ICE with a standard GCC target, I just see it for a
private port.  However, this might also be a latent problem for official GCC
targets.  The problem is that the loop optimization above runs after RTL
unsharing so that the sharing of the SUBREG is not resolved.

A possible fix is obviously to t1 = copy_rtx (t1) after the first use of t1 and
befor its second use.

FYI, the code for which I see the ICE is gcc.c-torture/execute/loop-3b.c from
GCC's test suite -- but as already said I found no official target that breaks
there.

There is also a simpler example like the code below, but fpr x86 and rs6000 it
works fine :-(

int n;

void f (int val)
{
  while (n > 0)
    {
      val++;
      n -=45;
    }
}


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/59559] ICE: invalid RTX sharing in expmed.c:expand_divmod
  2013-12-19 12:57 [Bug middle-end/59559] New: ICE: invalid RTX sharing in expmed.c:expand_divmod gjl at gcc dot gnu.org
@ 2013-12-19 15:32 ` ebotcazou at gcc dot gnu.org
  2023-11-14  7:03 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2013-12-19 15:32 UTC (permalink / raw)
  To: gcc-bugs

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

Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-12-19
                 CC|                            |ebotcazou at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
See expand_mult_const for a similar issue and possible fix.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/59559] ICE: invalid RTX sharing in expmed.c:expand_divmod
  2013-12-19 12:57 [Bug middle-end/59559] New: ICE: invalid RTX sharing in expmed.c:expand_divmod gjl at gcc dot gnu.org
  2013-12-19 15:32 ` [Bug middle-end/59559] " ebotcazou at gcc dot gnu.org
@ 2023-11-14  7:03 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-14  7:03 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2021-12-18 00:00:00         |2023-11-13

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note the code is still the same today.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-11-14  7:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-19 12:57 [Bug middle-end/59559] New: ICE: invalid RTX sharing in expmed.c:expand_divmod gjl at gcc dot gnu.org
2013-12-19 15:32 ` [Bug middle-end/59559] " ebotcazou at gcc dot gnu.org
2023-11-14  7:03 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).