Hi,
I have a problem with 4.1 on m68k-linux, which miscompiles the following
test case during the gcse pass:
struct b {
unsigned a : 1;
unsigned b : 1;
unsigned c : 1;
unsigned d : 1;
};
unsigned int x = 1;
void f(int y, struct b *p)
{
switch (y) {
case 1:
p->a = 0;
p->b = 0;
break;
case 3:
p->a = 0;
p->b = 1;
break;
default:
return;
}
p->c = x;
p->d = 1;
}
The assignment to p->c is done via zero_extract:
(insn 46 45 48 5 (set (zero_extract:SI (mem/s/j:QI (reg/v/f:SI 31 [ p ]) [0 S1
A8])
(const_int 1 [0x1])
(const_int 2 [0x2]))
(reg:SI 40 [ x ])) 278 {*m68k.md:4815} (nil)
(nil))
The other assignments are done with (and) and (ior). When propagating the
mem expression, gcse misses this assignment and the assignment to p->d
overwrites it, because the earlier mem expression was propagated past it
in a register.
Currently I'm testing the patch below, which simply invalidates the
load/store. Now I need some help from someone, who is more familiar with
this code, whether this is the correct approach.
It would be nice if above could be changed into (zero_extract:SI (reg)),
but I guess that would be a little too complex.
bye, Roman
Index: gcc/gcse.c
===================================================================
--- gcc/gcse.c (revision 116085)
+++ gcc/gcse.c (working copy)
@@ -5319,6 +5319,16 @@
else
ptr->invalid = 1;
}
+ else if (GET_CODE (dest) == ZERO_EXTRACT)
+ {
+ dest = XEXP (dest, 0);
+ if (MEM_P (dest) && simple_mem (dest))
+ {
+ ptr = ldst_entry (dest);
+ ptr->invalid = 1;
+ }
+
+ }
}
else
invalidate_any_buried_refs (PATTERN (insn));