aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-fold.c
diff options
context:
space:
mode:
authorPrathamesh Kulkarni <prathamesh.kulkarni@linaro.org>2017-04-29 10:05:13 +0000
committerPrathamesh Kulkarni <prathamesh3492@gcc.gnu.org>2017-04-29 10:05:13 +0000
commitfe75f73248425f0f4c0d2196811ce1d7afb9c09f (patch)
tree9e0c2d1d28b1e5baecc44a4c7b78ad81f0e1bef3 /gcc/gimple-fold.c
parent6bcd876838b433fd2730a6a15740ddcecbefd9ea (diff)
downloadgcc-fe75f73248425f0f4c0d2196811ce1d7afb9c09f.zip
gcc-fe75f73248425f0f4c0d2196811ce1d7afb9c09f.tar.gz
gcc-fe75f73248425f0f4c0d2196811ce1d7afb9c09f.tar.bz2
re PR tree-optimization/79697 (unused realloc(0, n) not eliminated)
2017-04-29 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org> PR tree-optimization/79697 * tree-ssa-dce.c (mark_stmt_if_obviously_necessary): Check if callee is BUILT_IN_STRDUP, BUILT_IN_STRNDUP, BUILT_IN_REALLOC. (propagate_necessity): Check if def_callee is BUILT_IN_STRDUP or BUILT_IN_STRNDUP. * gimple-fold.c (gimple_fold_builtin_realloc): New function. (gimple_fold_builtin): Call gimple_fold_builtin_realloc. testsuite/ * gcc.dg/tree-ssa/pr79697.c: New test. From-SVN: r247407
Diffstat (limited to 'gcc/gimple-fold.c')
-rw-r--r--gcc/gimple-fold.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index a6a958c..5ebdcdf 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -3251,6 +3251,28 @@ gimple_fold_builtin_acc_on_device (gimple_stmt_iterator *gsi, tree arg0)
return true;
}
+/* Fold realloc (0, n) -> malloc (n). */
+
+static bool
+gimple_fold_builtin_realloc (gimple_stmt_iterator *gsi)
+{
+ gimple *stmt = gsi_stmt (*gsi);
+ tree arg = gimple_call_arg (stmt, 0);
+ tree size = gimple_call_arg (stmt, 1);
+
+ if (operand_equal_p (arg, null_pointer_node, 0))
+ {
+ tree fn_malloc = builtin_decl_implicit (BUILT_IN_MALLOC);
+ if (fn_malloc)
+ {
+ gcall *repl = gimple_build_call (fn_malloc, 1, size);
+ replace_call_with_call_and_fold (gsi, repl);
+ return true;
+ }
+ }
+ return false;
+}
+
/* Fold the non-target builtin at *GSI and return whether any simplification
was made. */
@@ -3409,6 +3431,9 @@ gimple_fold_builtin (gimple_stmt_iterator *gsi)
case BUILT_IN_ACC_ON_DEVICE:
return gimple_fold_builtin_acc_on_device (gsi,
gimple_call_arg (stmt, 0));
+ case BUILT_IN_REALLOC:
+ return gimple_fold_builtin_realloc (gsi);
+
default:;
}