[2/2] Fix bogus inner induction (PR 86725)
authorRichard Sandiford <richard.sandiford@arm.com>
Wed, 22 Aug 2018 13:02:48 +0000 (13:02 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Wed, 22 Aug 2018 13:02:48 +0000 (13:02 +0000)
commit18bc19a7aa4cd08d45d64f6741b8b1e0f48f262b
treec8db399ae2a4f3b3e183377ac39f13adc902cb03
parent3a4da26602da1bd30c4ff2793fed480f180248c1
[2/2] Fix bogus inner induction (PR 86725)

This patch is the second part of the fix for PR 86725.  The problem
in the original test is that for:

  outer1:
    x_1 = PHI <x_4(outer2), ...>;
    ...

  inner:
    x_2 = PHI <x_1(outer1), x_3(...)>;
    ...
    x_3 = ...;
    ...

  outer2:
    x_4 = PHI <x_3(inner)>;
    ...

there are corner cases in which it is possible to classify the
inner phi as an induction but not the outer phi.  The -4.c test
is a more direct example.

After failing to classify x_1 as an induction, we go on to
classify it as a double reduction (which is basically true).
But we still classified the inner phi as an induction rather
than as part of a reduction, leading to an ICE when trying
to vectorise the outer phi.

We analyse the phis for outer loops first, so the simplest
fix is not to classify the phi as an induction if outer loop
analysis said that it should be a reduction.

The -2.c test is from the original PR.  The -3.c test is a
version in which "wo" really is used a reduction; this was
already correctly rejected, but for the wrong reason ("inner-loop
induction only used outside of the outer vectorized loop").
The -4.c test is another way of tickling the original problem
without relying on the undefinedness of signed overflow.
The -5.c test shows an (uninteresting) example in which the
patch prevents a spurious failure to vectorise the outer loop.

2018-08-22  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
PR tree-optimization/86725
* tree-vect-loop.c (vect_inner_phi_in_double_reduction_p): New
function.
(vect_analyze_scalar_cycles_1): Check it.

gcc/testsuite/
PR tree-optimization/86725
* gcc.dg/vect/no-scevccp-pr86725-2.c: New test.
* gcc.dg/vect/no-scevccp-pr86725-3.c: Likewise.
* gcc.dg/vect/no-scevccp-pr86725-4.c: Likewise.
* gcc.dg/vect/no-scevccp-pr86725-5.c: Likewise.

From-SVN: r263774
gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-5.c [new file with mode: 0644]
gcc/tree-vect-loop.c