]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
crc: Fix up ICE from optimize_crc_loop [PR120677]
authorJakub Jelinek <jakub@redhat.com>
Tue, 17 Jun 2025 11:20:11 +0000 (13:20 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 17 Jun 2025 11:20:11 +0000 (13:20 +0200)
The following testcase ICEs, because optimize_crc_loop inserts a call
statement before labels instead of after labels.

Fixed thusly (plus fixed other issues noticed around it).

2025-06-17  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/120677
* gimple-crc-optimization.cc (crc_optimization::optimize_crc_loop):
Insert before gsi_after_labels instead of gsi_start_bb.  Use
gimple_bb (output_crc) instead of output_crc->bb.  Formatting fix.

* gcc.c-torture/execute/pr120677.c: New test.

gcc/gimple-crc-optimization.cc
gcc/testsuite/gcc.c-torture/execute/pr120677.c [new file with mode: 0644]

index a98cbe6752b56f104bd8717e2498a0dc4c1eb5f3..1751be9bc97f1870f005d7459595e913b091fef4 100644 (file)
@@ -1261,15 +1261,12 @@ crc_optimization::optimize_crc_loop (gphi *output_crc)
   loc = EXPR_LOCATION (phi_result);
 
   /* Add IFN call and write the return value in the phi_result.  */
-  gcall *call
-      = gimple_build_call_internal (ifn, 3,
-                                   m_crc_arg,
-                                   m_data_arg,
-                                   polynomial_arg);
+  gcall *call = gimple_build_call_internal (ifn, 3, m_crc_arg, m_data_arg,
+                                           polynomial_arg);
 
   gimple_call_set_lhs (call, phi_result);
   gimple_set_location (call, loc);
-  gimple_stmt_iterator si = gsi_start_bb (output_crc->bb);
+  gimple_stmt_iterator si = gsi_after_labels (gimple_bb (output_crc));
   gsi_insert_before (&si, call, GSI_SAME_STMT);
 
   /* Remove phi statement, which was holding CRC result.  */
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr120677.c b/gcc/testsuite/gcc.c-torture/execute/pr120677.c
new file mode 100644 (file)
index 0000000..3cff04e
--- /dev/null
@@ -0,0 +1,31 @@
+/* PR tree-optimization/120677 */
+/* { dg-do run { target int32plus } } */
+
+unsigned a;
+int b, e;
+
+int
+foo (int d)
+{
+  switch (d)
+    {
+    case 0:
+    case 2:
+      return 0;
+    default:
+      return 1;
+    }
+}
+
+int
+main ()
+{
+  for (b = 8; b; b--)
+    if (a & 1)
+      a = a >> 1 ^ 20000000;
+    else
+      a >>= 1;
+  e = foo (0);
+  if (e || a)
+    __builtin_abort ();
+}