https://gcc.gnu.org/g:e520fe08031a4f16e5a7933b4a5fada00413fc6c
commit r16-4356-ge520fe08031a4f16e5a7933b4a5fada00413fc6c Author: Richard Biener <[email protected]> Date: Fri Oct 10 10:05:46 2025 +0200 Use gimple_build to perform conversion simplification 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. Diff: --- gcc/testsuite/gcc.target/arm/pr122111.c | 14 ++++++++++++ gcc/tree-ssa-math-opts.cc | 38 +-------------------------------- 2 files changed, 15 insertions(+), 37 deletions(-) diff --git a/gcc/testsuite/gcc.target/arm/pr122111.c b/gcc/testsuite/gcc.target/arm/pr122111.c new file mode 100644 index 000000000000..82d15e9a43bf --- /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 0db39f330ead..04c9f2c07e92 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
