This patchset improves folding in cases where input lengths
and/or destination sizes may not be constant but are range bound.

Tested on x86_64 with a full bootstrap build and verified that there are
no regressions resulting from this patchset.  I double-checked that the
run was current and I wasn't checking logs of a stale build.

I tested builds of bash and wpa_supplicant with this patchset.
wpa_supplicant ends up with 30 fewer __memcpy_chk calls, of which 14 are
completely optimized away and the rest transformed to __memcpy. 

In bash, 3 __memcpy_chk calls are optimized away completely in addition
to a couple of memmove and strcpy chk variants being transformed into
regular calls.

Changes from v1:

- Use dump_* functions instead of directly using dump_file
- Bring back warnings and reduce scope of changes to strncat to only
  using ranges to determine if call can be simplified to strcat.
- Renamed known_safe to known_lower

Siddhesh Poyarekar (3):
  gimple-fold: Transform stp*cpy_chk to str*cpy directly
  gimple-fold: Use ranges to simplify _chk calls
  gimple-fold: Use ranges to simplify strncat and snprintf

 gcc/gimple-fold.c                       | 343 ++++++++++--------------
 gcc/testsuite/gcc.dg/Wobjsize-1.c       |   5 +-
 gcc/testsuite/gcc.dg/fold-stringops-1.c |  23 ++
 gcc/testsuite/gcc.dg/fold-stringops-2.c |  63 +++++
 gcc/testsuite/gcc.dg/fold-stringops-3.c |  18 ++
 5 files changed, 256 insertions(+), 196 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/fold-stringops-1.c
 create mode 100644 gcc/testsuite/gcc.dg/fold-stringops-2.c
 create mode 100644 gcc/testsuite/gcc.dg/fold-stringops-3.c

-- 
2.31.1

Reply via email to