From patchwork Sat Aug 7 15:25:40 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [rtl-optimization] : Fix PR 45223, RTL PRE GCSE pass hoists trapping insn out of loop Date: Sat, 07 Aug 2010 05:25:40 -0000 From: Uros Bizjak X-Patchwork-Id: 61181 Message-Id: To: gcc-patches@gcc.gnu.org Hello! Attached patch fixes wrong hoisting of trapping insns out from the loop. As commented in the original PR [1], the problem is in PRE GCSE pass that does not look if the moved instruction can trap. The original problem reliably triggers on targets, where modulo is a single HW insn (as in case of moxie-elf target), but the problem can also be shown on x86_64-pc-linux-gnu with slightly modified testcase [2]. 2010-08-07 Uros Bizjak PR rtl-optimization/45223 * gcse.c (compute_hash_table_work): Skip insns that may trap when building hash table. The patch was bootstrapped and regression tested on x86_64-pc-linux-gnu {,-m32} on gcc-4_5 branch. I have also checked that patched gcc produces correct asm for moxie and for modified FP case. In the modified FP case, --ffast-math still hoists FP division out of the loop (allowed by may_trap_p predicate). H.J. will check the performance effect of the patch on the SPEC, but --ffast-math compilation seems to be unaffected. OK for mainline and release branches? [1] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38819#c16 [2] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45223#c2 Uros. Index: gcse.c =================================================================== --- gcse.c (revision 162975) +++ gcse.c (working copy) @@ -1693,7 +1693,7 @@ compute_hash_table_work (struct hash_tab /* The next pass builds the hash table. */ FOR_BB_INSNS (current_bb, insn) - if (INSN_P (insn)) + if (INSN_P (insn) && !may_trap_p (PATTERN (insn))) hash_scan_insn (insn, table); }