rtl-optimization/105231 - distribute_notes and REG_EH_REGION
authorRichard Biener <rguenther@suse.de>
Thu, 14 Apr 2022 12:06:22 +0000 (14:06 +0200)
committerRichard Biener <rguenther@suse.de>
Mon, 25 Apr 2022 07:25:33 +0000 (09:25 +0200)
commit4f77738c3b44cb6b7bfe2a7ef823a5d9d75c0e79
treeade51b6bef8f3501aa2b7e14fd056f0d205697bd
parent3c940d42701707559fabe49be99296f60fbc43e7
rtl-optimization/105231 - distribute_notes and REG_EH_REGION

The following mitigates a problem in combine distribute_notes which
places an original REG_EH_REGION based on only may_trap_p which is
good to test whether a non-call insn can possibly throw but not if
actually it does or we care.  That's something we decided at RTL
expansion time where we possibly still know the insn evaluates
to a constant.

In fact, the REG_EH_REGION note with lp > 0 can only come from the
original i3 and an assert is added to that effect.  That means we only
need to retain the note on i3 or, if that cannot trap, drop it but we
should never move it to i2.

The following places constraints on the insns to combine with
non-call exceptions since we cannot handle the case where we
have more than one EH side-effect in the IL.  The patch also
makes sure we can accumulate that on i3 and do not split
a possible exception raising part of it to i2.  As a special
case we do not place any restriction on all externally
throwing insns when there is no REG_EH_REGION present.

2022-04-22  Richard Biener  <rguenther@suse.de>

PR rtl-optimization/105231
* combine.cc (distribute_notes): Assert that a REG_EH_REGION
with landing pad > 0 is from i3.  Put any REG_EH_REGION note
on i3 or drop it if the insn can not trap.
(try_combine): Ensure that we can merge REG_EH_REGION notes
with non-call exceptions.  Ensure we are not splitting a
trapping part of an insn with non-call exceptions when there
is any REG_EH_REGION note to preserve.

* gcc.dg/torture/pr105231.c: New testcase.
gcc/combine.cc
gcc/testsuite/gcc.dg/torture/pr105231.c [new file with mode: 0644]