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.
Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
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 | 14 +++++++++
gcc/tree-ssa-math-opts.cc | 38 +------------------------
2 files changed, 15 insertions(+), 37 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/arm/pr122111.c
diff --git a/gcc/testsuite/gcc.target/arm/pr122111.c
b/gcc/testsuite/gcc.target/arm/pr122111.c
new file mode 100644
index 00000000000..82d15e9a43b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/pr122111.c
@@ -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;
+}
diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc
index 0db39f330ea..04c9f2c07e9 100644
--- a/gcc/tree-ssa-math-opts.cc
+++ b/gcc/tree-ssa-math-opts.cc
@@ -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
--
2.51.0