From: Pan Li <[email protected]>
When the val of build_and_insert_cast comes from a cast already, we
can refine it to the val casted from to avoid duplicated cast on
condition. However, it is valid only for int types, other types
like pointer/reference is invalid as it at least requires the
type precision is totoally the same.
The below test suites are passed for this patch:
1. The x86 bootstrap tests.
2. The x86 fully regression tests.
3. The pr122111.c test of arm.
PR middel-end/122111
gcc/ChangeLog:
* tree-ssa-math-opts.cc (build_and_insert_cast): Add the
INTEGRAL_TYPE_P check for the cast val.
gcc/testsuite/ChangeLog:
* gcc.target/arm/pr122111.c: New test.
Signed-off-by: Pan Li <[email protected]>
---
gcc/testsuite/gcc.target/arm/pr122111.c | 14 ++++++++++++++
gcc/tree-ssa-math-opts.cc | 3 ++-
2 files changed, 16 insertions(+), 1 deletion(-)
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..0bc4ea32f65 100644
--- a/gcc/tree-ssa-math-opts.cc
+++ b/gcc/tree-ssa-math-opts.cc
@@ -1639,7 +1639,8 @@ build_and_insert_cast (gimple_stmt_iterator *gsi,
location_t loc,
gimple *def = SSA_NAME_DEF_STMT (val);
if (is_gimple_assign (def)
- && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def)))
+ && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def))
+ && INTEGRAL_TYPE_P (TREE_TYPE (gimple_assign_rhs1 (def))))
{
tree cast_rhs = gimple_assign_rhs1 (def);
tree cast_rhs_type = TREE_TYPE (cast_rhs);
--
2.43.0