[Bug rtl-optimization/18628] [4.0/4.1 regression] miscompilation of switch statement in loop
--- Additional Comments From cvs-commit at gcc dot gnu dot org 2005-03-14 20:06 --- Subject: Bug 18628 CVSROOT:/cvs/gcc Module name:gcc Changes by: [EMAIL PROTECTED] 2005-03-14 20:06:23 Modified files: gcc: ChangeLog cse.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: pr18628.c Log message: gcc/ChangeLog: PR middle-end/18628 * cse.c (fold_rtx_mem): Don't fold a load from a jumptable into a register. gcc/testsuite/ChangeLog: * gcc.dg/pr18628.c: New. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gccr1=2.7849r2=2.7850 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cse.c.diff?cvsroot=gccr1=1.349r2=1.350 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gccr1=1.5166r2=1.5167 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr18628.c.diff?cvsroot=gccr1=NONEr2=1.1 -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18628
[Bug rtl-optimization/18628] [4.0/4.1 regression] miscompilation of switch statement in loop
--- Additional Comments From cvs-commit at gcc dot gnu dot org 2005-03-14 20:32 --- Subject: Bug 18628 CVSROOT:/cvs/gcc Module name:gcc Branch: gcc-4_0-branch Changes by: [EMAIL PROTECTED] 2005-03-14 20:32:50 Modified files: gcc: ChangeLog cse.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: pr18628.c Log message: gcc/ChangeLog: PR middle-end/18628 * cse.c (fold_rtx_mem): Don't fold a load from a jumptable into a register. gcc/testsuite/ChangeLog: * gcc.dg/pr18628.c: New. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcconly_with_tag=gcc-4_0-branchr1=2.7592.2.49r2=2.7592.2.50 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cse.c.diff?cvsroot=gcconly_with_tag=gcc-4_0-branchr1=1.345r2=1.345.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcconly_with_tag=gcc-4_0-branchr1=1.5084.2.44r2=1.5084.2.45 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr18628.c.diff?cvsroot=gcconly_with_tag=gcc-4_0-branchr1=NONEr2=1.1.2.1 -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18628
[Bug rtl-optimization/18628] [4.0/4.1 regression] miscompilation of switch statement in loop
--- Additional Comments From aoliva at gcc dot gnu dot org 2005-03-14 23:43 --- Fixed -- What|Removed |Added Status|ASSIGNED|RESOLVED Resolution||FIXED http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18628
[Bug rtl-optimization/18628] [4.0/4.1 regression] miscompilation of switch statement in loop
--- Additional Comments From rth at gcc dot gnu dot org 2005-03-11 12:45 --- Subject: Re: [PR middle-end/18628] do not fold to label load from tablejump to reg On Thu, Mar 10, 2005 at 05:37:48PM -0300, Alexandre Oliva wrote: * cse.c (fold_rtx_mem): Don't fold a load from a jumptable into a register. Ok. r~ -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18628
[Bug rtl-optimization/18628] [4.0/4.1 regression] miscompilation of switch statement in loop
--- Additional Comments From rth at gcc dot gnu dot org 2005-03-10 13:46 --- Subject: Re: [PR middle-end/18628] do not fold to label load from tablejump to reg On Wed, Mar 09, 2005 at 07:26:37AM -0300, Alexandre Oliva wrote: + /* If it's not a REG, the REG_EQUAL note is inappropriate. */ + if (REG_P (SET_DEST (set))) + set_unique_reg_note (insn, REG_EQUAL, label); I don't think this is a good idea at all. This is just asking for reload to recreate a reference to the deleted label. r~ -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18628
[Bug rtl-optimization/18628] [4.0/4.1 regression] miscompilation of switch statement in loop
--- Additional Comments From aoliva at gcc dot gnu dot org 2005-03-10 20:38 --- Subject: Re: [PR middle-end/18628] do not fold to label load from tablejump to reg On Mar 10, 2005, Richard Henderson [EMAIL PROTECTED] wrote: On Wed, Mar 09, 2005 at 07:26:37AM -0300, Alexandre Oliva wrote: +/* If it's not a REG, the REG_EQUAL note is inappropriate. */ +if (REG_P (SET_DEST (set))) + set_unique_reg_note (insn, REG_EQUAL, label); I don't think this is a good idea at all. This is just asking for reload to recreate a reference to the deleted label. Here's a patch with that bit removed, along with the change in cse_init that it required. Ok? Index: gcc/ChangeLog from Alexandre Oliva [EMAIL PROTECTED] PR middle-end/18628 * cse.c (fold_rtx_mem): Don't fold a load from a jumptable into a register. Index: gcc/cse.c === RCS file: /cvs/gcc/gcc/gcc/cse.c,v retrieving revision 1.349 diff -u -p -r1.349 cse.c --- gcc/cse.c 8 Mar 2005 13:56:56 - 1.349 +++ gcc/cse.c 10 Mar 2005 20:36:36 - @@ -3515,8 +3515,30 @@ fold_rtx_mem (rtx x, rtx insn) if (offset = 0 (offset / GET_MODE_SIZE (GET_MODE (table)) XVECLEN (table, 0))) - return XVECEXP (table, 0, - offset / GET_MODE_SIZE (GET_MODE (table))); + { + rtx label = XVECEXP + (table, 0, offset / GET_MODE_SIZE (GET_MODE (table))); + rtx set; + + /* If we have an insn that loads the label from the + jumptable into a reg, we don't want to set the reg + to the label, because this may cause a reference to + the label to remain after the label is removed in + some very obscure cases (PR middle-end/18628). */ + if (!insn) + return label; + + set = single_set (insn); + + if (! set || SET_SRC (set) != x) + return x; + + /* If it's a jump, it's safe to reference the label. */ + if (SET_DEST (set) == pc_rtx) + return label; + + return x; + } } if (table_insn JUMP_P (table_insn) GET_CODE (PATTERN (table_insn)) == ADDR_DIFF_VEC) Index: gcc/testsuite/ChangeLog from Alexandre Oliva [EMAIL PROTECTED] * gcc.dg/pr18628.c: New. Index: gcc/testsuite/gcc.dg/pr18628.c === RCS file: gcc/testsuite/gcc.dg/pr18628.c diff -N gcc/testsuite/gcc.dg/pr18628.c --- /dev/null 1 Jan 1970 00:00:00 - +++ gcc/testsuite/gcc.dg/pr18628.c 10 Mar 2005 20:36:52 - @@ -0,0 +1,31 @@ +/* { dg-do link } */ +/* { dg-options -O2 } */ + +/* PR middle-end/18628 exposed a problem in which cse folded a load + from a jump table into the label that was the target of the branch. + Unfortunately, the indirect jump was moved to a different basic + block, and the LABEL_REF copied to the register wasn't enough to + keep the cfg from optimizing the otherwise-unused label away. So + we ended up with a dangling reference to the label. */ + +int i; + +int main() +{ + for (;;) + { +switch (i) +{ + case 0: + case 1: +return 1; + + case 2: + case 3: +return 0; + + case 5: +--i; +} + } +} -- Alexandre Oliva http://www.ic.unicamp.br/~oliva/ Red Hat Compiler Engineer [EMAIL PROTECTED], gcc.gnu.org} Free Software Evangelist [EMAIL PROTECTED], gnu.org} -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18628
[Bug rtl-optimization/18628] [4.0/4.1 regression] miscompilation of switch statement in loop
--- Additional Comments From pluto at pld-linux dot org 2005-03-10 23:00 --- I've just built qt334/kde340(core) with -march=i686 -O/-O2. They are totally broken (damaged grahpics/widgets) :/ I don't have a testcase at this moment but gcc4 has a serious bug. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18628
[Bug rtl-optimization/18628] [4.0/4.1 regression] miscompilation of switch statement in loop
--- Additional Comments From pinskia at gcc dot gnu dot org 2005-03-10 23:13 --- (In reply to comment #27) I've just built qt334/kde340(core) with -march=i686 -O/-O2. They are totally broken (damaged grahpics/widgets) :/ I don't have a testcase at this moment but gcc4 has a serious bug. That is most likely PR 19317. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18628
[Bug rtl-optimization/18628] [4.0/4.1 regression] miscompilation of switch statement in loop
--- Additional Comments From law at redhat dot com 2005-03-11 00:51 --- Subject: Re: [PR middle-end/18628] do not fold to label load from tablejump to reg On Thu, 2005-03-10 at 17:37 -0300, Alexandre Oliva wrote: On Mar 10, 2005, Richard Henderson [EMAIL PROTECTED] wrote: On Wed, Mar 09, 2005 at 07:26:37AM -0300, Alexandre Oliva wrote: + /* If it's not a REG, the REG_EQUAL note is inappropriate. */ + if (REG_P (SET_DEST (set))) +set_unique_reg_note (insn, REG_EQUAL, label); I don't think this is a good idea at all. This is just asking for reload to recreate a reference to the deleted label. Here's a patch with that bit removed, along with the change in cse_init that it required. Ok? BTW, can you open a new bug with the same testcase and attach it to the things CSE still catches meta-bug. I'd like to catch this at the tree level if we can rather than wait for our friend CSE. jeff -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18628