llvm-project/debuginfo-tests/dexter-tests/optnone-vectors-and-functio...

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

136 lines
5.9 KiB
C++
Raw Normal View History

[debuginfo-tests] Add some optnone tests Add dexter tests using the optnone attribute in various scenarios. Our users have found optnone useful when debugging optimised code. We have these tests downstream (and one upstream already: D89873) and we would like to contribute them if there is any interest. The tests are fairly self explanatory. Testing optnone with: * optnone-fastmath.cpp: floats and -ffast-math, * optnone-simple-functions: simple functions and integer arithmetic, * optnone-struct-and-methods: a struct with methods, * optnone-vectors-and-functions: templates and integer vector arithmetic. optnone-vectors-and-functions contains two FIXMEs. The first problem is that lldb seems to struggle with evaluating expressions with the templates used here (example below). Perhaps this is PR42920? (lldb) p TypeTraits<int __attribute__((ext_vector_type(4)))>::NumElements error: <user expression 0>:1:1: no template named 'TypeTraits' TypeTraits<int __attribute__((ext_vector_type(4)))>::NumElements ^ The second is that while lldb cannot evaluate the following expression, gdb can, but it reports that the variable has been optimzed away. It does this when compiling at O0 too. llvm-dwarfdump shows that MysteryNumber does have a location. I don't know whether the DIE is bad or if both debuggers just don't support it. TypeTraits<int __attribute__((ext_vector_type(4)))>::MysteryNumber DW_TAG_variable DW_AT_specification (0x0000006b "MysteryNumber") DW_AT_location (DW_OP_addr 0x601028) DW_AT_linkage_name ("_ZN10TypeTraitsIDv4_iE13MysteryNumberE") Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D97668
2021-03-02 16:45:53 +08:00
// RUN: %dexter --fail-lt 1.0 -w \
// RUN: --builder 'clang' --debugger 'lldb' \
// RUN: --cflags "-g -O2" -v -- %s
// RUN: %dexter --fail-lt 1.0 -w \
// RUN: --builder 'clang' --debugger 'lldb' \
// RUN: --cflags "-g -O0" -- %s
// REQUIRES: lldb
// UNSUPPORTED: system-windows
//// Check that the debugging experience with __attribute__((optnone)) at O2
//// matches O0. Test simple template functions performing simple arithmetic
//// vector operations and trivial loops.
typedef int int4 __attribute__((ext_vector_type(4)));
template<typename T> struct TypeTraits {};
template<>
struct TypeTraits<int4> {
static const unsigned NumElements = 4;
static const unsigned UnusedField = 0xDEADBEEFU;
static unsigned MysteryNumber;
};
unsigned TypeTraits<int4>::MysteryNumber = 3U;
template<typename T>
__attribute__((optnone))
T test1(T x, T y) {
T tmp = x + y; // DexLabel('break_0')
T tmp2 = tmp + y;
return tmp; // DexLabel('break_1')
}
// DexLimitSteps('1', '1', from_line='break_0', to_line='break_1')
//// FIXME: gdb can print this but lldb cannot. Perhaps PR42920?
// \DexExpectWatchValue('TypeTraits<int __attribute__((ext_vector_type(4)))>::NumElements', 4, on_line='break_0')
// \DexExpectWatchValue('TypeTraits<int __attribute__((ext_vector_type(4)))>::UnusedField', 0xdeadbeef, on_line='break_0')
// DexExpectWatchValue('x[0]', 1, on_line='break_0')
// DexExpectWatchValue('x[1]', 2, on_line='break_0')
// DexExpectWatchValue('x[2]', 3, on_line='break_0')
// DexExpectWatchValue('x[3]', 4, on_line='break_0')
// DexExpectWatchValue('y[0]', 5, on_line='break_0')
// DexExpectWatchValue('y[1]', 6, on_line='break_0')
// DexExpectWatchValue('y[2]', 7, on_line='break_0')
// DexExpectWatchValue('y[3]', 8, on_line='break_0')
// DexExpectWatchValue('tmp[0]', 6, on_line='break_1')
// DexExpectWatchValue('tmp[1]', 8, on_line='break_1')
// DexExpectWatchValue('tmp[2]', 10, on_line='break_1')
// DexExpectWatchValue('tmp[3]', 12, on_line='break_1')
// DexExpectWatchValue('tmp2[0]', 11, on_line='break_1')
// DexExpectWatchValue('tmp2[1]', 14, on_line='break_1')
// DexExpectWatchValue('tmp2[2]', 17, on_line='break_1')
// DexExpectWatchValue('tmp2[3]', 20, on_line='break_1')
template<typename T>
__attribute__((optnone))
T test2(T x, T y) {
T tmp = x;
int break_2 = 0; // DexLabel('break_2')
for (unsigned i = 0; i != TypeTraits<T>::NumElements; ++i) {
tmp <<= 1; // DexLabel('break_3')
tmp |= y;
}
tmp[0] >>= TypeTraits<T>::MysteryNumber;
return tmp; // DexLabel('break_5')
}
// DexLimitSteps('1', '1', on_line='break_2')
// DexExpectWatchValue('x[0]', 6, on_line='break_2')
// DexExpectWatchValue('x[1]', 8, on_line='break_2')
// DexExpectWatchValue('x[2]', 10, on_line='break_2')
// DexExpectWatchValue('x[3]', 12, on_line='break_2')
// DexExpectWatchValue('y[0]', 5, on_line='break_2')
// DexExpectWatchValue('y[1]', 6, on_line='break_2')
// DexExpectWatchValue('y[2]', 7, on_line='break_2')
// DexExpectWatchValue('y[3]', 8, on_line='break_2')
// DexExpectWatchValue('tmp[0]', 6, on_line='break_2')
// DexExpectWatchValue('tmp[1]', 8, on_line='break_2')
// DexExpectWatchValue('tmp[2]', 10, on_line='break_2')
// DexExpectWatchValue('tmp[3]', 12, on_line='break_2')
// DexLimitSteps('i', 3, on_line='break_3')
// DexExpectWatchValue('tmp[0]', 63, on_line='break_3')
// DexExpectWatchValue('tmp[1]', 94, on_line='break_3')
// DexExpectWatchValue('tmp[2]', 95, on_line='break_3')
// DexExpectWatchValue('tmp[3]', 120, on_line='break_3')
// DexLimitSteps('i', 3, on_line='break_5')
// DexExpectWatchValue('tmp[0]', 15, on_line='break_5')
template<typename T>
__attribute__((optnone))
T test3(T InVec) {
T result;
for (unsigned i=0; i != TypeTraits<T>::NumElements; ++i)
result[i] = InVec[i]; // DexLabel('break_6')
return result; // DexLabel('break_7')
}
// DexLimitSteps('i', '3', from_line='break_6', to_line='break_7')
// DexExpectWatchValue('InVec[0]', 15, from_line='break_6', to_line='break_7')
// DexExpectWatchValue('InVec[1]', 190, from_line='break_6', to_line='break_7')
// DexExpectWatchValue('InVec[2]', 191, from_line='break_6', to_line='break_7')
// DexExpectWatchValue('InVec[3]', 248, from_line='break_6', to_line='break_7')
// DexExpectWatchValue('result[0]', 15, from_line='break_6', to_line='break_7')
// DexExpectWatchValue('result[1]', 190, from_line='break_6', to_line='break_7')
// DexExpectWatchValue('result[2]', 191, from_line='break_6', to_line='break_7')
// DexExpectWatchValue('result[3]', 248, on_line='break_7')
template<typename T>
__attribute__((optnone))
T test4(T x, T y) {
for (unsigned i=0; i != TypeTraits<T>::NumElements; ++i)
x[i] = (x[i] > y[i])? x[i] : y[i] + TypeTraits<T>::MysteryNumber; // DexLabel('break_11')
return x; // DexLabel('break_12')
}
// DexLimitSteps('1', '1', from_line='break_11', to_line='break_12')
//// FIXME: lldb won't print this but gdb unexpectedly says it's optimized out, even at O0.
// \DexExpectWatchValue('TypeTraits<int __attribute__((ext_vector_type(4)))>::MysteryNumber', 3, on_line='break_11')
// DexExpectWatchValue('i', 0, 1, 2, 3, on_line='break_11')
// DexExpectWatchValue('x[0]', 1, 8, from_line='break_11', to_line='break_12')
// DexExpectWatchValue('x[1]', 2, 9, from_line='break_11', to_line='break_12')
// DexExpectWatchValue('x[2]', 3, 10, from_line='break_11', to_line='break_12')
// DexExpectWatchValue('x[3]', 4, 11, from_line='break_11', to_line='break_12')
// DexExpectWatchValue('y[0]', 5, from_line='break_11', to_line='break_12')
// DexExpectWatchValue('y[1]', 6, from_line='break_11', to_line='break_12')
// DexExpectWatchValue('y[2]', 7, from_line='break_11', to_line='break_12')
// DexExpectWatchValue('y[3]', 8, from_line='break_11', to_line='break_12')
int main() {
int4 a = (int4){1,2,3,4};
int4 b = (int4){5,6,7,8};
int4 tmp = test1(a,b);
tmp = test2(tmp,b);
tmp = test3(tmp);
tmp += test4(a,b);
return tmp[0];
}