This is the mail archive of the gcc-patches@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]
Other format: [Raw text]

Patch: [lno-branch] loop-invariant.c problem


I've had an off-and-on problem with a miscompare in (SPEC) equake on ppc,
and have finally tracked it down to this code. Inside two nested loops there is this RTL,
which is invariant in the inner loop but not the outer loop:

LOOP_BEG:
(insn 2166 2163 2168 132 quake.c:437 (set (reg:SI 1597)
(plus:SI (reg:SI 2101)
(reg:SI 265 [ ivtmp.2219 ]))) 36 {*addsi3_internal1} (nil)
(nil))

(insn 2168 2166 2169 132 quake.c:437 (set (reg:SI 1599)
(ashift:SI (reg:SI 1597)
(const_int 3 [0x3]))) 131 {ashlsi3_no_power} (nil)
(expr_list:REG_EQUAL (ashift:SI (reg:SI 1597)
(const_int 3 [0x3]))
(nil)))

Invariant hoisting decides to hoist these insns (still within the outer loop), but
doesn't replace the reference to 1597 in the NOTE in 2168:

(insn 2166 3468 2168 131 quake.c:437 (set (reg:SI 2151)
(plus:SI (reg:SI 2101)
(reg:SI 265 [ ivtmp.2219 ]))) 36 {*addsi3_internal1} (nil)
(nil))

(insn 2168 2166 2169 131 quake.c:437 (set (reg:SI 2152)
(ashift:SI (reg:SI 2151)
(const_int 3 [0x3]))) 131 {ashlsi3_no_power} (nil)
(expr_list:REG_EQUAL (ashift:SI (reg:SI 1597)
(const_int 3 [0x3]))
(nil)))

LOOP_BEG:

(insn 3778 2163 3779 132 (set (reg:SI 1597)
(reg:SI 2151)) -1 (nil)
(nil))

(insn 3779 3778 3780 132 (set (reg:SI 1599)
(reg:SI 2152)) -1 (nil)
(nil))

Which is wrong, and causes invalid code to be produced when the outer
loop is completely peeled: the REG_EQUAL from one iteration matches
with the set of 1597 from the previous iteration. The fix is simply to record
REG_EQUAL notes as uses:

Index: loop-invariant.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/loop-invariant.c,v
retrieving revision 1.1.4.9
diff -u -d -b -w -r1.1.4.9 loop-invariant.c
--- loop-invariant.c 10 May 2004 17:55:56 -0000 1.1.4.9
+++ loop-invariant.c 24 May 2004 21:24:38 -0000
@@ -303,7 +303,7 @@
for (i = 0; i < loop->num_nodes; i++)
bitmap_set_bit (blocks, body[i]->index);


- df_analyze_subcfg (df, blocks, DF_UD_CHAIN | DF_HARD_REGS);
+ df_analyze_subcfg (df, blocks, DF_UD_CHAIN | DF_HARD_REGS | DF_EQUIV_NOTES);
BITMAP_XFREE (blocks);
}


I believe this is obvious. Any problem?

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