__builtin_stack_save can be removed when the lhs becomes unused
as it is just recording the current StackPointer into another register.
Bootstrapped and tested on x86_64-linux-gnu.
PR tree-optimization/122037
gcc/ChangeLog:
* tree-ssa-dce.cc (eliminate_unnecessary_stmts): Remove
__builtin_stack_save when the lhs is unused.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/vla-1.c: New test.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized -fdump-tree-cddce1-details" } */
+/* PR tree-optimization/122037 */
+
+void bar1 (char *, int) __attribute__((noreturn));
+void foo1 (int size)
+{
+ char temp[size];
+ temp[size-1] = '\0';
+ bar1 (temp, size);
+}
+
+/* The call to __builtin_stack_save should have been removed. */
+/* { dg-final { scan-tree-dump "Deleting : __builtin_stack_save" "cddce1" } } */
+/* { dg-final { scan-tree-dump-not "__builtin_stack_save " "optimized" } } */
update_stmt (call_stmt);
release_ssa_name (name);
+ /* __builtin_stack_save without lhs is not needed. */
+ if (gimple_call_builtin_p (call_stmt, BUILT_IN_STACK_SAVE))
+ remove_dead_stmt (&gsi, bb, to_remove_edges);
/* GOMP_SIMD_LANE (unless three argument) or ASAN_POISON
without lhs is not needed. */
- if (gimple_call_internal_p (call_stmt))
+ else if (gimple_call_internal_p (call_stmt))
switch (gimple_call_internal_fn (call_stmt))
{
case IFN_GOMP_SIMD_LANE: