]> gcc.gnu.org Git - gcc.git/commit
Implement constant-folding simplifications of reductions.
authorRoger Sayle <roger@nextmovesoftware.com>
Tue, 22 Feb 2022 12:32:22 +0000 (12:32 +0000)
committerRoger Sayle <roger@nextmovesoftware.com>
Tue, 22 Feb 2022 12:32:22 +0000 (12:32 +0000)
commit2ef0e75d0bbc80bc06a0a39135e3564f907e39c8
tree1ceacdf57c7c09f000456ec8aa17f0669a7a71b8
parent2f59f067610f22c3f2ec9b1516e24b85836676ed
Implement constant-folding simplifications of reductions.

This patch addresses a code quality regression in GCC 12 by implementing
some constant folding/simplification transformations for REDUC_PLUS_EXPR
in match.pd.  The motivating example is gcc.dg/vect/pr89440.c which with
-O2 -ffast-math (with vectorization now enabled) gets optimized to:

float f (float x)
{
  vector(4) float vect_x_14.11;
  vector(4) float _2;
  float _32;

  _2 = {x_9(D), 0.0, 0.0, 0.0};
  vect_x_14.11_29 = _2 + { 1.0e+1, 2.6e+1, 4.2e+1, 5.8e+1 };
  _32 = .REDUC_PLUS (vect_x_14.11_29); [tail call]
  return _32;
}

With these proposed new transformations, we can simplify the
above code even further.

float f (float x)
{
  float _32;
  _32 = x_9(D) + 1.36e+2;
  return _32;
}

[which happens to match what we'd produce with -fno-tree-vectorize,
and with GCC 11].

2022-02-22  Roger Sayle  <roger@nextmovesoftware.com>
    Richard Biener  <rguenther@suse.de>

gcc/ChangeLog
* fold-const.cc (ctor_single_nonzero_element): New function to
return the single non-zero element of a (vector) constructor.
* fold-const.h (ctor_single_nonzero_element): Prototype here.
* match.pd (reduc (constructor@0)): Simplify reductions of a
constructor containing a single non-zero element.
(reduc (@0 op VECTOR_CST) ->  (reduc @0) op CONST): Simplify
reductions of vector operations of the same operator with
constant vector operands.

gcc/testsuite/ChangeLog
* gcc.dg/fold-reduc-1.c: New test case.
gcc/fold-const.cc
gcc/fold-const.h
gcc/match.pd
gcc/testsuite/gcc.dg/fold-reduc-1.c [new file with mode: 0644]
This page took 0.069846 seconds and 5 git commands to generate.