Fix ICE when lhs is NULL.
authorliuhongt <hongtao.liu@intel.com>
Thu, 20 May 2021 01:59:36 +0000 (09:59 +0800)
committerliuhongt <hongtao.liu@intel.com>
Mon, 24 May 2021 01:21:21 +0000 (09:21 +0800)
gcc/ChangeLog:
PR target/100660
* config/i386/i386.c (ix86_gimple_fold_builtin): Replacing
stmt with GIMPLE_NOP when lhs doesn't exist.

gcc/testsuite/ChangeLog:
PR target/100660
* gcc.target/i386/pr100660.c: New test.

gcc/config/i386/i386.c
gcc/testsuite/gcc.target/i386/pr100660.c [new file with mode: 0644]

index f3b4518..28e6113 100644 (file)
@@ -17991,21 +17991,24 @@ ix86_gimple_fold_builtin (gimple_stmt_iterator *gsi)
       gcc_assert (n_args == 2);
       arg0 = gimple_call_arg (stmt, 0);
       arg1 = gimple_call_arg (stmt, 1);
-      {
-       location_t loc = gimple_location (stmt);
-       tree type = TREE_TYPE (arg0);
-       tree zero_vec = build_zero_cst (type);
-       tree minus_one_vec = build_minus_one_cst (type);
-       tree cmp_type = truth_type_for (type);
-       gimple_seq stmts = NULL;
-       tree cmp = gimple_build (&stmts, tcode, cmp_type, arg0, arg1);
-       gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
-       gimple* g = gimple_build_assign (gimple_call_lhs (stmt),
-                                        VEC_COND_EXPR, cmp,
-                                        minus_one_vec, zero_vec);
-       gimple_set_location (g, loc);
-       gsi_replace (gsi, g, false);
-      }
+      if (gimple_call_lhs (stmt))
+       {
+         location_t loc = gimple_location (stmt);
+         tree type = TREE_TYPE (arg0);
+         tree zero_vec = build_zero_cst (type);
+         tree minus_one_vec = build_minus_one_cst (type);
+         tree cmp_type = truth_type_for (type);
+         gimple_seq stmts = NULL;
+         tree cmp = gimple_build (&stmts, tcode, cmp_type, arg0, arg1);
+         gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
+         gimple* g = gimple_build_assign (gimple_call_lhs (stmt),
+                                          VEC_COND_EXPR, cmp,
+                                          minus_one_vec, zero_vec);
+         gimple_set_location (g, loc);
+         gsi_replace (gsi, g, false);
+       }
+      else
+       gsi_replace (gsi, gimple_build_nop (), false);
       return true;
 
     case IX86_BUILTIN_PSLLD:
diff --git a/gcc/testsuite/gcc.target/i386/pr100660.c b/gcc/testsuite/gcc.target/i386/pr100660.c
new file mode 100644 (file)
index 0000000..1112b74
--- /dev/null
@@ -0,0 +1,10 @@
+/* PR target/pr100660.  */
+/* { dg-do compile } */
+/* { dg-options "-mavx2 -O" } */
+
+typedef char v16qi __attribute__ ((vector_size (16)));
+v16qi
+f5 (v16qi a, v16qi b)
+{
+  __builtin_ia32_pcmpgtb128 (a, b);
+}