From patchwork Sat Feb 19 20:55:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [PR, tree-optimization/46620, 4.4] skip padding in bitfield SRA grouping Date: Sat, 19 Feb 2011 10:55:08 -0000 From: Alexandre Oliva X-Patchwork-Id: 83715 Message-Id: To: Richard Guenther Cc: gcc-patches@gcc.gnu.org On Feb 16, 2011, Richard Guenther wrote: > On Wed, Feb 16, 2011 at 11:04 AM, Alexandre Oliva wrote: >> Before the latest SRA rewrite, we had a pass that attempted to group >> multiple bitfields into single variables.  It attempted to extend these >> variables to cover padding bits, but there was a bug that got it >> confused when it found padding bits before the range it intended to >> cover. >> >> This patch changes the tests so that the tentatively-extended range will >> always shrink towards the range of interest, instead of getting stuck at >> a padding range. >> >> Regstrapped on x86_64-linux-gnu.  Ok to install? > Please add a runtime testcase for such wrong-code bugs. Ok with > that, please also install the testcase on the 4.5 branch and trunk. Here's the patch that adds the testcase, reduced to a single source file from the two source files in the bug report. for gcc/testsuite/ChangeLog from Alexandre Oliva PR tree-optimization/46620 * gcc.dg/pr46620.c: New. Index: gcc/testsuite/gcc.dg/pr46620.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gcc/testsuite/gcc.dg/pr46620.c 2011-02-19 18:52:23.116761084 -0200 @@ -0,0 +1,76 @@ +/* PR tree-optimization/46620 */ +/* SRA bitfield grouping used to lose track at padding bitfields in + the middle of a word. */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +#include + +struct PCT +{ + unsigned char pi1 : 4; + unsigned char pi2 : 3; + unsigned char pif : 5; + + unsigned char sl : 2; + unsigned char uc : 1; + unsigned char st : 1; + + unsigned char p : 1; + unsigned char cs : 1; + unsigned char ss : 1; + + unsigned char pc : 3; + unsigned char dmv : 4; + unsigned char cv : 4; +}; + +struct rt +{ + struct rt* d; + void (*edo)(void * const); + short lId; + char dac; +}; + +struct pedr +{ + struct rt re; + struct PCT pc; + unsigned char mid; +} ; + +void __attribute__((__noinline__)) +rei(struct rt* const me, unsigned short anId, void *ad ) +{ + asm volatile (""); +} + +void __attribute__((__noinline__)) +pedrdo(void * const p) +{ + asm volatile (""); +} + +void __attribute__((__noinline__)) +pedri (struct pedr* const me, struct PCT ppc, unsigned char pmid) +{ + rei(&(me->re), 0x7604, 0); + me->pc = ppc; + me->mid = pmid; + (me)->re.edo = pedrdo; +} + +int main() +{ + struct PCT ps; + struct pedr pm; + + pm.pc.dmv = 0; + ps.dmv = 1; + pedri(&pm, ps, 32); + + if (pm.pc.dmv != 1) + abort (); + exit (0); +}