aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/bits/hashtable.h
diff options
context:
space:
mode:
authorVictor Do Nascimento <victor.donascimento@arm.com>2024-05-22 12:14:11 +0100
committerVictor Do Nascimento <victor.donascimento@arm.com>2024-06-12 14:38:55 +0100
commitadcc815a01ae009d2768b6afb546e357bd37bbd2 (patch)
treec06363a3959c9469dd8e5cf47c7be368120b1ef3 /libstdc++-v3/include/bits/hashtable.h
parent1cae1a5ce088c1fa351b5752d43de52f1f116a75 (diff)
downloadgcc-adcc815a01ae009d2768b6afb546e357bd37bbd2.zip
gcc-adcc815a01ae009d2768b6afb546e357bd37bbd2.tar.gz
gcc-adcc815a01ae009d2768b6afb546e357bd37bbd2.tar.bz2
middle-end: Drop __builtin_prefetch calls in autovectorization [PR114061]
At present the autovectorizer fails to vectorize simple loops involving calls to `__builtin_prefetch'. A simple example of such loop is given below: void foo(double * restrict a, double * restrict b, int n){ int i; for(i=0; i<n; ++i){ a[i] = a[i] + b[i]; __builtin_prefetch(&(b[i+8])); } } The failure stems from two issues: 1. Given that it is typically not possible to fully reason about a function call due to the possibility of side effects, the autovectorizer does not attempt to vectorize loops which make such calls. Given the memory reference passed to `__builtin_prefetch', in the absence of assurances about its effect on the passed memory location the compiler deems the function unsafe to vectorize, marking it as clobbering memory in `vect_find_stmt_data_reference'. This leads to the failure in autovectorization. 2. Notwithstanding the above issue, though the prefetch statement would be classed as `vect_unused_in_scope', the loop invariant that is used in the address of the prefetch is the scalar loop's and not the vector loop's IV. That is, it still uses `i' and not `vec_iv' because the instruction wasn't vectorized, causing DCE to think the value is live, such that we now have both the vector and scalar loop invariant actively used in the loop. This patch addresses both of these: 1. About the issue regarding the memory clobber, data prefetch does not generate faults if its address argument is invalid and does not write to memory. Therefore, it does not alter the internal state of the program or its control flow under any circumstance. As such, it is reasonable that the function be marked as not affecting memory contents. To achieve this, we add the necessary logic to `get_references_in_stmt' to ensure that builtin functions are given given the same treatment as internal functions. If the gimple call is to a builtin function and its function code is `BUILT_IN_PREFETCH', we mark `clobbers_memory' as false. 2. Finding precedence in the way clobber statements are handled, whereby the vectorizer drops these from both the scalar and vectorized versions of a given loop, we choose to drop prefetch hints in a similar fashion. This seems appropriate given how software prefetch hints are typically ignored by processors across architectures, as they seldom lead to performance gain over their hardware counterparts. gcc/ChangeLog: PR tree-optimization/114061 * tree-data-ref.cc (get_references_in_stmt): set `clobbers_memory' to false for __builtin_prefetch. * tree-vect-loop.cc (vect_transform_loop): Drop all __builtin_prefetch calls from loops. gcc/testsuite/ChangeLog: * gcc.dg/vect/vect-prefetch-drop.c: New test. * gcc.target/aarch64/vect-prefetch-drop.c: Likewise.
Diffstat (limited to 'libstdc++-v3/include/bits/hashtable.h')
0 files changed, 0 insertions, 0 deletions