[llvm-bugs] [Bug 44663] New: [Attributor?] Smart noalias deduction
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat Jan 25 10:56:48 PST 2020
https://bugs.llvm.org/show_bug.cgi?id=44663
Bug ID: 44663
Summary: [Attributor?] Smart noalias deduction
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Global Analyses
Assignee: unassignedbugs at nondot.org
Reporter: lebedev.ri at gmail.com
CC: llvm-bugs at lists.llvm.org
In this example `sink()` is static, we know all it's call sites.
We should be able to tell in all the call sites,
it's third argument (`highpass.data`) does not alias
with any other pointers used in `sink()` (namely `highhigh.data` and
`lowhigh.data`),
because we should be able to see how `highpass.data`
is being set to a fresh noalias pointer.
https://godbolt.org/z/32edkj
#include <cassert> // for assert
#include <type_traits>
#include <vector> // for vector
#include <cstddef> // for vector
#include <cstdint> // for vector
template <class T> class Array2DRef {
int _pitch = 0;
T* _data = nullptr;
friend Array2DRef<const T>; // We need to be able to convert to const
version.
inline T& operator[](int row) const;
public:
using value_type = T;
using cvless_value_type = typename std::remove_cv<value_type>::type;
int width = 0, height = 0;
Array2DRef() = default;
Array2DRef(T* data, int dataWidth, int dataHeight, int dataPitch = 0);
// Conversion from Array2DRef<T> to Array2DRef<const T>.
template <class T2, typename = std::enable_if_t<std::is_same<
typename std::remove_const<T>::type, T2>::value>>
Array2DRef(Array2DRef<T2> RHS) { // NOLINT google-explicit-constructor
_data = RHS._data;
_pitch = RHS._pitch;
width = RHS.width;
height = RHS.height;
}
template <typename AllocatorType =
typename std::vector<cvless_value_type>::allocator_type>
static Array2DRef<T>
create(std::vector<cvless_value_type, AllocatorType>* storage, int width,
int height) {
storage->resize(width * height);
return {storage->data(), width, height};
}
inline T& operator()(int row, int col) const;
};
template <class T>
Array2DRef<T>::Array2DRef(T* data, const int dataWidth, const int dataHeight,
const int dataPitch /* = 0 */)
: _data(data), width(dataWidth), height(dataHeight) {
assert(width >= 0);
assert(height >= 0);
_pitch = (dataPitch == 0 ? dataWidth : dataPitch);
}
template <class T> T& Array2DRef<T>::operator[](const int row) const {
assert(_data);
assert(row >= 0);
assert(row < height);
return _data[row * _pitch];
}
template <class T>
T& Array2DRef<T>::operator()(const int row, const int col) const {
assert(col >= 0);
assert(col < width);
return (&(operator[](row)))[col];
}
static __attribute__((noinline)) void sink(const Array2DRef<const int16_t>
highhigh, const Array2DRef<const int16_t> lowhigh, Array2DRef<int16_t>
highpass) {
for(int row = 0; row < highpass.height; ++row) {
for(int col = 0; col < highpass.width; ++col) {
// highpass does not alias highhigh/lowhigh !
// this should nicely vectorize.
highpass(row, col) = 24 * highhigh(row, col) + 18 * lowhigh (row,
col);
}
}
}
void foo(int width, int height, const Array2DRef<const int16_t> highhigh, const
Array2DRef<const int16_t> lowhigh, std::vector<int16_t>& highpass_storage) {
Array2DRef<int16_t> highpass = Array2DRef<int16_t>::create(&highpass_storage,
width, height);
sink(highhigh, lowhigh, highpass);
}
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200125/b329fa7b/attachment.html>
More information about the llvm-bugs
mailing list