]> git.ipfire.org Git - thirdparty/gcc.git/commit
Rewrite bool loads for undefined case [PR121279]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Fri, 15 Aug 2025 23:17:35 +0000 (16:17 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Mon, 25 Aug 2025 15:26:34 +0000 (08:26 -0700)
commit7269aa0765415df071778b92bd9ecea82f8ea5b2
tree8aadede5e026f494f54e61cc556f764543efc7da
parent2e1dfaad2ae7f11e1ea16f5f419d82d6cbd50c3d
Rewrite bool loads for undefined case [PR121279]

Just like r16-465-gf2bb7ffe84840d8 but this time
instead of a VCE there is a full on load from a boolean.
This showed up when trying to remove the extra copy
in the testcase from the revision mentioned above (pr120122-1.c).
So when moving loads from a boolean type from being conditional
to non-conditional, the load needs to become a full load and then
casted into a bool so that the upper bits are correct.

Bitfields loads will always do the truncation so they don't need to
be rewritten. Non boolean types always do the truncation too.

What we do is wrap the original reference with a VCE which causes
the full load and then do a casting to do the truncation. Using
fold_build1 with VCE will do the correct thing if there is a secondary
VCE and will also fold if this was just a plain MEM_REF so there is
no need to handle those 2 cases special either.

Changes since v1:
* v2: Use VIEW_CONVERT_EXPR instead of doing a manual load.
      Accept all non mode precision loads rather than just
      boolean ones.
* v3: Move back to checking boolean type. Don't handle BIT_FIELD_REF.
      Add asserts for IMAG/REAL_PART_EXPR.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/121279

gcc/ChangeLog:

* gimple-fold.cc (gimple_needing_rewrite_undefined): Return
true for non mode precision boolean loads.
(rewrite_to_defined_unconditional): Handle non mode precision loads.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/pr121279-1.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/gimple-fold.cc
gcc/testsuite/gcc.dg/torture/pr121279-1.c [new file with mode: 0644]