Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 5)

2014-01-09 Thread Richard Biener
Jakub Jelinek wrote: >On Thu, Jan 09, 2014 at 02:27:40PM +0100, Richard Biener wrote: >> > Perhaps, if you don't like the !gimple_in_ssa_p (cfun) in the >condition >> > we can just drop the lhs always in that case, just doing what we do >for >> > __builtin_unreachable if lhs is SSA_NAME: >> > tr

[PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 5)

2014-01-09 Thread Jakub Jelinek
On Thu, Jan 09, 2014 at 02:27:40PM +0100, Richard Biener wrote: > > Perhaps, if you don't like the !gimple_in_ssa_p (cfun) in the condition > > we can just drop the lhs always in that case, just doing what we do for > > __builtin_unreachable if lhs is SSA_NAME: > > tree var = create_tmp_var (TREE

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 3)

2014-01-09 Thread Richard Biener
On Thu, 9 Jan 2014, Jakub Jelinek wrote: > On Thu, Jan 09, 2014 at 02:13:39PM +0100, Richard Biener wrote: > > On Thu, 9 Jan 2014, Jakub Jelinek wrote: > > > > > On Thu, Jan 09, 2014 at 01:30:53PM +0100, Richard Biener wrote: > > > > > gimplify_modify_expr has: > > > > > > > > > > if (!gim

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 3)

2014-01-09 Thread Jakub Jelinek
On Thu, Jan 09, 2014 at 02:13:39PM +0100, Richard Biener wrote: > On Thu, 9 Jan 2014, Jakub Jelinek wrote: > > > On Thu, Jan 09, 2014 at 01:30:53PM +0100, Richard Biener wrote: > > > > gimplify_modify_expr has: > > > > > > > > if (!gimple_call_noreturn_p (assign)) > > > > gimple_cal

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 3)

2014-01-09 Thread Richard Biener
On Thu, 9 Jan 2014, Jakub Jelinek wrote: > On Thu, Jan 09, 2014 at 01:30:53PM +0100, Richard Biener wrote: > > > gimplify_modify_expr has: > > > > > > if (!gimple_call_noreturn_p (assign)) > > > gimple_call_set_lhs (assign, *to_p); > > > > Ok, it seems to be too early then - move i

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 3)

2014-01-09 Thread Jakub Jelinek
On Thu, Jan 09, 2014 at 01:30:53PM +0100, Richard Biener wrote: > > gimplify_modify_expr has: > > > > if (!gimple_call_noreturn_p (assign)) > > gimple_call_set_lhs (assign, *to_p); > > Ok, it seems to be too early then - move it after the folding. That wouldn't help all the other e

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 3)

2014-01-09 Thread Richard Biener
On Thu, 9 Jan 2014, Jakub Jelinek wrote: > On Thu, Jan 09, 2014 at 12:31:47PM +0100, Richard Biener wrote: > > On Thu, 9 Jan 2014, Jakub Jelinek wrote: > > > > > On Thu, Jan 09, 2014 at 12:15:00PM +0100, Richard Biener wrote: > > > > > Well, then the __cxa_pure_virtual testcases ICE again, but th

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 3)

2014-01-09 Thread Jakub Jelinek
On Thu, Jan 09, 2014 at 12:31:47PM +0100, Richard Biener wrote: > On Thu, 9 Jan 2014, Jakub Jelinek wrote: > > > On Thu, Jan 09, 2014 at 12:15:00PM +0100, Richard Biener wrote: > > > > Well, then the __cxa_pure_virtual testcases ICE again, but the > > > > pr59622-5.C > > > > testcase ICEs anyway,

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 3)

2014-01-09 Thread Richard Biener
On Thu, 9 Jan 2014, Jakub Jelinek wrote: > On Thu, Jan 09, 2014 at 12:15:00PM +0100, Richard Biener wrote: > > > Well, then the __cxa_pure_virtual testcases ICE again, but the pr59622-5.C > > > testcase ICEs anyway, so here is a different patch (untested so far except > > > for the tests). The is

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 3)

2014-01-09 Thread Jakub Jelinek
On Thu, Jan 09, 2014 at 12:15:00PM +0100, Richard Biener wrote: > > Well, then the __cxa_pure_virtual testcases ICE again, but the pr59622-5.C > > testcase ICEs anyway, so here is a different patch (untested so far except > > for the tests). The issue with the calls is that when fold_stmt is done

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 3)

