gcc/ 2010-03-16 H.J. Lu PR rtl-optimization/43360 * loop-invariant.c (move_invariant_reg): Bail if the REG_EQUAL note is not invariant. gcc/testsuite/ 2010-03-16 H.J. Lu PR rtl-optimization/43360 * gcc.dg/torture/pr43360.c: New. diff --git a/gcc/loop-invariant.c b/gcc/loop-invariant.c index 82e1829..cd9c88f 100644 --- a/gcc/loop-invariant.c +++ b/gcc/loop-invariant.c @@ -1181,6 +1181,11 @@ move_invariant_reg (struct loop *loop, unsigned invno) the register used for the representative. */ if (inv == repr) { + /* Bail if the REG_EQUAL note is not invariant. */ + note = find_reg_note (inv->insn, REG_EQUAL, NULL_RTX); + if (note && !check_maybe_invariant (XEXP (note, 0))) + goto fail; + if (inv->depends_on) { EXECUTE_IF_SET_IN_BITMAP (inv->depends_on, 0, i, bi) @@ -1213,8 +1218,7 @@ move_invariant_reg (struct loop *loop, unsigned invno) Note that uses in REG_EQUAL notes are taken into account in the computation of invariants. Hence it is safe to retain the note even if the note contains register references. */ - if (! inv->always_executed - && (note = find_reg_note (inv->insn, REG_EQUAL, NULL_RTX))) + if (note && ! inv->always_executed) remove_note (inv->insn, note); } else diff --git a/gcc/testsuite/gcc.dg/torture/pr43360.c b/gcc/testsuite/gcc.dg/torture/pr43360.c new file mode 100644 index 0000000..9ed9872 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr43360.c @@ -0,0 +1,20 @@ +/* { dg-do run } */ + +int l_5_5_2 = 4; +int g_3[1][1]; + +void func_1 (void) +{ + for (g_3[0][0] = 1; g_3[0][0] < 8; g_3[0][0] += 7) { + int *l_6 = &g_3[0][0]; + *l_6 = l_5_5_2; + } +} + +int main (void) +{ + func_1 (); + if (g_3[0][0] != 11) + __builtin_abort (); + return 0; +}