Re: [PATCH 2/2] middle-end/126788 - more vector folding

"H.J. Lu" <[email protected]>
Newsgroups gmane.comp.gcc.patches
Message-ID <CAMe9rOr=N4LY_3o1HbT2PFyeaKwdYwW_2yc_AMCtNoJSijFDgA@mail.gmail.com>
On Fri, Aug 14, 2026 at 8:13 PM Richard Biener <[email protected]> wrote:
>
> The last match.pd update for double-conversion folding didn't handle
> the case where a vector conversion would go away because
> supportable_convert_operation doesn't consider a noop conversion
> (or a sign conversion).  The following rectifies this, allowing
> a NOP_EXPR and VIEW_CONVERT_EXPR for same mode types as supportable
> conversion as we can RTL expand that just fine.
>
> This shows that the vectorizer routed sign-conversions through
> vectorizable_assignment but now vectorizable_conversion would
> handle it, emitting NOP_EXPRs (which is fine) instead of
> VIEW_CONVERT_EXPRs (which we declared canonical for vectors).
> This would confuse some foldings, leading to testsuite FAILs,
> so make vectorizable_conversion also prefer VIEW_CONVERT_EXPRs
> here.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu.
>
> I'll wait on comments on 1/2 before pushing.
>
> Richard.
>
>         PR middle-end/126788
>         * optabs-tree.cc (supportable_convert_operation): For same
>         modes allow NOP_EXPR and VIEW_CONVERT_EXPR.
>         * tree-ssa-forwprop.cc (simplify_vector_constructor): Avoid
>         converting the vector to be used for blending into the
>         result to the type of the permutation.
>         * tree-vect-stmts.cc (vectorizable_conversion): Prefer
>         VIEW_CONVERT_EXPR for sign changes.
>
>         * gcc.target/i386/pr126788.c: New testcase.
> ---
>  gcc/optabs-tree.cc                       |  4 ++++
>  gcc/testsuite/gcc.target/i386/pr126788.c | 24 ++++++++++++++++++++++++
>  gcc/tree-ssa-forwprop.cc                 |  1 +
>  gcc/tree-vect-stmts.cc                   |  9 ++++++++-
>  4 files changed, 37 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr126788.c
>

It failed with this:

[hjl@gnu-zen4-1 gcc]$ cat /tmp/x.C
extern int _M_current;
extern int end ();
struct color
{
  char r;
  struct
  {
    unsigned char g;
    unsigned char b;
  } m_24bit;
  color (char g, char b)
  {
    m_24bit.g = g;
    m_24bit.b = b;
  }
};
void
set_style_bg_color (color)
{
  for (;;)
    {
      const unsigned char g = _M_current;
      if (end ())
break;
      set_style_bg_color (color (g, _M_current));
    }
}
[hjl@gnu-zen4-1 gcc]$ ./xgcc -B./ -S -O2 -march=x86-64-v4 /tmp/x.C
/tmp/x.C: In function ‘void set_style_bg_color(color)’:
/tmp/x.C:18:1: error: type mismatch between an SSA_NAME and its symbol
   18 | set_style_bg_color (color)
      | ^~~~~~~~~~~~~~~~~~
/tmp/x.C:18:1: error: type mismatch between an SSA_NAME and its symbol
while verifying SSA_NAME vect_g_49.10_100 in statement
vect_g_49.10_100 = (vector(2) unsigned char) _101;
during GIMPLE pass: slp
/tmp/x.C:18:1: internal compiler error: verify_ssa failed
0x4fa8116 internal_error(char const*, ...)
/export/gnu/import/git/gitlab/x86-gcc-test/gcc/diagnostic-global-context.cc:787
0x313c855 verify_ssa(bool, bool)
/export/gnu/import/git/gitlab/x86-gcc-test/gcc/tree-ssa.cc:1226
0x2c64811 execute_function_todo
/export/gnu/import/git/gitlab/x86-gcc-test/gcc/passes.cc:2107
0x2c6345a do_per_function
/export/gnu/import/git/gitlab/x86-gcc-test/gcc/passes.cc:1699
0x2c649a8 execute_todo
/export/gnu/import/git/gitlab/x86-gcc-test/gcc/passes.cc:2152
./cc1plus -quiet -iprefix
/export/build/gnu/tools-build/gcc-gitlab-test-debug/build-x86_64-linux/gcc/../lib/gcc/x86_64-pc-linux-gnu/17.0.0/
-isystem ./include -isystem ./include-fixed -D_GNU_SOURCE /tmp/x.C
-quiet -dumpbase x.C -dumpbase-ext .C -march=x86-64-v4
-mtls-dialect=gnu2 -O2 -o x.s
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
[hjl@gnu-zen4-1 gcc]$

-- 
H.J.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.