2014-01-09 Thread Richard Biener
On Thu, 9 Jan 2014, Jakub Jelinek wrote: > On Thu, Jan 09, 2014 at 09:46:11AM +0100, Richard Biener wrote: > > > + /* If fndecl (like __builtin_unreachable or > > > + __cxa_pure_virtual) takes no arguments, doesn't have > > > + return value and is noreturn, if the call does

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 3)

2014-01-09 Thread Jakub Jelinek
On Thu, Jan 09, 2014 at 09:46:11AM +0100, Richard Biener wrote: > > + /* If fndecl (like __builtin_unreachable or > > +__cxa_pure_virtual) takes no arguments, doesn't have > > +return value and is noreturn, if the call doesn't have > > +lhs or lhs isn't S

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 3)

2014-01-09 Thread Richard Biener
On Wed, 8 Jan 2014, Jakub Jelinek wrote: > On Wed, Jan 08, 2014 at 12:19:02PM +0100, Richard Biener wrote: > > On Wed, 8 Jan 2014, Jakub Jelinek wrote: > > > > > On Wed, Jan 08, 2014 at 12:15:40PM +0100, Richard Biener wrote: > > > > > I start to think this is a too complex transform for stmt fol

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 3)

2014-01-08 Thread Jakub Jelinek
On Wed, Jan 08, 2014 at 12:19:02PM +0100, Richard Biener wrote: > On Wed, 8 Jan 2014, Jakub Jelinek wrote: > > > On Wed, Jan 08, 2014 at 12:15:40PM +0100, Richard Biener wrote: > > > > I start to think this is a too complex transform for stmt folding ... > > > > > > Alternatively do update_call_f

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 3)

2014-01-08 Thread Richard Biener
On Wed, 8 Jan 2014, Jakub Jelinek wrote: > On Wed, Jan 08, 2014 at 12:15:40PM +0100, Richard Biener wrote: > > > I start to think this is a too complex transform for stmt folding ... > > > > Alternatively do update_call_from_tree (gsi, get_or_create_ssa_default_def > > (cfun, create_tmp_var (TRE

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 3)

2014-01-08 Thread Jakub Jelinek
On Wed, Jan 08, 2014 at 12:15:40PM +0100, Richard Biener wrote: > > I start to think this is a too complex transform for stmt folding ... > > Alternatively do update_call_from_tree (gsi, get_or_create_ssa_default_def > (cfun, create_tmp_var (TREE_TYPE (lhs. The lhs might not be is_gimple_reg

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 3)

2014-01-08 Thread Richard Biener
On Wed, 8 Jan 2014, Richard Biener wrote: > On Wed, 8 Jan 2014, Jakub Jelinek wrote: > > > On Wed, Jan 08, 2014 at 11:45:28AM +0100, Richard Biener wrote: > > > I prefer to always do this, not do the fancy insertion-before. That > > > would do repeated folding for > > > > > >fold_stmt (gsi)

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 3)

2014-01-08 Thread Richard Biener
On Wed, 8 Jan 2014, Jakub Jelinek wrote: > On Wed, Jan 08, 2014 at 11:45:28AM +0100, Richard Biener wrote: > > I prefer to always do this, not do the fancy insertion-before. That > > would do repeated folding for > > > >fold_stmt (gsi); > >fold_stmt (gsi); > >fold_stmt (gsi); > > >

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 3)

2014-01-08 Thread Jakub Jelinek
On Wed, Jan 08, 2014 at 11:45:28AM +0100, Richard Biener wrote: > I prefer to always do this, not do the fancy insertion-before. That > would do repeated folding for > >fold_stmt (gsi); >fold_stmt (gsi); >fold_stmt (gsi); > > where the last two should be a no-op. I don't see how is

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 3)

2014-01-08 Thread Richard Biener
On Tue, 7 Jan 2014, Jakub Jelinek wrote: > Hi! > > On Fri, Jan 03, 2014 at 11:33:50AM +0100, Jakub Jelinek wrote: > > On Fri, Jan 03, 2014 at 11:24:53AM +0100, Richard Biener wrote: > > Anyway, back to the original patch, so do you prefer something like > this instead? I.e. handle only __builti

[PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 3)

2014-01-07 Thread Jakub Jelinek
Hi! On Fri, Jan 03, 2014 at 11:33:50AM +0100, Jakub Jelinek wrote: > On Fri, Jan 03, 2014 at 11:24:53AM +0100, Richard Biener wrote: Anyway, back to the original patch, so do you prefer something like this instead? I.e. handle only __builtin_unreachable and __cxa_pure_virtual specially, and not

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 2)

2014-01-03 Thread Jakub Jelinek
On Fri, Jan 03, 2014 at 11:24:53AM +0100, Richard Biener wrote: > works just fine for me but shows > > int (*) () f; > > int _4; > >

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 2)

2014-01-03 Thread Richard Biener
On Fri, 3 Jan 2014, Richard Biener wrote: > On Fri, 3 Jan 2014, Jakub Jelinek wrote: > > > On Fri, Jan 03, 2014 at 11:15:32AM +0100, Richard Biener wrote: > > > so if there is a decl then use its type signature, otherwise > > > (indirect calls) use the caller signature (and hope it matches > > >

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 2)

2014-01-03 Thread Richard Biener
On Fri, 3 Jan 2014, Jakub Jelinek wrote: > On Fri, Jan 03, 2014 at 11:15:32AM +0100, Richard Biener wrote: > > so if there is a decl then use its type signature, otherwise > > (indirect calls) use the caller signature (and hope it matches > > the callee...). That it later falls back to looking at

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 2)

2014-01-03 Thread Jakub Jelinek
On Fri, Jan 03, 2014 at 11:15:32AM +0100, Richard Biener wrote: > so if there is a decl then use its type signature, otherwise > (indirect calls) use the caller signature (and hope it matches > the callee...). That it later falls back to looking at > DECL_ARGUMENTS is odd (probably a FE issue wher

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 2)

2014-01-03 Thread Richard Biener
On Fri, 3 Jan 2014, Jakub Jelinek wrote: > On Fri, Jan 03, 2014 at 11:01:13AM +0100, Richard Biener wrote: > > > Well, see PR59630. The question is if having to handle it everywhere > > > is worth it. > > > > Well, this case happens because we go back to GENERIC which doesn't > > have this featu

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 2)

2014-01-03 Thread Jakub Jelinek
On Fri, Jan 03, 2014 at 11:01:13AM +0100, Richard Biener wrote: > > Well, see PR59630. The question is if having to handle it everywhere > > is worth it. > > Well, this case happens because we go back to GENERIC which doesn't > have this feature. So "everywhere" is somewhat a broad stmt. > It's

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 2)

2014-01-03 Thread Richard Biener
On Fri, 3 Jan 2014, Jakub Jelinek wrote: > On Fri, Jan 03, 2014 at 10:26:44AM +0100, Richard Biener wrote: > > Jakub Jelinek wrote: > > >On Tue, Dec 31, 2013 at 11:30:12AM +0100, Richard Biener wrote: > > >> Meanwhile your patch is ok. > > > > > >As discussed in the PR, the patch wasn't sufficien

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 2)

2014-01-03 Thread Jakub Jelinek
On Fri, Jan 03, 2014 at 10:26:44AM +0100, Richard Biener wrote: > Jakub Jelinek wrote: > >On Tue, Dec 31, 2013 at 11:30:12AM +0100, Richard Biener wrote: > >> Meanwhile your patch is ok. > > > >As discussed in the PR, the patch wasn't sufficient, __cxa_pure_virtual > >can appear in the vtable and

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 2)

2014-01-03 Thread Richard Biener
Jakub Jelinek wrote: >On Tue, Dec 31, 2013 at 11:30:12AM +0100, Richard Biener wrote: >> Meanwhile your patch is ok. > >As discussed in the PR, the patch wasn't sufficient, __cxa_pure_virtual >can appear in the vtable and it has pretty much the same properties >as __builtin_unreachable (void retur

[PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 2)

2014-01-03 Thread Jakub Jelinek
On Tue, Dec 31, 2013 at 11:30:12AM +0100, Richard Biener wrote: > Meanwhile your patch is ok. As discussed in the PR, the patch wasn't sufficient, __cxa_pure_virtual can appear in the vtable and it has pretty much the same properties as __builtin_unreachable (void return value, no arguments, noret

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622)

2013-12-31 Thread Richard Biener
Jan Hubicka wrote: >> >I think so, after all don't we set noreturn attribute automatically >> >even if it is missing when IPA can prove the function never returns? >> >If we fold_stmt after that, the above testcase even without explicit >> >noreturn attribute would need cfg cleanup. >> > >> >Perha

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622)

2013-12-31 Thread Jan Hubicka
> >I think so, after all don't we set noreturn attribute automatically > >even if it is missing when IPA can prove the function never returns? > >If we fold_stmt after that, the above testcase even without explicit > >noreturn attribute would need cfg cleanup. > > > >Perhaps gimple_fold_call should

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622)

2013-12-31 Thread Richard Biener
Jakub Jelinek wrote: >On Tue, Dec 31, 2013 at 08:39:02AM +0100, Richard Biener wrote: >> >That said, fold_stmt callers have to be prepared to handle say a >normal >> >call becoming noreturn call, consider say: >> > >> >struct A { virtual int foo (); }; >> >struct B : public A { int foo () __attrib

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622)

2013-12-31 Thread Jakub Jelinek
On Tue, Dec 31, 2013 at 08:39:02AM +0100, Richard Biener wrote: > >That said, fold_stmt callers have to be prepared to handle say a normal > >call becoming noreturn call, consider say: > > > >struct A { virtual int foo (); }; > >struct B : public A { int foo () __attribute__((noreturn)); }; > >int

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622)

2013-12-30 Thread Richard Biener
Jakub Jelinek wrote: >On Mon, Dec 30, 2013 at 10:14:16PM +0100, Jan Hubicka wrote: >> this is C version >> static int (*p) (int a) = (int (*)(int))__builtin_unreachable; >> main() >> { >> return p(1); >> } > >Well, that testcase is invalid, as you are calling the function >(builtin) >through inc

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622)

2013-12-30 Thread Jan Hubicka
> On Mon, Dec 30, 2013 at 10:14:16PM +0100, Jan Hubicka wrote: > > this is C version > > static int (*p) (int a) = (int (*)(int))__builtin_unreachable; > > main() > > { > > return p(1); > > } > > Well, that testcase is invalid, as you are calling the function (builtin) > through incompatible fun

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622)

2013-12-30 Thread Jakub Jelinek
On Mon, Dec 30, 2013 at 10:14:16PM +0100, Jan Hubicka wrote: > this is C version > static int (*p) (int a) = (int (*)(int))__builtin_unreachable; > main() > { > return p(1); > } Well, that testcase is invalid, as you are calling the function (builtin) through incompatible function pointer, so al

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622)

2013-12-30 Thread Jan Hubicka
Hi, this is C version static int (*p) (int a) = (int (*)(int))__builtin_unreachable; main() { return p(1); } Here we get in CCP: Folding statement: return _4; Not folded Folding statement: _4 = p.0_2 (1); Folded into: _4 = __builtin_unreachable (1); Removing dead stmt p.0_2 = __builtin_unreacha

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622)

2013-12-30 Thread Jan Hubicka
> > Yes. Also affecting other statements isn't allowed. > > >One would need to also unlink vdefs and release the vdef SSA_NAME, and > >not > >sure if fold_stmt_inplace callers would be even prepared for the stmt > >to > >become noreturn, and no longer throwing, etc. > > That I think they have t

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622)

2013-12-30 Thread Richard Biener
Jakub Jelinek wrote: >On Mon, Dec 30, 2013 at 05:56:04PM +0100, Richard Biener wrote: >> Jakub Jelinek wrote: >> >Setting gimple_call_set_fndecl of a random method call to >> >__bultin_unreachable can't work properly, the method call probably >> >passes in arguments that __builtin_unreachable doe

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622)

2013-12-30 Thread Jakub Jelinek
On Mon, Dec 30, 2013 at 05:56:04PM +0100, Richard Biener wrote: > Jakub Jelinek wrote: > >Setting gimple_call_set_fndecl of a random method call to > >__bultin_unreachable can't work properly, the method call probably > >passes in arguments that __builtin_unreachable doesn't expect, and if > >the

Re: [PATCH] Fix devirtualization ICE (PR tree-optimization/59622)

2013-12-30 Thread Richard Biener
Jakub Jelinek wrote: >Hi! > >Setting gimple_call_set_fndecl of a random method call to >__bultin_unreachable can't work properly, the method call probably >passes in arguments that __builtin_unreachable doesn't expect, and if >the method call has LHS, we'll ICE, because __builtin_unreachable >does

[PATCH] Fix devirtualization ICE (PR tree-optimization/59622)

2013-12-30 Thread Jakub Jelinek
Hi! Setting gimple_call_set_fndecl of a random method call to __bultin_unreachable can't work properly, the method call probably passes in arguments that __builtin_unreachable doesn't expect, and if the method call has LHS, we'll ICE, because __builtin_unreachable doesn't have a LHS. Fixed by not