Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-20 Thread Jeff Law
On 5/14/19 4:57 PM, Jakub Jelinek wrote: > On Tue, May 14, 2019 at 01:08:27PM -0600, Jeff Law wrote: >>> In https://gcc.gnu.org/ml/gcc-patches/2019-05/msg00484.html I've posted a >>> patch that would set it earlier (or it could be set during gimplification >>> and propagated during inlining, would

Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-20 Thread Iain Sandoe
Hi Jakub, all, > On 14 May 2019, at 23:57, Jakub Jelinek wrote: > > On Tue, May 14, 2019 at 01:08:27PM -0600, Jeff Law wrote: >>> In https://gcc.gnu.org/ml/gcc-patches/2019-05/msg00484.html I've posted a >>> patch that would set it earlier (or it could be set during gimplification >>> and

Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-14 Thread Jakub Jelinek
On Tue, May 14, 2019 at 01:08:27PM -0600, Jeff Law wrote: > > In https://gcc.gnu.org/ml/gcc-patches/2019-05/msg00484.html I've posted a > > patch that would set it earlier (or it could be set during gimplification > > and propagated during inlining, would need to be in cfun->calls_eh_return > >

Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-14 Thread Jeff Law
On 5/13/19 4:51 PM, Jakub Jelinek wrote: > On Mon, May 13, 2019 at 04:29:21PM -0600, Jeff Law wrote: >>> That is a serious misunderstanding of what __builtin_eh_return does. >>> For the most part, __builtin_eh_return works by forcing all call clobbered >>> registers to stack, having that described

Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-14 Thread Michael Matz
Hi, On Tue, 14 May 2019, Jakub Jelinek wrote: > In https://gcc.gnu.org/ml/gcc-patches/2019-05/msg00484.html I've posted > a patch that would set it earlier (or it could be set during > gimplification and propagated during inlining, would need to be in > cfun->calls_eh_return instead of

Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-13 Thread Jakub Jelinek
On Mon, May 13, 2019 at 04:29:21PM -0600, Jeff Law wrote: > > That is a serious misunderstanding of what __builtin_eh_return does. > > For the most part, __builtin_eh_return works by forcing all call clobbered > > registers to stack, having that described in the unwind info and having the > >

Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-13 Thread Jeff Law
On 5/13/19 2:09 PM, Jakub Jelinek wrote: > On Mon, May 13, 2019 at 07:57:30PM +, Wilco Dijkstra wrote: >> Hi, >> >>> I think my worry would be all the targets that support tail calls, but >>> which we can't easily test.   ie, we put in the hack, but when do we >>> know it can be removed? >> >>

Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-13 Thread Wilco Dijkstra
Hi Jakub, >> We could simpify __builtin_eh_return and implement it as a libgcc >> function or automatically generated thunk. Basically all you need is >> tailcall a 2-instruction helper which adjusts the stack and then jumps >> to the given function pointer. This way you don't need the complex

Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-13 Thread Jakub Jelinek
On Mon, May 13, 2019 at 07:57:30PM +, Wilco Dijkstra wrote: > Hi, > > > I think my worry would be all the targets that support tail calls, but > > which we can't easily test.   ie, we put in the hack, but when do we > > know it can be removed? > > Well it would be easy to make a runnable

Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-13 Thread Wilco Dijkstra
Hi, > I think my worry would be all the targets that support tail calls, but > which we can't easily test.   ie, we put in the hack, but when do we > know it can be removed? Well it would be easy to make a runnable torture test. I'm not sure how easy it would be to do it using a scan-assembler

Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-13 Thread Iain Sandoe
> On 13 May 2019, at 20:10, Jakub Jelinek wrote: > > On Mon, May 13, 2019 at 12:52:54PM -0600, Jeff Law wrote: >> On 5/10/19 9:17 AM, Jakub Jelinek wrote: >>> On Fri, May 10, 2019 at 01:46:07PM +, Wilco Dijkstra wrote: And looking at the generated code, emitting a tailcall for this

Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-13 Thread Jakub Jelinek
On Mon, May 13, 2019 at 12:52:54PM -0600, Jeff Law wrote: > On 5/10/19 9:17 AM, Jakub Jelinek wrote: > > On Fri, May 10, 2019 at 01:46:07PM +, Wilco Dijkstra wrote: > >> And looking at the generated code, emitting a tailcall for this case is > >> actually a > >> de-optimization since the

Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-13 Thread Jeff Law
On 5/10/19 9:17 AM, Jakub Jelinek wrote: > On Fri, May 10, 2019 at 01:46:07PM +, Wilco Dijkstra wrote: >> And looking at the generated code, emitting a tailcall for this case is >> actually a >> de-optimization since the large eh_return epilog must be repeated for every >> tailcall. > > On

Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-11 Thread Segher Boessenkool
On Sat, May 11, 2019 at 09:38:22AM +0100, Richard Sandiford wrote: > Jakub Jelinek writes: > > Previously, the mere existence of the addressable variables this_context > > and cur_context prevented tail call on the early out > > return _Unwind_RaiseException (exc); > > but since r271013 the

Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-11 Thread Richard Sandiford
Jakub Jelinek writes: > Hi! > > My recent patch for tail call improvement apparently affects also the > _Unwind_Resume_or_Rethrow function in libgcc: > > _Unwind_Reason_Code __attribute__((optimize ("no-omit-frame-pointer"))) > _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *exc) > { >

Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-10 Thread Jakub Jelinek
On Fri, May 10, 2019 at 01:46:07PM +, Wilco Dijkstra wrote: > And looking at the generated code, emitting a tailcall for this case is > actually a > de-optimization since the large eh_return epilog must be repeated for every > tailcall. On x86_64, the code is shorter with the tail call

Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-10 Thread Wilco Dijkstra
Hi Jakub, >> That's great to hear, but all the other targets still need to be fixed >> somehow. > > Not all other targets, just some.  I don't see what you find wrong on > actually fixing them.  The tail call in that spot is actually very > desirable, but only if we can do a shrink wrapping for

Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-10 Thread Jakub Jelinek
On Fri, May 10, 2019 at 01:46:07PM +, Wilco Dijkstra wrote: > > So given this and the fact there is no real gain from emitting tailcalls in > > eh_return > > functions, wouldn't it make more sense to always block tailcalls in the > > mid-end? > > > No.  E.g. x86 handles that just fine, >

Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-10 Thread Wilco Dijkstra
Hi Jakub, > So given this and the fact there is no real gain from emitting tailcalls in > eh_return > functions, wouldn't it make more sense to always block tailcalls in the > mid-end? > No.  E.g. x86 handles that just fine, That's great to hear, but all the other targets still need to be

Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-10 Thread Jakub Jelinek
On Fri, May 10, 2019 at 11:38:50AM +, Wilco Dijkstra wrote: > > __builtin_eh_return is a noreturn call, and we never tail call optimize > > noreturn calls: > >  if (flags & ECF_NORETURN) > >    { > >  maybe_complain_about_tail_call (exp, "callee does not return"); > >  return false; >

Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-10 Thread Wilco Dijkstra
Hi Jakub, > __builtin_eh_return is a noreturn call, and we never tail call optimize > noreturn calls: >  if (flags & ECF_NORETURN) >    { >  maybe_complain_about_tail_call (exp, "callee does not return"); >  return false; >    } > As both the __builtin_eh_return and other tail calls are

Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-10 Thread Jakub Jelinek
On Fri, May 10, 2019 at 10:25:58AM +, Wilco Dijkstra wrote: > Hi Jakub, > > 27ec: 912143ffadd sp, sp, #0x850 > 27f0: 8b2463ffadd sp, sp, x4 > 27f4: 1400b 23c8 <_Unwind_RaiseException> > > > This does a lot of register

Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-10 Thread Wilco Dijkstra
Hi Jakub, 27ec: 912143ffadd sp, sp, #0x850 27f0: 8b2463ffadd sp, sp, x4 27f4: 1400b 23c8 <_Unwind_RaiseException> > This does a lot of register saving and restoring, which is not needed but is > not wrong-code (guess

[PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-10 Thread Jakub Jelinek
Hi! My recent patch for tail call improvement apparently affects also the _Unwind_Resume_or_Rethrow function in libgcc: _Unwind_Reason_Code __attribute__((optimize ("no-omit-frame-pointer"))) _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *exc) { struct _Unwind_Context this_context,