]> git.ipfire.org Git - thirdparty/gcc.git/commit
if-conv: Apply VN to hoisted conversions
authorRichard Sandiford <richard.sandiford@arm.com>
Tue, 30 Nov 2021 09:52:29 +0000 (09:52 +0000)
committerRichard Sandiford <richard.sandiford@arm.com>
Tue, 30 Nov 2021 09:52:29 +0000 (09:52 +0000)
commit32ede1083fad4b68873bec3e5a775e2092d6566e
tree5bb00283ab0e8633020e602716bd7171db7bc601
parent10833849b55401a52f2334eb032a70beb688e9fc
if-conv: Apply VN to hoisted conversions

This patch is a prerequisite for a later one.  At the moment,
if-conversion converts predicated POINTER_PLUS_EXPRs into
non-wrapping forms, which for:

    … = base + offset

becomes:

    tmp = (unsigned long) base
    … = tmp + offset

It then hoists these conversions out of the loop where possible.

However, because “base” is a valid gimple operand, there can be
multiple POINTER_PLUS_EXPRs with the same base, which can in turn
lead to multiple instances of the same conversion.  The later VN pass
is (and I think needs to be) restricted to the new if-converted code,
whereas here we're deliberately inserting the conversions before the
.LOOP_VECTORIZED condition:

/* If we versioned loop then make sure to insert invariant
   stmts before the .LOOP_VECTORIZED check since the vectorizer
   will re-use that for things like runtime alias versioning
   whose condition can end up using those invariants.  */

We can therefore enter the vectoriser with redundant conversions.

The easiest fix seemed to be to defer the hoisting until after VN.
This catches other hoisting opportunities too.

Hoisting the code from the (artificial) loop in pr99102.c means
that it's no longer worth vectorising.  The patch forces vectorisation
instead of relying on the cost model.

The patch also reverts pr87007-4.c and pr87007-5.c back to their
original forms, undoing changes in 783dc66f9ccb0019c3dad.
The code at the time the tests were added was:

        testl   %edi, %edi
        je      .L10
        vxorps  %xmm1, %xmm1, %xmm1
        vsqrtsd d3(%rip), %xmm1, %xmm0
        vsqrtsd d2(%rip), %xmm1, %xmm1
...
.L10:
        ret

with the operations being hoisted, and the vxorps was specifically
wanted (compared to the previous code).  This patch restores the code
to that form, with the hoisted operations and the vxorps.

gcc/
* tree-if-conv.c: Include tree-eh.h.
(predicate_statements): Remove pe argument.  Don't hoist
statements here.
(combine_blocks): Remove pe argument.
(ifcvt_available_on_edge_p, ifcvt_can_hoist): New functions.
(ifcvt_hoist_invariants): Likewise.
(tree_if_conversion): Update call to combine_blocks.  Call
ifcvt_hoist_invariants after VN.

gcc/testsuite/
* gcc.dg/vect/pr99102.c: Add -fno-vect-cost-model.

Revert:
2020-09-09  Richard Biener  [rguenther@suse.de]

* gcc.target/i386/pr87007-4.c: Adjust.
* gcc.target/i386/pr87007-5.c: Likewise.
gcc/testsuite/gcc.dg/vect/pr99102.c
gcc/testsuite/gcc.target/i386/pr87007-4.c
gcc/testsuite/gcc.target/i386/pr87007-5.c
gcc/tree-if-conv.c