Hi!

On Fri, Apr 22, 2022 at 10:53:30AM +0200, Richard Biener wrote:
> I was still unhappy with the previous patch and indeed, re-thinking
> all the special casing I put in there I found a hole with respect
> to externally throwing stmts which I totally forgot about and which
> might end up in must-not-throw regions after the previous patch.
> 
> Fortunately all of the complicated situations only arise with
> non-call exceptions and when there's a REG_EH_REGION note to
> distribute.  So first of all the new patch makes that explicit
> and does not affect the not non-call EH path (apart from the
> new assert in distribute_notes).  It also does not affect the
> non-call EH path when there is no REG_EH_REGION on any of the
> insns.
> 
> I resisted trying to be clever with lp_nr == 0 or INT_MIN
> (the nothrow notes that we could in theory just drop), but I
> put in an extra check in case we have a REG_EH_REGION note
> on an insn that cannot ever throw (and drop those at
> distribute_notes time).
> 
> The patch preserves the main part of the very original patch,
> that we only ever place the REG_EH_REGION on i3.  The
> split precondition should make sure that i2 never throws
> (but no assert since the trigger happy may_trap_p might
> be confused by some "optimization" done on the split part later).
> The hunk at the start of try_combine makes sure that we only
> have a single REG_EH_REGION note to distribute which ends up
> on i3 which accumulates all possibly throwing side-effects
> thanks to the split precondition.

Right, that is foolproof :-)

> +  bool nce_any_eh_region_note = false;

Name this "has_non_call_exception" please?

> +  /* With non-call exceptions we can end up trying to combine multiple
> +     stmts with possible EH side effects.  Make sure we can combine
> +     that to a single stmt which means there must be at most one insn
> +     in the combination with an EH side effect.  */

s/stmt/insn/g

Or, what else does "statement" mean here?

> +  if (cfun->can_throw_non_call_exceptions)
> +    {
> +      if (find_reg_note (i3, REG_EH_REGION, NULL_RTX)
> +       || find_reg_note (i2, REG_EH_REGION, NULL_RTX)
> +       || (i1 && find_reg_note (i1, REG_EH_REGION, NULL_RTX))
> +       || (i0 && find_reg_note (i0, REG_EH_REGION, NULL_RTX)))
> +     {
> +       nce_any_eh_region_note = true;
> +       if (insn_could_throw_p (i3)
> +           + insn_could_throw_p (i2)
> +           + (i1 ? insn_could_throw_p (i1) : 0)
> +           + (i0 ? insn_could_throw_p (i0) : 0) > 1)
> +         {
> +           if (dump_file && (dump_flags & TDF_DETAILS))
> +             fprintf (dump_file, "Can't combine multiple insns with EH "
> +                      "side-effects\n");
> +           undo_all ();
> +           return 0;
> +         }
> +     }
> +    }

Nice :-)

> +       /* We should not split a possibly trapping part when we
> +          care about non-call EH and have REG_EH_REGION notes
> +          to distribute.  */
> +       && (!cfun->can_throw_non_call_exceptions
> +           || !nce_any_eh_region_note
> +           || !may_trap_p (*split)))

I'm still not a fan of manual De Morgan, it is too easy to make a
mistake in it, or in reading it.  It is better as
          && (!(cfun->can_throw_non_call_exceptions
                && nce_any_eh_region_note
                && may_trap_p (*split))))
imo.  But, this kind of thing is not new of course, and combine is one
of the worst "complicated expressions are great!" offenders around ;-)

> +       {
> +         /* This handling needs to be kept in sync with the
> +            prerequisite checking in try_combine.  */
> +         int lp_nr = INTVAL (XEXP (note, 0));

Please spell out "landing pad", in the comment if not in the code.

> +         /* A REG_EH_REGION note transfering control can only ever come
> +            from i3.  */
> +         if (lp_nr > 0)
> +           gcc_assert (from_insn == i3);
> +         /* We are making sure there is a single effective REG_EH_REGION
> +            note and it's valid to put it on i3.  */
> +         if (!insn_could_throw_p (from_insn))
> +           /* Deal with stray notes on insns that can never throw.  */
> +           ;

"Throw away stray notes" etc.?

> +/* { dg-do compile } */
> +/* { dg-require-effective-target int32plus } */
> +/* { dg-require-effective-target dfp } */
> +/* { dg-additional-options "-fsanitize-coverage=trace-pc 
> -fnon-call-exceptions --param=max-cse-insns=1 -frounding-math" } */
> +/* { dg-additional-options "-mstack-arg-probe" { target x86_64-*-* i?86-*-* 
> } } */
> +
> +void baz (int *);
> +void bar (double, double, _Decimal64);
> +
> +void
> +foo (void)
> +{
> +  int s __attribute__((cleanup (baz)));
> +  bar (0xfffffffffffffffe, 0xebf3fff2fbebaf7f, 0xffffffffffffff);
> +}

Why the int32plus?  It needs 64-bit integers, and the size of "int"
does not matter at all afaics?  Maybe you want lp64?

Okay for trunk with the naming and comment stuff looked at.  Thank you!


Segher

Reply via email to