[PR 47382] We cannot simply fold OBJ_TYPE_REF at all in 4.6

Martin Jambor mjambor@suse.cz
Tue Feb 8 17:53:00 GMT 2011


Hi,

sorry for a late (and a rather brief) reply.

On Fri, Feb 04, 2011 at 12:18:42AM +0300, Maxim Kuvyrkov wrote:
> <trimming CC:>
> 
> On Jan 25, 2011, at 4:57 PM, Martin Jambor wrote:
> 
> > Hi,
> > 
> > PR 47382 is another devirtualization issue but at least this time I
> > think I did not cause it.  The problem is that even when I reverted
> > gimple-folding of OBJ_TYPE_REF to what is being done in 4.5, the IL
> > now looks different and thus we still miscompile stuff.
> 
> Martin,
> 
> Is it expected that this patch stops GCC from devirtualizing cases
> when inlining functions with references for parameters?

This patch basically disables all intraprocedural devirtualization
simply because that transformation relies on assumptions that no
longer hold true.  That leaves only devirtualization within inlining
and IPA-CP but those do not work intraprocedurally (i.e. when the
object is within the same function as the call).  And in your
testcase, early inlining puts all virtual calls to main() where the
objects are.

> 
> GCC mainline just before your patch was optimizing the following
> testcase to have no virtual calls.  I wonder how this can be fixed
> non-intrusively to qualify for Stage 4.

I have patches for this and hope I will post them soon (probably only as an
RFC, however).  They in fact are in the gcc-patches archives:
http://gcc.gnu.org/ml/gcc-patches/2011-01/msg01033.html and 
http://gcc.gnu.org/ml/gcc-patches/2010-12/msg01214.html 

Unfortunately, I am afraid we would need to make a _very_ compelling
case for them to be included at this point.

Martin


> 
> ====================
> /* Verify that the inliner makes good decisions and the example
>    is optimized to 4 printf()s in main().  */
> // { dg-do compile }
> // { dg-options "-O2 -fdump-tree-optimized"  }
> 
> #include <stdio.h>
> 
> class Calculable
> {
> public:
> 	virtual unsigned char calculate() = 0;
> 	virtual ~Calculable() {}
> };
> 
> class X : public Calculable
> {
> public:
> 	unsigned char calculate() { return 1; }
> };
> 
> class Y : public Calculable
> {
> public:
> 	virtual unsigned char calculate() { return 2; }
> };
> 
> static void print(X& c)
> {
> 	printf("%d\n", c.calculate());
> 	printf("+1: %d\n", c.calculate() + 1);
> }
> 
> static void print(Y& c)
> {
> 	printf("%d\n", c.calculate());
> 	printf("+1: %d\n", c.calculate() + 1);
> }
> 
> int main()
> {
> 	X x;
> 	Y y;
> 
> 	print(x);
> 	print(y);
> 
> 	return 0;
> }
> 
> // { dg-final { scan-tree-dump "printf \\(\"%d\\\\n\", 1\\);" "optimized" } }
> // { dg-final { scan-tree-dump "printf \\(\"\\+1: %d\\\\n\", 2\\);" "optimized" } }
> // { dg-final { scan-tree-dump "printf \\(\"%d\\\\n\", 2\\);" "optimized" } }
> // { dg-final { scan-tree-dump "printf \\(\"\\+1: %d\\\\n\", 3\\);" "optimized" } }
> =====================
> 
> Thank you,
> 
> --
> Maxim Kuvyrkov
> CodeSourcery
> +7-812-677-6839
> 



More information about the Gcc-patches mailing list