On 11/12/21 22:46, Prathamesh Kulkarni wrote:
On Fri, 12 Nov 2021 at 01:12, Siddhesh Poyarekar <siddh...@gotplt.org> wrote:

Avoid going through another folding cycle and use the ignore flag to
directly transform BUILT_IN_STPCPY_CHK to BUILT_IN_STRCPY when set,
likewise for BUILT_IN_STPNCPY_CHK to BUILT_IN_STPNCPY.

Dump the transformation in dump_file so that we can verify in tests that
the direct transformation actually happened.

gcc/ChangeLog:

         * gimple-fold.c (gimple_fold_builtin_stxcpy_chk,
         gimple_fold_builtin_stxncpy_chk): Use BUILT_IN_STRNCPY if return
         value is not used.

gcc/testsuite/ChangeLog:

         * gcc.dg/fold-stringops.c: New test.

Signed-off-by: Siddhesh Poyarekar <siddh...@gotplt.org>
---
  gcc/gimple-fold.c                       | 50 +++++++++++++++++--------
  gcc/testsuite/gcc.dg/fold-stringops-1.c | 23 ++++++++++++
  2 files changed, 57 insertions(+), 16 deletions(-)
  create mode 100644 gcc/testsuite/gcc.dg/fold-stringops-1.c

diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index 6e25a7c05db..92e15784803 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -3088,6 +3088,19 @@ gimple_fold_builtin_memory_chk (gimple_stmt_iterator 
*gsi,
    return true;
  }

+static void
+dump_transformation (gimple *from, gimple *to)
I assume that both from and to will always be builtin calls ?
In that case, perhaps better to use gcall * here (and in rest of patch).
Also, needs a top-level comment describing the function.
+{
+  if (dump_file && (dump_flags & TDF_DETAILS))
Perhaps better to use dump_enabled_p ?
+    {
+      fprintf (dump_file, "transformed ");
Perhaps use dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, ...) ?
I think you can use gimple_location to get the location.


Thanks, I'll fix these up.

Siddhesh

Reply via email to