builtins: Pass access direction to get_memory_rtx [PR127185]

get_memory_rtx creates memory operands for both sources and destinations
of string operations.  The memory attribute setter cannot infer the access
direction from the address expression.  Its conservative default therefore
loses nontrapping information for known loads.  An inline memcmp source
changes from:

  (mem:QI (...) [ this ])

to:

  (mem/c:QI (...) [ this ])

Add a required STORE_P argument to get_memory_rtx.  Mark destinations as
stores and sources as loads at every caller.  This keeps precise nontrapping
information for loads without using it for stores.

Bootstrapped and tested on aarch64-unknown-linux-gnu.  Tested on
x86_64-pc-linux-gnu.

	PR middle-end/127185

gcc/ChangeLog:

	* builtins.cc (get_memory_rtx): Add STORE_P.  Pass it to
	set_mem_attributes.
	(expand_builtin_memory_copy_args): Mark the destination as a store
	and the source as a load.
	(expand_movstr): Likewise.
	(expand_builtin_strncpy): Mark the destination as a store.
	(expand_builtin_memset_args): Likewise.
	(expand_builtin_memcmp): Mark both memory operands as loads.
	(expand_builtin_strcmp): Likewise.
	(expand_builtin_strncmp): Likewise.
	(inline_string_cmp): Mark the memory operand as a load.
	* builtins.h (get_memory_rtx): Add STORE_P.
	* internal-fn.cc (expand_RAWMEMCHR): Mark the memory operand as a
	load.

gcc/testsuite/ChangeLog:

	* g++.dg/opt/mem-notrap-load-builtin.C: New test.

Signed-off-by: Kyrylo Tkachov <ktkachov@nvidia.com>
4 files changed