]> git.ipfire.org Git - thirdparty/gcc.git/commit
ifcombine field merge: stricten loads tests, swap compare to match
authorAlexandre Oliva <oliva@adacore.com>
Thu, 19 Dec 2024 01:16:58 +0000 (22:16 -0300)
committerAlexandre Oliva <oliva@gnu.org>
Thu, 19 Dec 2024 01:16:58 +0000 (22:16 -0300)
commit86d9951acb4ec6f6f47402abb1fe3f059beb3ddb
treeeb1e7969bb2aa6fd52ff57b494d5fc5bd9fa1f4b
parentcabc4793b3c88f47099597e6c5180f95894e93ef
ifcombine field merge: stricten loads tests, swap compare to match

ACATS-4 ca11d02 exposed an error in the logic for recognizing and
identifying the inner object in decode_field_ref: a view-converting
load, inserted in a previous successful field merging operation, was
recognized by gimple_convert_def_p within decode_field_reference, and
as a result we took its operand as the expression, and failed to take
note of the load location.

Without that load, we couldn't compare vuses, and then we ended up
inserting a wider load before relevant parts of the object were
initialized.

This patch makes gimple_convert_def_p recognize loads only when
requested, and requires that either both or neither parts of a
potentially merged operand have associated loads.

As a bonus, it enables additional optimizations by swapping the
operands of the second compare when that makes left-hand operands
of both compares match.

for  gcc/ChangeLog

* gimple-fold.cc (gimple_convert_def_p): Reject load stmts
unless requested.
(decode_field_reference): Accept a converting load at the last
conversion matcher, subsuming the load identification.
(fold_truth_andor_for_ifcombine): Refuse to merge operands
when only one of them has an associated load stmt.  Swap
operands of one of the compares if that helps them match.

for  gcc/testsuite/ChangeLog

* gcc.dg/field-merge-13.c: New.
gcc/gimple-fold.cc
gcc/testsuite/gcc.dg/field-merge-13.c [new file with mode: 0644]