From 2d7210947b4cf5973a8100c652f3c9fcecef4c40 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Fri, 8 Jun 2007 16:00:24 +0000 Subject: [PATCH] some new testcases from llvm [r14381] --- ir/be/test/globalrefs.c | 64 +++++++ .../test/llvm/2003-05-14-initialize-string.c | 6 + ir/be/test/llvm/2003-05-21-BitfieldHandling.c | 59 +++++++ ir/be/test/llvm/2003-05-21-UnionBitfields.c | 22 +++ ir/be/test/llvm/2003-05-21-UnionTest.c | 11 ++ ir/be/test/llvm/2003-05-22-LocalTypeTest.c | 24 +++ ir/be/test/llvm/2003-05-22-VarSizeArray.c | 12 ++ ir/be/test/llvm/2003-05-23-TransparentUnion.c | 20 +++ .../test/llvm/2003-06-16-InvalidInitializer.c | 8 + ir/be/test/llvm/2003-06-16-VolatileError.c | 5 + .../llvm/2003-10-12-GlobalVarInitializers.c | 11 ++ ir/be/test/llvm/2004-02-03-AggregateCopy.c | 14 ++ .../test/llvm/2004-08-12-InlinerAndAllocas.c | 26 +++ .../llvm/2005-05-06-LongLongSignedShift.c | 5 + .../llvm/ConstructorDestructorAttributes.c | 14 ++ ir/be/test/llvm/DuffsDevice.c | 38 +++++ ir/be/test/llvm/PR491.c | 30 ++++ ir/be/test/llvm/PR640.c | 55 ++++++ ir/be/test/llvm/badidx.c | 25 +++ ir/be/test/llvm/bigstack.c | 79 +++++++++ ir/be/test/llvm/callargs.c | 156 ++++++++++++++++++ ir/be/test/llvm/casts.c | 138 ++++++++++++++++ ir/be/test/llvm/globalrefs.c | 64 +++++++ ir/be/test/llvm/matrixTranspose.c | 46 ++++++ ir/be/test/llvm/pointer_arithmetic.c | 20 +++ ir/be/test/llvm/sumarray.c | 25 +++ ir/be/test/llvm/sumarray2d.c | 29 ++++ ir/be/test/llvm/sumarraymalloc.c | 44 +++++ ir/be/test/llvm/test_indvars.c | 36 ++++ ir/be/test/llvm/testtrace.c | 44 +++++ ir/be/test/makereport.sh | 2 +- 31 files changed, 1131 insertions(+), 1 deletion(-) create mode 100644 ir/be/test/globalrefs.c create mode 100644 ir/be/test/llvm/2003-05-14-initialize-string.c create mode 100644 ir/be/test/llvm/2003-05-21-BitfieldHandling.c create mode 100644 ir/be/test/llvm/2003-05-21-UnionBitfields.c create mode 100644 ir/be/test/llvm/2003-05-21-UnionTest.c create mode 100644 ir/be/test/llvm/2003-05-22-LocalTypeTest.c create mode 100644 ir/be/test/llvm/2003-05-22-VarSizeArray.c create mode 100644 ir/be/test/llvm/2003-05-23-TransparentUnion.c create mode 100644 ir/be/test/llvm/2003-06-16-InvalidInitializer.c create mode 100644 ir/be/test/llvm/2003-06-16-VolatileError.c create mode 100644 ir/be/test/llvm/2003-10-12-GlobalVarInitializers.c create mode 100644 ir/be/test/llvm/2004-02-03-AggregateCopy.c create mode 100644 ir/be/test/llvm/2004-08-12-InlinerAndAllocas.c create mode 100644 ir/be/test/llvm/2005-05-06-LongLongSignedShift.c create mode 100644 ir/be/test/llvm/ConstructorDestructorAttributes.c create mode 100644 ir/be/test/llvm/DuffsDevice.c create mode 100644 ir/be/test/llvm/PR491.c create mode 100644 ir/be/test/llvm/PR640.c create mode 100644 ir/be/test/llvm/badidx.c create mode 100644 ir/be/test/llvm/bigstack.c create mode 100644 ir/be/test/llvm/callargs.c create mode 100644 ir/be/test/llvm/casts.c create mode 100644 ir/be/test/llvm/globalrefs.c create mode 100644 ir/be/test/llvm/matrixTranspose.c create mode 100644 ir/be/test/llvm/pointer_arithmetic.c create mode 100644 ir/be/test/llvm/sumarray.c create mode 100644 ir/be/test/llvm/sumarray2d.c create mode 100644 ir/be/test/llvm/sumarraymalloc.c create mode 100644 ir/be/test/llvm/test_indvars.c create mode 100644 ir/be/test/llvm/testtrace.c diff --git a/ir/be/test/globalrefs.c b/ir/be/test/globalrefs.c new file mode 100644 index 000000000..e4247a93f --- /dev/null +++ b/ir/be/test/globalrefs.c @@ -0,0 +1,64 @@ +/* globalrefs.c - Test symbolic constant expressions constructed from + * global addresses and index expressions into global addresses. + * Do this both with global constants and with inline constant. + * Instead of printing absolute addresses, print out the differences in + * memory addresses to get output that matches that of the native compiler. + */ + +#include + +#define __STDC_LIMIT_MACROS 1 +#include + +struct test { + long A; + struct { unsigned X; unsigned Y; } S; + struct test* next; +}; + +struct test TestArray[10]; +struct test Test1; + +/* Create global symbolic constants from the addresses of the above globals */ + +struct test* TestArrayPtr = &TestArray[3]; +long* Aptr = &Test1.A; +unsigned* Yptr = &Test1.S.Y; +struct test** NextPtr = &Test1.next; + +void +printdiff(void* p1, void* p2) +{ + printf(" %d", (int)((unsigned long) p1 - (unsigned long) p2)); +} + +int +main(int argc, char** argv) +{ + unsigned long diff1, diff2, diff3, diff4; + + printf("sizeof(struct Test) = %d\n\n", (int)sizeof(struct test)); + + printdiff(&TestArray[3], TestArray); + printdiff(&Test1.S.Y, &Test1.A); + printdiff(&Test1.next, &Test1.S.Y); + printf("\n"); + + diff1 = (unsigned long) &TestArray[3] - (unsigned long) TestArray; + diff3 = (unsigned long) &Test1.S.Y - (unsigned long) &Test1.A; + diff4 = (unsigned long) &Test1.next - (unsigned long) &Test1.S.Y; + + printf("&TestArray[3] - TestArray = 0x%lx\n", diff1); + printf("Xptr - Aptr = 0x%lx\n", diff3); + printf("NextPtr - Xptr = 0x%lx\n\n", diff4); + + diff1 = (unsigned long) TestArrayPtr - (unsigned long) TestArray; + diff3 = (unsigned long) Yptr - (unsigned long) Aptr; + diff4 = (unsigned long) NextPtr - (unsigned long) Yptr; + + printf("&TestArray[3] - TestArray = 0x%lx\n", diff1); + printf("Xptr - Aptr = 0x%lx\n", diff3); + printf("NextPtr - Xptr = 0x%lx\n\n", diff4); + + return 0; +} diff --git a/ir/be/test/llvm/2003-05-14-initialize-string.c b/ir/be/test/llvm/2003-05-14-initialize-string.c new file mode 100644 index 000000000..543b13c4b --- /dev/null +++ b/ir/be/test/llvm/2003-05-14-initialize-string.c @@ -0,0 +1,6 @@ + +int main() { + char title[] = "foo and stuff\n"; + printf("%s", title); + return 0; +} diff --git a/ir/be/test/llvm/2003-05-21-BitfieldHandling.c b/ir/be/test/llvm/2003-05-21-BitfieldHandling.c new file mode 100644 index 000000000..12508a931 --- /dev/null +++ b/ir/be/test/llvm/2003-05-21-BitfieldHandling.c @@ -0,0 +1,59 @@ +struct test_empty { +} e; +int Esize = sizeof(e); + +struct rtx_def { + unsigned short code; + long long :3; + int mode : 8; + long long :0; + long long x :31; + //long long y:31; +} N = {2, 7, 1 }; +int Nsize = sizeof(N); // Size = 8 + +struct test1 { + char x:1; + long long :0; +} F1; int F1size = sizeof(F1); // Size = 4 + +struct test2 { + long long x :4; +} F2; int F2size = sizeof(F2); // Size = 4 + +struct test3 { + char x:1; + long long :20; +} F3; int F3size = sizeof(F3); // Size = 3 + +struct test4 { + char x:1; + long long :21; + short Y : 14; +} F4; int F4size = sizeof(F4); // Size = 6 + +struct test5 { + char x:1; + long long :17; + char Y : 1; +} F5; int F5size = sizeof(F5); // Size = 3 + +struct test6 { + char x:1; + long long :42; + int Y : 21; +} F6; int F6size = sizeof(F6); // Size = 8 + +struct test { + char c; + char d : 3; + char e: 3; + int : 0; + char f; + char :0; + long long x : 4; +} M; int Msize = sizeof(M); // Size = 8 + +int main() { + return 0; +} diff --git a/ir/be/test/llvm/2003-05-21-UnionBitfields.c b/ir/be/test/llvm/2003-05-21-UnionBitfields.c new file mode 100644 index 000000000..d4da0d683 --- /dev/null +++ b/ir/be/test/llvm/2003-05-21-UnionBitfields.c @@ -0,0 +1,22 @@ +#include +#include + +int target_isinf(double x) { + union { + double d; + struct { + unsigned mantissa2; + unsigned mantissa1 : 20; + unsigned exponent : 11; + unsigned sign : 1; + } big_endian; + } u; + + u.d = x; + return (u.big_endian.exponent == 2047 && u.big_endian.mantissa1 == 0 && u.big_endian.mantissa2 == 0); +} + +int main() { + printf("%d %d\n", target_isinf(1234.42), target_isinf(1.0/1.0e-1000)); + return 0; +} diff --git a/ir/be/test/llvm/2003-05-21-UnionTest.c b/ir/be/test/llvm/2003-05-21-UnionTest.c new file mode 100644 index 000000000..626ba09d7 --- /dev/null +++ b/ir/be/test/llvm/2003-05-21-UnionTest.c @@ -0,0 +1,11 @@ +#include + +int __signbit (double __x) { + union { double __d; int __i[3]; } __u = { __d: __x }; + return __u.__i[1] < 0; +} + +int main() { + printf("%d %d\n", __signbit(-1), __signbit(2.0)); + return 0; +} diff --git a/ir/be/test/llvm/2003-05-22-LocalTypeTest.c b/ir/be/test/llvm/2003-05-22-LocalTypeTest.c new file mode 100644 index 000000000..2e2869259 --- /dev/null +++ b/ir/be/test/llvm/2003-05-22-LocalTypeTest.c @@ -0,0 +1,24 @@ +#include + +struct sometimes { + short offset; short bit; + short live_length; short calls_crossed; +} Y; + +int main() { + int X; + { + struct sometimes { int X, Y; } S; + S.X = 1; + X = S.X; + } + { + struct sometimes { char X; } S; + S.X = -1; + X += S.X; + } + X += Y.offset; + + printf("Result is %d\n", X); + return X; +} diff --git a/ir/be/test/llvm/2003-05-22-VarSizeArray.c b/ir/be/test/llvm/2003-05-22-VarSizeArray.c new file mode 100644 index 000000000..7ab4d67a9 --- /dev/null +++ b/ir/be/test/llvm/2003-05-22-VarSizeArray.c @@ -0,0 +1,12 @@ +#include + +int test(int Num) { + int Arr[Num]; + Arr[2] = 0; + return Arr[2]; +} + +int main() { + printf("%d\n", test(4)); + return 0; +} diff --git a/ir/be/test/llvm/2003-05-23-TransparentUnion.c b/ir/be/test/llvm/2003-05-23-TransparentUnion.c new file mode 100644 index 000000000..870826a59 --- /dev/null +++ b/ir/be/test/llvm/2003-05-23-TransparentUnion.c @@ -0,0 +1,20 @@ +#include + +typedef union { + float *__fptr; + int *__iptr; +} UNION __attribute__ ((__transparent_union__)); + +int try(UNION U) { + return 1; +} +int test() { + int I; + float F; + return try(&I) | try(&F); +} + +int main() { + if (test()) printf("ok"); + return 0; +} diff --git a/ir/be/test/llvm/2003-06-16-InvalidInitializer.c b/ir/be/test/llvm/2003-06-16-InvalidInitializer.c new file mode 100644 index 000000000..d6bfc53a4 --- /dev/null +++ b/ir/be/test/llvm/2003-06-16-InvalidInitializer.c @@ -0,0 +1,8 @@ +typedef struct { + char *auth_pwfile; + int x; +} auth_config_rec; + +void *Ptr = &((auth_config_rec*)0)->x; + +int main() { return 0; } diff --git a/ir/be/test/llvm/2003-06-16-VolatileError.c b/ir/be/test/llvm/2003-06-16-VolatileError.c new file mode 100644 index 000000000..127e54064 --- /dev/null +++ b/ir/be/test/llvm/2003-06-16-VolatileError.c @@ -0,0 +1,5 @@ +/* This crashes the CFE. */ +extern int volatile test; +int volatile test = 0; + +int main() { return 0; } diff --git a/ir/be/test/llvm/2003-10-12-GlobalVarInitializers.c b/ir/be/test/llvm/2003-10-12-GlobalVarInitializers.c new file mode 100644 index 000000000..30e63ad7e --- /dev/null +++ b/ir/be/test/llvm/2003-10-12-GlobalVarInitializers.c @@ -0,0 +1,11 @@ +#include + +union { unsigned __l; float __d; } GlobalUnion = { 0x70c00000U }; + +int main() { + union { unsigned __l; float __d; } LocalUnion = { 0x7fc00000U }; + + printf("%f %f\n", GlobalUnion.__d, LocalUnion.__d); + + return 0; +} diff --git a/ir/be/test/llvm/2004-02-03-AggregateCopy.c b/ir/be/test/llvm/2004-02-03-AggregateCopy.c new file mode 100644 index 000000000..69be5618e --- /dev/null +++ b/ir/be/test/llvm/2004-02-03-AggregateCopy.c @@ -0,0 +1,14 @@ +#include + +typedef struct { + int X; +} agg; + +int main() { + agg A; A.X = 123; + agg B, C; + B = C = A; + + printf("%d, %d, %d\n", A.X, B.X, C.X); + return 0; +} diff --git a/ir/be/test/llvm/2004-08-12-InlinerAndAllocas.c b/ir/be/test/llvm/2004-08-12-InlinerAndAllocas.c new file mode 100644 index 000000000..e7030a24e --- /dev/null +++ b/ir/be/test/llvm/2004-08-12-InlinerAndAllocas.c @@ -0,0 +1,26 @@ +// A compiler cannot inline Callee into main unless it is prepared to reclaim +// the stack memory allocated in it. + +#if defined(__FreeBSD__) || defined(__OpenBSD__) +#include +#else +#include +#endif +#include + +static int Callee(int i) { + if (i != 0) { + char *X = alloca(1000); + sprintf(X, "%d\n", i); + return X[0]; + } + return 0; +} + +int main() { + int i, j = 0; + for (i = 0; i < 10000; ++i) + j += Callee(i); + printf("%d\n", j); + return 0; +} diff --git a/ir/be/test/llvm/2005-05-06-LongLongSignedShift.c b/ir/be/test/llvm/2005-05-06-LongLongSignedShift.c new file mode 100644 index 000000000..d2f0c12b2 --- /dev/null +++ b/ir/be/test/llvm/2005-05-06-LongLongSignedShift.c @@ -0,0 +1,5 @@ +int main(int argc, char **argv) { + printf("%lld\n", (argc-100LL) >> 38); + + return 0; +} diff --git a/ir/be/test/llvm/ConstructorDestructorAttributes.c b/ir/be/test/llvm/ConstructorDestructorAttributes.c new file mode 100644 index 000000000..1a5fb9c4d --- /dev/null +++ b/ir/be/test/llvm/ConstructorDestructorAttributes.c @@ -0,0 +1,14 @@ +#include + +void ctor() __attribute__((constructor)); + +void ctor() { + printf("Create!\n"); +} +void dtor() __attribute__((destructor)); + +void dtor() { + printf("Create!\n"); +} + +int main() { return 0; } diff --git a/ir/be/test/llvm/DuffsDevice.c b/ir/be/test/llvm/DuffsDevice.c new file mode 100644 index 000000000..0f9e9610e --- /dev/null +++ b/ir/be/test/llvm/DuffsDevice.c @@ -0,0 +1,38 @@ +/* This silly testcase is here to check that "Duff's Device" works properly + * in LLVM. Guess what, it does. :) + * + * For more info, see: http://www.lysator.liu.se/c/duffs-device.html + */ + +#include + + sum(to, from, count) + register short *to, *from; + register count; + { + register n=(count+7)/8; + switch(count%8){ + case 0: do{ *to += *from++; + case 7: *to += *from++; + case 6: *to += *from++; + case 5: *to += *from++; + case 4: *to += *from++; + case 3: *to += *from++; + case 2: *to += *from++; + case 1: *to += *from++; + }while(--n>0); + } + } + +void main() { + short Array[100]; + short Sum = 0; + int i; + + for (i = 0; i != 100; ++i) + Array[i] = i; + + sum(&Sum, Array, 100); + + printf("Sum is %d\n", Sum); +} diff --git a/ir/be/test/llvm/PR491.c b/ir/be/test/llvm/PR491.c new file mode 100644 index 000000000..c25afc18b --- /dev/null +++ b/ir/be/test/llvm/PR491.c @@ -0,0 +1,30 @@ +#include + +static int assert_fail(const char* s, unsigned l) +{ + fprintf(stderr, "assertion failed in line %u: '%s'\n", l, s); + return 0; +} +#define ASSERT(expr) ((expr) ? 1 : assert_fail(#expr,__LINE__)) + +int test(int r) { +#if !defined(__i386__) + #if !defined(BYTE_ORDER) || !defined(LITTLE_ENDIAN) + return r; + #else + if (BYTE_ORDER != LITTLE_ENDIAN) return r; + #endif +#endif + + /* little endian */ + union { long l; unsigned char c[sizeof(long)]; } u; + u.l = 0; u.c[0] = 0x80; + r &= ASSERT(u.l == 128); + u.l = 0; u.c[sizeof(long)-1] = 0x80; + r &= ASSERT(u.l < 0); + return r; +} + +int main() { + return test(1) == 1; +} diff --git a/ir/be/test/llvm/PR640.c b/ir/be/test/llvm/PR640.c new file mode 100644 index 000000000..7eccdab9a --- /dev/null +++ b/ir/be/test/llvm/PR640.c @@ -0,0 +1,55 @@ +#include +#include + +static int test_stdarg_va(void* p1, ...) +{ + va_list ap; + unsigned long l; + int i1, i2; + void* p2; + va_start(ap, p1); + i1 = va_arg(ap, int); + l = va_arg(ap, unsigned long); + i2 = va_arg(ap, int); + p2 = va_arg(ap, void *); + va_end(ap); + return p1 == p2 && i1 == 1 && l == 0x76214365ul && i2 == 2; +} + + +static int test_stdarg_builtin_va(void* p1, ...) +{ + __builtin_va_list ap; + unsigned long l; + int i1, i2; + void* p2; + __builtin_stdarg_start(ap, p1); + i1 = __builtin_va_arg(ap, int); + l = __builtin_va_arg(ap, unsigned long); + i2 = __builtin_va_arg(ap, int); + p2 = __builtin_va_arg(ap, void *); + __builtin_va_end(ap); + return p1 == p2 && i1 == 1 && l == 0x76214369ul && i2 == 2; +} + + +static int test_stdarg(int r) +{ + char c1 = 1, c2 = 2; + if (test_stdarg_va(&r, c1, 0x76214365ul, c2, &r) != 1) + return 0; + if (test_stdarg_builtin_va(&r, c1, 0x76214369ul, c2, &r) != 1) + return 0; + return r & 1; +} + + +int main(int argc, char **argv) +{ + if (test_stdarg(1) != 1) { + printf("ERROR\n"); + return 1; + } + printf("All done.\n"); + return 0; +} diff --git a/ir/be/test/llvm/badidx.c b/ir/be/test/llvm/badidx.c new file mode 100644 index 000000000..ed9be6abe --- /dev/null +++ b/ir/be/test/llvm/badidx.c @@ -0,0 +1,25 @@ +/* -*- mode: c -*- + * $Id: badidx.c,v 1.1 2002/08/22 03:04:14 vadve Exp $ + * http://www.bagley.org/~doug/shootout/ + * + * this program is modified from: + * http://cm.bell-labs.com/cm/cs/who/bwk/interps/pap.html + * Timing Trials, or, the Trials of Timing: Experiments with Scripting + * and User-Interface Languages by Brian W. Kernighan and + * Christopher J. Van Wyk. + * + * I added free() to deallocate memory. + */ + +#include +#include + +int +main(int argc, char *argv[]) { + int i, n = ((argc == 2) ? atoi(argv[1]) : 1); + int *y = (int *) calloc(n, sizeof(int)); + for (i=0; i < n; i++) + y[i] = i*i; + printf("%d\n", y[n-1]); + return(0); +} diff --git a/ir/be/test/llvm/bigstack.c b/ir/be/test/llvm/bigstack.c new file mode 100644 index 000000000..f372a882e --- /dev/null +++ b/ir/be/test/llvm/bigstack.c @@ -0,0 +1,79 @@ +/*===- test/Regression/Transforms/Scalar/DecomposeMultiDimRefs.cpp -----=* + * + * This is a feature test that checks for correct code generation + * of the SAVE instruction when the stack size does not fit in the + * immediate field of the SAVE instruction. This happens in main(). + *===---------------------------------------------------------------------===*/ + +#include +#include + +typedef struct Flat_struct { + char c; + float x; +} Flat_t; + +typedef struct Mixed_struct { + int N; + double A[10]; + double B[10][10]; + Flat_t F[10]; +} Mixed_t; + + +double +AddMixed(Mixed_t* M) +{ + double sum = 0; + int i, j; + + for (i=0; i < 10; ++i) + sum += M->A[i]; + + for (i=0; i < 10; ++i) + for (j=0; j < 10; ++j) + sum += M->B[i][j]; + + for (i=0; i < 10; ++i) { + sum += (double) M->F[i].c; + sum += M->F[i].x; + } + + return sum; +} + +void +InitializeMixed(Mixed_t* M, int base) +{ + int i, j; + + for (i=0; i < 10; ++i) + M->A[i] = i + base; + + for (i=0; i < 10; ++i) + for (j=0; j < 10; ++j) + M->B[i][j] = i*10 + j + base; + + for (i=0; i < 10; ++i) { + M->F[i].c = 'Q'; + M->F[i].x = i / 10 + base; + } +} + +int +main(int argc, char** argv) +{ + Mixed_t M; + Mixed_t MA[4]; + int i; + + InitializeMixed(&M, 100); + printf("Sum(M) = %.2f\n", AddMixed(&M)); + + for (i=0; i < 4; i++) { + InitializeMixed(&MA[i], 100 * (i+2)); + printf("Sum(MA[%d]) = %.2f\n", i, AddMixed(&MA[i])); + } + + return 0; +} diff --git a/ir/be/test/llvm/callargs.c b/ir/be/test/llvm/callargs.c new file mode 100644 index 000000000..4ca1cfe7f --- /dev/null +++ b/ir/be/test/llvm/callargs.c @@ -0,0 +1,156 @@ +#include +#include + + +#undef LLVM_CAN_PASS_STRUCTS_BY_VALUE +#ifdef LLVM_CAN_PASS_STRUCTS_BY_VALUE +typedef struct SmallStruct_struct { + char c1, c2, c3, c4; + int n; +} SmallStruct; + + +typedef struct BigStruct_struct { + char c1, c2, c3, c4; + double d1, d2; /* Note: d1 will need padding */ + int n; + struct BigStruct_struct* next; /* Note: next will need padding */ +} BigStruct; + + +SmallStruct +printStructArgs(SmallStruct s1, /* Could fit in reg */ + int a1, float a2, char a3, double a4, char* a5, + BigStruct s2, /* Must go on stack */ + int a6, float a7, char a8, double a9, char* a10, + SmallStruct s3, /* Probably no available regs */ + int a11, float a12, char a13, double a14, char* a15) +{ + SmallStruct result; + + printf("\nprintStructArgs with 13 arguments:\n"); + printf("\tArg 1 : %c %c %c %c %d\n", s1.c1, s1.c2, s1.c3, s1.c4, s1.n); + printf("\tArgs 2-6 : %d %f %c %lf %c\n", a1, a2, a3, a4, *a5); + printf("\tArg 7 : %c %c %c %c %lf %lf %d %p\n", + s2.c1, s2.c2, s2.c3, s2.c4, s2.d1, s2.d2, s2.n,s2.next); + printf("\tArg 8 : %c %c %c %c %d\n", s3.c1, s3.c2, s3.c3, s3.c4, s3.n); + printf("\tArgs 9-13 : %d %f %c %lf %c\n", a6, a7, a8, a9, *a10); + printf("\tArgs 14-18: %d %f %c %lf %c\n", a11, a12, a13, a14, *a15); + printf("\n"); + + result.c1 = s2.c1; + result.c2 = s2.c2; + result.c3 = s2.c3; + result.c4 = s2.c4; + result.n = s2.n; + + return result; +} +#endif /* LLVM_CAN_PASS_STRUCTS_BY_VALUE */ + +#undef LLC_SUPPORTS_VARARGS_FUNCTIONS +#ifdef LLC_SUPPORTS_VARARGS_FUNCTIONS +void +printVarArgs(int a1, ...) +{ + double a2, a7, a12; /* float is promoted to double! */ + int a3, a8, a13; /* char is promoted to int! */ + double a4, a9, a14; + char *a5, *a10, *a15; + int a6, a11; + + va_list ap; + va_start(ap, a1); + a2 = va_arg(ap, double); + a3 = va_arg(ap, int); + a4 = va_arg(ap, double); + a5 = va_arg(ap, char*); + + a6 = va_arg(ap, int); + a7 = va_arg(ap, double); + a8 = va_arg(ap, int); + a9 = va_arg(ap, double); + a10 = va_arg(ap, char*); + + a11 = va_arg(ap, int); + a12 = va_arg(ap, double); + a13 = va_arg(ap, int); + a14 = va_arg(ap, double); + a15 = va_arg(ap, char*); + + printf("\nprintVarArgs with 15 arguments:\n"); + printf("\tArgs 1-5 : %d %f %c %f %c\n", a1, a2, a3, a4, *a5); + printf("\tArgs 6-10 : %d %f %c %f %c\n", a6, a7, a8, a9, *a10); + printf("\tArgs 11-14: %d %f %c %f %c\n", a11, a12, a13, a14, *a15); + printf("\n"); + return; +} +#endif /* LLC_SUPPORTS_VARARGS_FUNCTIONS */ + + +void +printArgsNoRet(int a1, float a2, char a3, double a4, char* a5, + int a6, float a7, char a8, double a9, char* a10, + int a11, float a12, char a13, double a14, char* a15) +{ + printf("\nprintArgsNoRet with 15 arguments:\n"); + printf("\tArgs 1-5 : %d %f %c %f %c\n", a1, a2, a3, a4, *a5); + printf("\tArgs 6-10 : %d %f %c %f %c\n", a6, a7, a8, a9, *a10); + printf("\tArgs 11-14: %d %f %c %f %c\n", a11, a12, a13, a14, *a15); + printf("\n"); + return; +} + + +int +main(int argc, char** argv) +{ +#ifdef LLVM_CAN_PASS_STRUCTS_BY_VALUE + SmallStruct s1, s3, result; + BigStruct s2; +#endif /* LLVM_CAN_PASS_STRUCTS_BY_VALUE */ + + printArgsNoRet(1, 2.1, 'c', 4.1, "e", + 6, 7.1, 'h', 9.1, "j", + 11, 12.1, 'm', 14.1, "o"); + +#ifdef LLC_SUPPORTS_VARARGS_FUNCTIONS + printVarArgs(1, 2.2, 'c', 4.2, "e", + 6, 7.2, 'h', 9.2, "j", + 11, 12.2, 'm', 14.2, "o"); +#endif /* LLC_SUPPORTS_VARARGS_FUNCTIONS */ + +#ifdef LLVM_CAN_PASS_STRUCTS_BY_VALUE + s1.c1 = 'a'; + s1.c2 = 'b'; + s1.c3 = 'c'; + s1.c4 = 'd'; + s1.n = 111; + + s2.c1 = 'h'; + s2.c2 = 'i'; + s2.c3 = 'j'; + s2.c4 = 'k'; + s2.d1 = 1.1; + s2.d2 = 2.2; + s2.n = 222; + s2.next = &s2; + + s3.c1 = 'w'; + s3.c2 = 'x'; + s3.c3 = 'y'; + s3.c4 = 'z'; + s3.n = 333; + + result = printStructArgs(s1, + 1, 2.0, 'c', 4.0, "e", + s2, + 6, 7.0, 'h', 9.0, "j", + s3); + + printf("\nprintStructArgs returns:\n\t%c %c %c %c %d\n\n", + result.c1, result.c2, result.c3, result.c4, result.n); +#endif /* LLVM_CAN_PASS_STRUCTS_BY_VALUE */ + + return 0; +} diff --git a/ir/be/test/llvm/casts.c b/ir/be/test/llvm/casts.c new file mode 100644 index 000000000..14478b549 --- /dev/null +++ b/ir/be/test/llvm/casts.c @@ -0,0 +1,138 @@ +#include +#include + +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif +#include + + +static int64_t lls[] = { + 123ULL, -1LL, -14LL, 14, 1ULL << 63, 0 +}; + +int +main(int argc, char** argv) +{ + int8_t C, c1; + uint8_t uc1; + + short S, s1; + unsigned short us1; + + int i1, i; + unsigned ui1; + + long L, l1; + unsigned long ul1; + + float F; + double D; + + /* input values */ + C = (char) (argc >= 2)? atoi(argv[1]) : 0x64; /* 100 = 'd' */ + S = (short) (argc >= 3)? atoi(argv[2]) : -769; /* 0xfcff = -769 */ + L = (long) (argc >= 4)? atoi(argv[3]) : 0xa3a3a3a3a3a3; /*179923220407203*/ + + /* Test integer to integer conversions */ + uc1 = (uint8_t) C; /* 100 = 'd' */ + us1 = (unsigned short) C; /* 100 = 'd' */ + ui1 = (unsigned int) C; /* 100 = 'd' */ + ul1 = (unsigned long) C; /* 100 = 'd' */ + + s1 = (short) C; /* 100 = 'd' */ + i1 = (int) C; /* 100 = 'd' */ + l1 = (long) C; /* 100 = 'd' */ + + printf("\nCHAR C = '%c' (%d)\t\t(0x%x)\n", C, C, C); + printf("char to short s1 = %d\t\t(0x%x)\n", s1, s1); + printf("char to int i1 = %d\t\t(0x%x)\n", i1, i1); + printf("char to long l1 = %ld\t\t(0x%lx)\n", l1, l1); + + printf("\nchar to ubyte uc1 = %u\t\t(0x%x)\n", uc1, uc1); + printf("char to ushort us1 = %u\t\t(0x%x)\n", us1, us1); + printf("char to uint ui1 = %u\t\t(0x%x)\n", ui1, ui1); + printf("char to ulong ul1 = %lu\t\t(0x%lx)\n", ul1, ul1); + + uc1 = (uint8_t) S; /* 0xff = 255 */ + us1 = (unsigned short) S; /* 0xfcff = 64767 */ + ui1 = (unsigned int) S; /* 0xfffffcff = 4294966527 */ + ul1 = (unsigned long) S; /* */ + + c1 = (int8_t) S; /* 0xff = -1 */ + i1 = (int) S; /* 0xfffffcff = -769 */ + l1 = (long) S; /* */ + + printf("\n\nSHORT S = %d\t\t(0x%x)\n", S, S); + printf("short to byte c1 = %d\t\t(0x%x)\n", c1, c1); + printf("short to int i1 = %d\t\t(0x%x)\n", i1, i1); + printf("short to long l1 = %ld\t\t(0x%lx)\n", l1, l1); + + printf("\nshort to ubyte uc1 = %u\t\t(0x%x)\n", uc1, uc1); + printf("short to ushort us1 = %u\t\t(0x%x)\n", us1, us1); + printf("short to uint ui1 = %u\t\t(0x%x)\n", ui1, ui1); + printf("short to ulong ul1 = %lu\t\t(0x%lx)\n", ul1, ul1); + + uc1 = (unsigned char) L; /* */ + c1 = (int8_t) L; /* */ + s1 = (short) L; /* */ + us1 = (unsigned short) L; /* */ + i1 = (int) L; /* */ + ui1 = (unsigned int) L; /* */ + ul1 = (unsigned long) L; /* */ + + printf("\n\nLONG L = %ld\t\t(0x%lx)\n", L, L); + printf("long to byte c1 = %d\t\t(0x%x)\n", c1, c1); + printf("long to short s1 = %d\t\t(0x%x)\n", s1, s1); + printf("long to int i1 = %d\t\t(0x%x)\n", i1, i1); + + printf("\nlong to ubyte uc1 = %u\t\t(0x%x)\n", uc1, uc1); + printf("long to ushort us1 = %u\t\t(0x%x)\n", us1, us1); + printf("long to uint ui1 = %u\t\t(0x%x)\n", ui1, ui1); + printf("long to ulong ul1 = %lu\t\t(0x%lx)\n", ul1, ul1); + + /* Test floating-point to integer conversions */ + F = (float) (argc >= 4)? atof(argv[3]) : 1.0; + D = (argc >= 5)? atof(argv[4]) : 2.0; + + us1 = (unsigned short) F; + ui1 = (unsigned int) F; + ul1 = (unsigned long) F; + + s1 = (short) F; + i1 = (int) F; + l1 = (long) F; + + printf("\n\nFLOAT F = %f\n", F); + printf("float to short s1 = %d\t\t(0x%x)\n", s1, s1); + printf("float to int i1 = %d\t\t(0x%x)\n", i1, i1); + + printf("float to ushort us1 = %u\t\t(0x%x)\n", us1, us1); + printf("float to uint ui1 = %u\t\t(0x%x)\n", ui1, ui1); + printf("float to ulong ul1 = %lu\t\t(0x%lx)\n", ul1, ul1); + + us1 = (unsigned short) D; + ui1 = (unsigned int) D; + ul1 = (unsigned long) D; + + s1 = (short) D; + i1 = (int) D; + l1 = (long) D; + + printf("\n\nDOUBLE D = %f\n", D); + printf("double to short s1 = %d\t\t(0x%x)\n", s1, s1); + printf("double to int i1 = %d\t\t(0x%x)\n", i1, i1); + printf("double to long l1 = %ld\t\t(0x%lx)\n", l1, l1); + + printf("double to ushort us1 = %u\t\t(0x%x)\n", us1, us1); + printf("double to uint ui1 = %u\t\t(0x%x)\n", ui1, ui1); + printf("double to ulong ul1 = %lu\t\t(0x%lx)\n", ul1, ul1); + + for (i = 0; lls[i]; ++i) { + printf("double <- long long %lld = %f\n", lls[i], (double)lls[i]); + printf("double <- unsigned long long %llu = %f\n", + (unsigned long long)lls[i], (double)(unsigned long long)lls[i]); + } + + return 0; +} diff --git a/ir/be/test/llvm/globalrefs.c b/ir/be/test/llvm/globalrefs.c new file mode 100644 index 000000000..e4247a93f --- /dev/null +++ b/ir/be/test/llvm/globalrefs.c @@ -0,0 +1,64 @@ +/* globalrefs.c - Test symbolic constant expressions constructed from + * global addresses and index expressions into global addresses. + * Do this both with global constants and with inline constant. + * Instead of printing absolute addresses, print out the differences in + * memory addresses to get output that matches that of the native compiler. + */ + +#include + +#define __STDC_LIMIT_MACROS 1 +#include + +struct test { + long A; + struct { unsigned X; unsigned Y; } S; + struct test* next; +}; + +struct test TestArray[10]; +struct test Test1; + +/* Create global symbolic constants from the addresses of the above globals */ + +struct test* TestArrayPtr = &TestArray[3]; +long* Aptr = &Test1.A; +unsigned* Yptr = &Test1.S.Y; +struct test** NextPtr = &Test1.next; + +void +printdiff(void* p1, void* p2) +{ + printf(" %d", (int)((unsigned long) p1 - (unsigned long) p2)); +} + +int +main(int argc, char** argv) +{ + unsigned long diff1, diff2, diff3, diff4; + + printf("sizeof(struct Test) = %d\n\n", (int)sizeof(struct test)); + + printdiff(&TestArray[3], TestArray); + printdiff(&Test1.S.Y, &Test1.A); + printdiff(&Test1.next, &Test1.S.Y); + printf("\n"); + + diff1 = (unsigned long) &TestArray[3] - (unsigned long) TestArray; + diff3 = (unsigned long) &Test1.S.Y - (unsigned long) &Test1.A; + diff4 = (unsigned long) &Test1.next - (unsigned long) &Test1.S.Y; + + printf("&TestArray[3] - TestArray = 0x%lx\n", diff1); + printf("Xptr - Aptr = 0x%lx\n", diff3); + printf("NextPtr - Xptr = 0x%lx\n\n", diff4); + + diff1 = (unsigned long) TestArrayPtr - (unsigned long) TestArray; + diff3 = (unsigned long) Yptr - (unsigned long) Aptr; + diff4 = (unsigned long) NextPtr - (unsigned long) Yptr; + + printf("&TestArray[3] - TestArray = 0x%lx\n", diff1); + printf("Xptr - Aptr = 0x%lx\n", diff3); + printf("NextPtr - Xptr = 0x%lx\n\n", diff4); + + return 0; +} diff --git a/ir/be/test/llvm/matrixTranspose.c b/ir/be/test/llvm/matrixTranspose.c new file mode 100644 index 000000000..9d6f94761 --- /dev/null +++ b/ir/be/test/llvm/matrixTranspose.c @@ -0,0 +1,46 @@ +typedef float fftw_real; + +void complex_transpose(fftw_real *rA, fftw_real *iA, int n, int is, int js) +{ + int i, j; + + for (i = 1; i < n; ++i) { + for (j = 0; j < i; ++j) { + fftw_real ar, ai, br, bi; + + ar = rA[i * is + j * js]; + ai = iA[i * is + j * js]; + br = rA[j * is + i * js]; + bi = iA[j * is + i * js]; + + rA[j * is + i * js] = ar; + iA[j * is + i * js] = ai; + rA[i * is + j * js] = br; + iA[i * is + j * js] = bi; + } + } +} + +fftw_real A[2048]; +int main(int argc, char **argv) +{ + int i; + + fftw_real sum = 0.0; + for (i = 0; i < 2048; ++i) { + A[i] = i; + sum = sum + A[i]; + } + printf("Checksum before = %lf\n", sum); + + for (i = 0; i < 10; ++i) { + complex_transpose(A, A+1, 32, 2, 64); + } + + sum = 0.0; + for (i = 0; i < 2048; ++i) + sum = sum + A[i]; + printf("Checksum after = %lf\n", sum); + + return 0; +} diff --git a/ir/be/test/llvm/pointer_arithmetic.c b/ir/be/test/llvm/pointer_arithmetic.c new file mode 100644 index 000000000..d716c9ed4 --- /dev/null +++ b/ir/be/test/llvm/pointer_arithmetic.c @@ -0,0 +1,20 @@ +typedef struct { + int w; +// float x; +// double y; +// long long z; +} S1Ty; + +typedef struct { + S1Ty A, B; +} S2Ty; + +void takeS1(S1Ty *V) {} +void takeVoid(void *P) {} + +int main() { + S2Ty E; + takeS1(&E.B); + takeVoid(&E); + return 0; +} diff --git a/ir/be/test/llvm/sumarray.c b/ir/be/test/llvm/sumarray.c new file mode 100644 index 000000000..e54a53056 --- /dev/null +++ b/ir/be/test/llvm/sumarray.c @@ -0,0 +1,25 @@ +#include +#include + +int SumArray(int Array[], int Num) { + unsigned i, Result = 0; + Array[34] = 1234; + + for (i = 0; i < Num; ++i) + Result += Array[i]; + + return Result; +} + +int main() { + int *Array = (int*)malloc(sizeof(int)*100); + int i; + + for (i = 0; i < 100; i += 2) + Array[i] = i*4; + for (i = 1; i < 100; i += 2) + Array[i] = i*2; + + printf("Produced: %d\n", SumArray(Array, 100)); + return 0; +} diff --git a/ir/be/test/llvm/sumarray2d.c b/ir/be/test/llvm/sumarray2d.c new file mode 100644 index 000000000..297d7e750 --- /dev/null +++ b/ir/be/test/llvm/sumarray2d.c @@ -0,0 +1,29 @@ +#include + +int SumArray(int Array[][100], unsigned int NumI, unsigned int NumJ) { + unsigned i, j; + int Result = 0; + + for (i = 0; i < NumI; i++) + for (j = 0; j < NumJ; j++) + Result += Array[i][j]; + + return Result; +} + +int main() { + int Array[100][100]; + unsigned int i, j; + + for (i = 0; i < 100; i++) + Array[i][i] = -i; + + for (i = 0; i < 100; i++) + for (j = 0; j < 100; j++) + if (j != i) + Array[i][j] = i+j; + + printf("Sum(Array[%d,%d] = %d\n", 100, 100, SumArray(Array, 100, 100)); + + return 0; +} diff --git a/ir/be/test/llvm/sumarraymalloc.c b/ir/be/test/llvm/sumarraymalloc.c new file mode 100644 index 000000000..3e7685804 --- /dev/null +++ b/ir/be/test/llvm/sumarraymalloc.c @@ -0,0 +1,44 @@ +#include +#include + +#define SIZE 100 + +static int SumArray(int *Array, unsigned Num) { + int Result = 0; + unsigned i; + for (i = 0; i < Num; ++i) + Result += Array[i]; + + return Result; +} + +static int SumArray2(int *Array, unsigned Num) { + int Result = 0; + unsigned i; + for (i = 0; i < Num; ++i) + Result += *Array++; + + return Result; +} + +static void FillArray(int *Array, unsigned Num) { + unsigned i; + for (i = 0; i < Num; ++i) + Array[i] = i; +} + +int +main(int argc, char** argv) +{ + int size; + int *MyArray; + + size = (argc < 2)? SIZE : atoi(argv[1]); + MyArray = malloc(sizeof(int)* size); + + FillArray(MyArray, size); + printf("Sum1 = %d\n", SumArray(MyArray, SIZE)); + printf("Sum2 = %d\n", SumArray2(MyArray, SIZE)); + free(MyArray); + return(0); +} diff --git a/ir/be/test/llvm/test_indvars.c b/ir/be/test/llvm/test_indvars.c new file mode 100644 index 000000000..b98d65a52 --- /dev/null +++ b/ir/be/test/llvm/test_indvars.c @@ -0,0 +1,36 @@ + +#include + +static void test_indvars(int *Array1, int Array2[100][200]) { + unsigned i, j; + Array1[1] = Array2[3][6] = 12345; + + for (i = 0; i < 100; i+=2) + Array1[i] = i; /* Step by non unit amount */ + + for (i = 3; i < 103; i++) + Array1[i] = i+4; /* Step with an offset */ + + for (i = 13; i < 100; i++) + for (j = 0; j < 100; j+=3) /* 2d array access */ + Array2[i][j/3] = Array2[i][i]; +} + + +int main() { + int Array[100][200], i, j; + double sum = 0.0; + + for (i=0; i < 100; i+=2) + for (j=0; j < 200; j++) + Array[i][j] = 0; + test_indvars(Array[0], Array); + + for (i=0; i < 100; i+=2) + for (j=0; j < 200; j++) + sum += Array[i][j]; + + printf("Checksum = %.0lf\n", sum); + + return 0; +} diff --git a/ir/be/test/llvm/testtrace.c b/ir/be/test/llvm/testtrace.c new file mode 100644 index 000000000..2ed3e1c09 --- /dev/null +++ b/ir/be/test/llvm/testtrace.c @@ -0,0 +1,44 @@ +#include + +/* + * Test routines for testing the tracing code. + */ + +struct DummyStruct { + struct DummyStruct* next; + int seqnum; +}; + +int +AddCounts(struct DummyStruct* S1, + struct DummyStruct* S2, + struct DummyStruct* S3, int noPrint) +{ + if (!noPrint) + printf("&S1 = %p\t&S2 = %p\t&S3 = %p\n", S1, S2, S3); + return S1->seqnum + S2->seqnum + S3->seqnum; +} + +void +testAllocaOrder(int noPrint) +{ + static int count = 0; + struct DummyStruct S1, S2, S3; + + S1.seqnum = ++count; + S2.seqnum = ++count; + S3.seqnum = ++count; + + printf("sum = %d\n", AddCounts(&S1, &S2, &S3, noPrint)); +} + +int +main(int argc, char** argv) +{ + unsigned int i, noPrint = 1; + if (argc > 1 && ! strcmp(argv[1], "-d")) + noPrint = 0; + for (i=0; i < 10; ++i) + testAllocaOrder(noPrint); + return 0; +} diff --git a/ir/be/test/makereport.sh b/ir/be/test/makereport.sh index 3fecc1b2a..29c1a8e2d 100755 --- a/ir/be/test/makereport.sh +++ b/ir/be/test/makereport.sh @@ -12,7 +12,7 @@ fi ECC="eccp" ECC_CFLAGS="${ADDCFLAGS} -O3 -c -D__builtin_memcpy=memcpy -D__builtin_memset=memset -D__builtin_strlen=strlen -D__builtin_strcpy=strcpy -D__builtin_strcmp=strcmp -DNO_TRAMPOLINES" -GCC="icc" +GCC="gcc" GCC_CFLAGS="-O0 -Itcc" LINKFLAGS="-lm" TIMEOUT_COMPILE=300 -- 2.20.1