This guards shift builtin folding to do nothing when there is
no LHS, similar to what other foldings do.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed as obvious.

2022-02-09  Richard Biener  <rguent...@suse.de>

        PR target/104453
        * config/i386/i386.cc (ix86_gimple_fold_builtin): Guard shift
        folding for NULL LHS.

        * gcc.target/i386/pr104453.c: New testcase.
---
 gcc/config/i386/i386.cc                  |  2 ++
 gcc/testsuite/gcc.target/i386/pr104453.c | 11 +++++++++++
 2 files changed, 13 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr104453.c

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index dd5584fb8ed..448c079c7ac 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -18642,6 +18642,8 @@ ix86_gimple_fold_builtin (gimple_stmt_iterator *gsi)
 
     do_shift:
       gcc_assert (n_args >= 2);
+      if (!gimple_call_lhs (stmt))
+       break;
       arg0 = gimple_call_arg (stmt, 0);
       arg1 = gimple_call_arg (stmt, 1);
       elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0));
diff --git a/gcc/testsuite/gcc.target/i386/pr104453.c 
b/gcc/testsuite/gcc.target/i386/pr104453.c
new file mode 100644
index 00000000000..325cedf0e2c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr104453.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-mavx512f" } */
+
+typedef short __attribute__((__vector_size__ (32))) V;
+V g;
+
+void
+foo (void)
+{
+  __builtin_ia32_psrawi256 (g, 0);
+}
-- 
2.34.1

Reply via email to