]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Use gimple_build to perform conversion simplification
authorRichard Biener <rguenther@suse.de>
Fri, 10 Oct 2025 08:05:46 +0000 (10:05 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 10 Oct 2025 09:25:02 +0000 (11:25 +0200)
The following uses gimple_build to do the conversion simplification
in build_and_insert_cast instead of duplicating it there.  Conveniently
when building directly into the IL all stmts are taken into account
for the simplification.

PR tree-optimization/122111
* tree-ssa-math-opts.cc (build_and_insert_cast): Remove
conversion simplification, instead use gimple_convert.

* gcc.target/arm/pr122111.c: New test.

gcc/testsuite/gcc.target/arm/pr122111.c [new file with mode: 0644]
gcc/tree-ssa-math-opts.cc

diff --git a/gcc/testsuite/gcc.target/arm/pr122111.c b/gcc/testsuite/gcc.target/arm/pr122111.c
new file mode 100644 (file)
index 0000000..82d15e9
--- /dev/null
@@ -0,0 +1,14 @@
+/* Test that we do not have ice when compile */
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+
+typedef long long wide;
+
+void g(void);
+wide f(int *a, unsigned t)
+{
+  wide i = t;
+  i *= 4;
+  unsigned long ai = (__SIZE_TYPE__)a;
+  return i + ai;
+}
index 0db39f330eadda3a34809e27923c13a47443d7fa..04c9f2c07e92717c361016c89905c6335ae0c6f8 100644 (file)
@@ -1631,43 +1631,7 @@ static tree
 build_and_insert_cast (gimple_stmt_iterator *gsi, location_t loc,
                       tree type, tree val)
 {
-  tree result = make_ssa_name (type);
-  tree rhs = val;
-
-  if (TREE_CODE (val) == SSA_NAME)
-    {
-      gimple *def = SSA_NAME_DEF_STMT (val);
-
-      if (is_gimple_assign (def)
-         && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def)))
-       {
-         tree cast_rhs = gimple_assign_rhs1 (def);
-         tree cast_rhs_type = TREE_TYPE (cast_rhs);
-         tree val_type = TREE_TYPE (val);
-
-         bool unsigned_p = TYPE_UNSIGNED (type);
-         bool unsigned_rhs_p = TYPE_UNSIGNED (cast_rhs_type);
-         bool unsigned_val_p = TYPE_UNSIGNED (val_type);
-
-         unsigned rhs_prec = TYPE_PRECISION (cast_rhs_type);
-         unsigned type_prec = TYPE_PRECISION (type);
-         unsigned val_prec = TYPE_PRECISION (val_type);
-
-         if (type_prec >= rhs_prec && val_prec >= rhs_prec)
-           {
-             /* Aka any sign extend from small to big size */
-             if (!((val_prec > rhs_prec && !unsigned_val_p && !unsigned_rhs_p)
-                 || (type_prec > val_prec && !unsigned_p && !unsigned_val_p)))
-               rhs = cast_rhs;
-           }
-       }
-    }
-
-  gassign *stmt = gimple_build_assign (result, NOP_EXPR, rhs);
-
-  gimple_set_location (stmt, loc);
-  gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
-  return result;
+  return gimple_convert (gsi, true, GSI_SAME_STMT, loc, type, val);
 }
 
 struct pow_synth_sqrt_info