]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
phiopt: Use rewrite_to_defined_overflow in move_stmt [PR116938]
authorAndrew Pinski <quic_apinski@quicinc.com>
Thu, 17 Oct 2024 05:30:10 +0000 (05:30 +0000)
committerAndrew Pinski <quic_apinski@quicinc.com>
Thu, 8 May 2025 07:24:47 +0000 (07:24 +0000)
As mentioned previously the rewrite in move_stmt should be
using gimple_needing_rewrite_undefined/rewrite_to_defined_unconditional
instead of just rewriting the VCE.
This moves move_stmt over to those APIs.

A few testcases needed to be updated due to ABS_EXPR rewrite that happens.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/116938

gcc/ChangeLog:

* tree-ssa-phiopt.cc (move_stmt): Use rewrite_to_defined_overflow
isntead of manually doing the rewrite of the VCE.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/phi-opt-40.c: Update to expect ABSU_EXPR.
* gcc.dg/tree-ssa/phi-opt-41.c: Likewise.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
gcc/testsuite/gcc.dg/tree-ssa/phi-opt-40.c
gcc/testsuite/gcc.dg/tree-ssa/phi-opt-41.c
gcc/tree-ssa-phiopt.cc

index a9011ce97fb1e5c4264c840eb7440bf45ab3f125..70629165bb61d212d02910e76eb9d7b07d29a5fa 100644 (file)
@@ -20,6 +20,7 @@ int f1(int x)
 
 /* { dg-final { scan-tree-dump-times "if " 1 "phiopt1" } } */
 /* { dg-final { scan-tree-dump-not "if " "phiopt2" } } */
-/* { dg-final { scan-tree-dump-times "ABS_EXPR <" 2 "phiopt1" } } */
-/* { dg-final { scan-tree-dump-times "ABS_EXPR <" 1 "phiopt2" } } */
-/* { dg-final { scan-tree-dump-times "ABSU_EXPR <" 1 "phiopt2" } } */
+/* The ABS_EXPR in f gets rewritten to ABSU_EXPR as phiopt can't prove it was not undefined when moving it. */
+/* { dg-final { scan-tree-dump-times "ABS_EXPR <" 1 "phiopt1" } } */
+/* { dg-final { scan-tree-dump-times "ABSU_EXPR <" 1 "phiopt1" } } */
+/* { dg-final { scan-tree-dump-times "ABSU_EXPR <" 2 "phiopt2" } } */
index 9774e283a7baced763ca3e688b0636d17f19dec7..817d4feb027958d6fe108e14e7218e0e05aa156d 100644 (file)
@@ -29,6 +29,6 @@ int fge(int a, unsigned char b)
   return a > 0 ? a : -a;
 }
 
-
+/* The ABS_EXPR gets rewritten to ABSU_EXPR as phiopt can't prove it was not undefined when moving it. */
 /* { dg-final { scan-tree-dump-not "if " "phiopt1" } } */
-/* { dg-final { scan-tree-dump-times "ABS_EXPR <" 4 "phiopt1" } } */
+/* { dg-final { scan-tree-dump-times "ABSU_EXPR <" 4 "phiopt1" } } */
index 54ecd93495a55001727c1765d9a393bb85c2e197..efd43d2d77e74dbe714a8739d72d9be1f19be585 100644 (file)
@@ -838,33 +838,13 @@ move_stmt (gimple *stmt, gimple_stmt_iterator *gsi, auto_bitmap &inserted_exprs)
   // Mark the name to be renamed if there is one.
   bitmap_set_bit (inserted_exprs, SSA_NAME_VERSION (name));
   gimple_stmt_iterator gsi1 = gsi_for_stmt (stmt);
-  gsi_move_before (&gsi1, gsi);
+  gsi_move_before (&gsi1, gsi, GSI_NEW_STMT);
   reset_flow_sensitive_info (name);
 
   /* Rewrite some code which might be undefined when
      unconditionalized. */
-  if (gimple_assign_single_p (stmt))
-    {
-      tree rhs = gimple_assign_rhs1 (stmt);
-      /* VCE from integral types to another integral types but with
-        different precisions need to be changed into casts
-        to be well defined when unconditional. */
-      if (gimple_assign_rhs_code (stmt) == VIEW_CONVERT_EXPR
-         && INTEGRAL_TYPE_P (TREE_TYPE (name))
-         && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (rhs, 0))))
-       {
-         if (dump_file && (dump_flags & TDF_DETAILS))
-           {
-             fprintf (dump_file, "rewriting stmt with maybe undefined VCE ");
-             print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
-           }
-         tree new_rhs = TREE_OPERAND (rhs, 0);
-         gcc_assert (is_gimple_val (new_rhs));
-         gimple_assign_set_rhs_code (stmt, NOP_EXPR);
-         gimple_assign_set_rhs1 (stmt, new_rhs);
-         update_stmt (stmt);
-       }
-    }
+  if (gimple_needing_rewrite_undefined (stmt))
+    rewrite_to_defined_unconditional (gsi);
 }
 
 /* RAII style class to temporarily remove flow sensitive