RFC: PR rtl-optimization/43360: [4.3/4.4/4.5 Regression] possible wrong code bug

H.J. Lu hjl.tools@gmail.com
Tue Mar 16 19:29:00 GMT 2010


On Tue, Mar 16, 2010 at 12:03 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Tue, Mar 16, 2010 at 11:56:13AM -0700, H.J. Lu wrote:
>> loop2_invariant rtl pass mishandleis:
>>
>> (insn 9 8 11 3 x.i:8 (set (mem:SI (symbol_ref:DI ("foo")  <var_decl 0x7f516f5438c0 foo>) [2 S4 A32])
>>         (reg:SI 58 [ pretmp.16 ])) 47 {*movsi_1} (nil))
>>
>> (insn 11 9 12 3 x.i:6 (parallel [
>>             (set (reg:SI 60 [ D.1604 ])
>>                 (plus:SI (reg:SI 58 [ pretmp.16 ])
>>                     (const_int 7 [0x7])))
>>             (clobber (reg:CC 17 flags))
>>         ]) 285 {*addsi_1} (expr_list:REG_DEAD (reg:SI 61 [ foo ])
>>         (expr_list:REG_UNUSED (reg:CC 17 flags)
>>             (expr_list:REG_EQUAL (plus:SI (mem/s:SI (symbol_ref:DI ("foo")  <var_decl 0x7f516f5438c0 foo>) [2 foo+0 S4 A32])
>>                     (const_int 7 [0x7]))
>>                 (nil)))))
>>
>> (insn 12 11 14 3 x.i:6 (set (mem/s:SI (symbol_ref:DI ("foo")  <var_decl 0x7f516f5438c0 foo>) [2 foo+0 S4 A32])
>>         (reg:SI 60 [ D.1604 ])) 47 {*movsi_1} (nil))
>>
>>
>> It failed to notice REG_EQUAL note on insn 11 which is
>>
>> foo[0][0] += 7
>>
>> This patch checks REG_EQUAL note.  But I have no ideas if it is correct.
>> Any comments?
>
> I'd say preventing the insn from being optimized is not desirable, instead
> if the REG_EQUAL is not invariant, the note should be dropped.
>
>        Jakub
>

Here is the updated patch.  OK for trunk/4.4/4.3?

Thanks.


-- 
H.J.
-------------- next part --------------
gcc/

2010-03-16  H.J. Lu  <hongjiu.lu@intel.com>

	PR rtl-optimization/43360
	* loop-invariant.c (find_invariant_insn): Drop the REG_EQUAL
	note if it is not invariant.

gcc/testsuite/

2010-03-16  H.J. Lu  <hongjiu.lu@intel.com>

	PR rtl-optimization/43360
	* gcc.dg/torture/pr43360.c: New.

diff --git a/gcc/loop-invariant.c b/gcc/loop-invariant.c
index 03f0a13..c1aca5e 100644
--- a/gcc/loop-invariant.c
+++ b/gcc/loop-invariant.c
@@ -840,7 +840,7 @@ find_invariant_insn (rtx insn, bool always_reached, bool always_executed)
   df_ref ref;
   struct def *def;
   bitmap depends_on;
-  rtx set, dest;
+  rtx set, dest, note;
   bool simple = true;
   struct invariant *inv;
 
@@ -863,6 +863,11 @@ find_invariant_insn (rtx insn, bool always_reached, bool always_executed)
       || !check_maybe_invariant (SET_SRC (set)))
     return;
 
+  /* Drop the REG_EQUAL note if it is not invariant.  */
+   note = find_reg_note (insn, REG_EQUAL, NULL_RTX);
+   if (note && !check_maybe_invariant (XEXP (note, 0)))
+     remove_note (insn, note);
+
   /* If the insn can throw exception, we cannot move it at all without changing
      cfg.  */
   if (can_throw_internal (insn))


More information about the Gcc-patches mailing list