gimple-fold: Transform stp*cpy_chk to str*cpy directly
commitd1753b4be981fcb176f56b6ed45f7dbe1177d641
authorSiddhesh Poyarekar <siddhesh@gotplt.org>
Mon, 15 Nov 2021 17:33:13 +0000 (15 23:03 +0530)
committerSiddhesh Poyarekar <siddhesh@gotplt.org>
Mon, 15 Nov 2021 22:49:51 +0000 (16 04:19 +0530)
treede2bb231db90865a3451fb4bcd592e51d86f9ccf
parent4c19122bf5afa5cb479fd9445f0c591c52add09b
gimple-fold: Transform stp*cpy_chk to str*cpy directly

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 (dump_transformation): New function.
(gimple_fold_builtin_stxcpy_chk,
gimple_fold_builtin_stxncpy_chk): Use it.  Simplify to
BUILT_IN_STRNCPY if return value is not used.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
gcc/gimple-fold.c
gcc/testsuite/gcc.dg/fold-stringops-1.c [new file with mode: 0644]