This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Strength reduction bug


This triggers a bug in strength reduction when compiled with -O2:

----------------------------------------------------------------------
void foo (int *BM_tab, int j)
{
  int *BM_tab_base;

  BM_tab_base = BM_tab;
  BM_tab += 0400;
  while (BM_tab_base != BM_tab)
    {
      *--BM_tab = j;
      *--BM_tab = j;
      *--BM_tab = j;
      *--BM_tab = j;
    }
}

int main ()
{
  int BM_tab[0400];
  memset (BM_tab, 0, sizeof (BM_tab));
  foo (BM_tab, 6);
  if (BM_tab[0] != 6)
    abort ();
  return 0;
}
----------------------------------------------------------------------

These are the insns of the loop after the increments of biv 29 are
converted to givs:

----------------------------------------------------------------------
(note 17 57 24 "" NOTE_INSN_LOOP_BEG)

(code_label 24 17 62 5 "" [num uses: 1])

(note 62 24 26 [bb 1] NOTE_INSN_BASIC_BLOCK)

(note 26 62 27 "" NOTE_INSN_DELETED)

(insn 27 26 29 (set (reg:SI 33)
        (plus:SI (reg/v:SI 29)
            (const_int -4 [0xfffffffc]))) 126 {*addsi3_internal} (nil)
    (nil))

(insn 29 27 31 (set (mem:SI (reg:SI 33) 2)
        (reg/v:SI 30)) 42 {movsi+1} (nil)
    (nil))

(insn 31 29 33 (set (reg:SI 34)
        (plus:SI (reg/v:SI 29)
            (const_int -8 [0xfffffff8]))) 126 {*addsi3_internal} (nil)
    (nil))

(insn 33 31 35 (set (mem:SI (reg:SI 34) 2)
        (reg/v:SI 30)) 42 {movsi+1} (nil)
    (nil))

(insn 35 33 37 (set (reg:SI 35)
        (plus:SI (reg/v:SI 29)
            (const_int -12 [0xfffffff4]))) 126 {*addsi3_internal} (nil)
    (nil))

(insn 37 35 39 (set (mem:SI (reg:SI 35) 2)
        (reg/v:SI 30)) 42 {movsi+1} (nil)
    (nil))

(insn 39 37 41 (set (reg/v:SI 29)
        (plus:SI (reg/v:SI 29)
            (const_int -16 [0xfffffff0]))) 126 {*addsi3_internal} (nil)
    (nil))

(insn 41 39 43 (set (mem:SI (reg/v:SI 29) 2)
        (reg/v:SI 30)) -1 (nil)
    (nil))

(note 43 41 60 "" NOTE_INSN_LOOP_CONT)

(note 60 43 20 "" NOTE_INSN_LOOP_VTOP)

(insn 20 60 21 (set (cc0)
        (compare (reg/v:SI 31)
            (reg/v:SI 29))) -1 (nil)
    (nil))

(jump_insn 21 20 49 (set (pc)
        (if_then_else (ne (cc0)
                (const_int 0 [0x0]))
            (label_ref 24)
            (pc))) -1 (nil)
    (nil))

(note 49 21 50 "" NOTE_INSN_LOOP_END)
----------------------------------------------------------------------


;; Function foo


Loop from 17 to 49: 10 real insns.
Continue at insn 43.
Insn 27: possible biv, reg 29, const = -4
Insn 31: possible biv, reg 29, const = -4
Insn 35: possible biv, reg 29, const = -4
Insn 39: possible biv, reg 29, const = -4
Reg 29: biv verified
Biv 29 initialized at insn 15: initial value is complex
Increment 27 of biv 29 converted to giv 33.

Increment 31 of biv 29 converted to giv 34.

Increment 35 of biv 29 converted to giv 35.

Insn 41: dest address src reg 29 benefit 0 lifetime 1 replaceable ncav mult 1 add 0
Loop iterations: Not normal loop.
Final biv value for 29, biv dead after loop exit.
Cannot eliminate biv 29: biv used in insn 20.
Sorted combine statistics:
 {35, 6} {31, 6} {27, 6} {41, 1}
giv at 41 combined with giv at 35
Sorted combine statistics:
 {31, 3} {27, 3}
giv of insn 35 not worth while, 0 vs 10.
giv at 41 recombined with giv at 31 as (plus:SI (reg:SI 34)
    (const_int 8 [0x8]))

This does not correctly handle the biv update (insn 39) between the giv at
41 and the other givs.  The correct combined rtx would have been (plus
(reg 36) (const_int -8)).

Andreas.

-- 
Andreas Schwab                                      "And now for something
schwab@issan.cs.uni-dortmund.de                      completely different"
schwab@gnu.org


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]