]> git.ipfire.org Git - thirdparty/gcc.git/commit
Widening-Mul: Fix one bug of consume after phi node released
authorPan Li <pan2.li@intel.com>
Tue, 8 Oct 2024 03:06:23 +0000 (11:06 +0800)
committerPan Li <pan2.li@intel.com>
Tue, 8 Oct 2024 14:24:21 +0000 (22:24 +0800)
commit2291739ec432abc01c7afc5a07443c575539316a
tree8883a2e18f61c980de0c79bbb79e4fec6df78766
parentf9f57df85a5411dce201165a42f4b9d57489bed9
Widening-Mul: Fix one bug of consume after phi node released

When try to matching saturation related pattern on PHI node, we may have
to try each pattern for all phi node of bb.  Aka:

for each PHI node in bb:
  gphi *phi = xxx;
  try_match_sat_add (, phi);
  try_match_sat_sub (, phi);
  try_match_sat_trunc (, phi);

The PHI node will be removed if one of the above 3 sat patterns are
matched.  There will be a problem that, for example, sat_add is
matched and then the phi is removed(freed), and the next 2 sat_sub and
sat_trunc will depend on the removed(freed) phi node.

This patch would like to fix this consume after phi node released issue.
To ensure at most one pattern of the above will be matched.

The below test suites are passed for this patch.
* The rv64gcv fully regression test.
* The x86 bootstrap test.
* The x86 fully regression test.

gcc/ChangeLog:

* tree-ssa-math-opts.cc (build_saturation_binary_arith_call): Rename
to...
(build_saturation_binary_arith_call_and_replace): ...this.
(build_saturation_binary_arith_call_and_insert): ...this.
(match_unsigned_saturation_add): Leverage renamed func.
(match_unsigned_saturation_sub): Ditto.
(match_saturation_add): Return bool on matched and leverage
renamed func.
(match_saturation_sub): Ditto.
(match_saturation_trunc): Ditto.
(math_opts_dom_walker::after_dom_children): Ensure at most one
pattern will be matched for each phi node.

Signed-off-by: Pan Li <pan2.li@intel.com>
gcc/tree-ssa-math-opts.cc