Skip to content

Commit e520fe0

Browse files
committed
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.
1 parent 53085a4 commit e520fe0

File tree

2 files changed

+15
-37
lines changed

2 files changed

+15
-37
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* Test that we do not have ice when compile */
2+
/* { dg-do compile } */
3+
/* { dg-options "-O3" } */
4+
5+
typedef long long wide;
6+
7+
void g(void);
8+
wide f(int *a, unsigned t)
9+
{
10+
wide i = t;
11+
i *= 4;
12+
unsigned long ai = (__SIZE_TYPE__)a;
13+
return i + ai;
14+
}

gcc/tree-ssa-math-opts.cc

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,43 +1631,7 @@ static tree
16311631
build_and_insert_cast (gimple_stmt_iterator *gsi, location_t loc,
16321632
tree type, tree val)
16331633
{
1634-
tree result = make_ssa_name (type);
1635-
tree rhs = val;
1636-
1637-
if (TREE_CODE (val) == SSA_NAME)
1638-
{
1639-
gimple *def = SSA_NAME_DEF_STMT (val);
1640-
1641-
if (is_gimple_assign (def)
1642-
&& CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def)))
1643-
{
1644-
tree cast_rhs = gimple_assign_rhs1 (def);
1645-
tree cast_rhs_type = TREE_TYPE (cast_rhs);
1646-
tree val_type = TREE_TYPE (val);
1647-
1648-
bool unsigned_p = TYPE_UNSIGNED (type);
1649-
bool unsigned_rhs_p = TYPE_UNSIGNED (cast_rhs_type);
1650-
bool unsigned_val_p = TYPE_UNSIGNED (val_type);
1651-
1652-
unsigned rhs_prec = TYPE_PRECISION (cast_rhs_type);
1653-
unsigned type_prec = TYPE_PRECISION (type);
1654-
unsigned val_prec = TYPE_PRECISION (val_type);
1655-
1656-
if (type_prec >= rhs_prec && val_prec >= rhs_prec)
1657-
{
1658-
/* Aka any sign extend from small to big size */
1659-
if (!((val_prec > rhs_prec && !unsigned_val_p && !unsigned_rhs_p)
1660-
|| (type_prec > val_prec && !unsigned_p && !unsigned_val_p)))
1661-
rhs = cast_rhs;
1662-
}
1663-
}
1664-
}
1665-
1666-
gassign *stmt = gimple_build_assign (result, NOP_EXPR, rhs);
1667-
1668-
gimple_set_location (stmt, loc);
1669-
gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
1670-
return result;
1634+
return gimple_convert (gsi, true, GSI_SAME_STMT, loc, type, val);
16711635
}
16721636

16731637
struct pow_synth_sqrt_info

0 commit comments

Comments
 (0)