]> git.ipfire.org Git - thirdparty/gcc.git/commit
tree-ssa-math-opts: Fix ICE if vectorizer produces IFN_SIN/COS calls master trunk
authorArsen Arsenović <aarsenovic@baylibre.com>
Fri, 19 Dec 2025 10:33:05 +0000 (10:33 +0000)
committerArsen Arsenović <arsen@gcc.gnu.org>
Thu, 25 Dec 2025 08:48:08 +0000 (09:48 +0100)
commitbce3ac1019c52c92ff39b4bf963c58fb7e8c4479
treed37995774b583a294a259877281f73c557105bb1
parentc3824ad07a3032a48f2776a7536565877c9f95c7
tree-ssa-math-opts: Fix ICE if vectorizer produces IFN_SIN/COS calls

With the following testcase, on AMDGCN with -Ofast:

  void
  foo (float* output, float* input)
  {
      for (int i = 0; i < 1024 * 1024; i++) {
          output[i] = __builtin_sinf (input[i]) + __builtin_cosf (input[i]);
      }
  }

... the following ICE happens:

  during GIMPLE pass: sincos
  test.cpp: In function 'void foo(float*, float*)':
  test.cpp:2:1: internal compiler error: Segmentation fault
      2 | foo (float* output, float* input)
        | ^~~
  [... snipped ...]
  0x17befb8 types_compatible_p(tree_node*, tree_node*)
          gcc/gimple-expr.h:67
  0x17befb8 execute_cse_sincos_1
          gcc/tree-ssa-math-opts.cc:1299
  0x17befb8 execute
          gcc/tree-ssa-math-opts.cc:2248

This happens because the vect pass converted the testcase into:

  vect__4.6_40 = MEM <vector(64) float> [(float *)vectp_input.4_38];
  vect__6.8_42 = .COS (vect__4.6_40);
  vect__5.7_41 = .SIN (vect__4.6_40);
  vect__8.9_43 = vect__5.7_41 + vect__6.8_42;

Then, sincos attempts to find the type of the IFN_SIN/IFN_COS via
mathfn_built_in_type.  This fails, so the compiler crashes.

For these IFNs, their input type is the same as their output type, so
we can fall back to that.

Note that, currently, GCC can't seem to handle vector sincos/cexpi
operations, so any attempt to CSE these will fail quickly after.  This
patch does not fix that, only the ICE that happens in the attempt.

gcc/ChangeLog:

* tree-ssa-math-opts.cc (execute_cse_sincos_1): If
mathfn_built_in_type fails to determine a type for our
operation, presume that it is the same as the input type.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/sincos-ice-on-ifn_sin-call.c: New test.
* gcc.target/gcn/sincos-ice-on-ifn_sin-call-1.c: New test.
gcc/testsuite/gcc.dg/tree-ssa/sincos-ice-on-ifn_sin-call.c [new file with mode: 0644]
gcc/testsuite/gcc.target/gcn/sincos-ice-on-ifn_sin-call-1.c [new file with mode: 0644]
gcc/tree-ssa-math-opts.cc