From 1e39a958c01130ef36666fa3b740b5b806e949b1 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 18 Oct 2001 21:50:39 +0000 Subject: [PATCH] Add new testcase from C source git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@906 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/fib2.c | 22 +++++++++++++++++ test/fib2.ll | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 test/fib2.c create mode 100644 test/fib2.ll diff --git a/test/fib2.c b/test/fib2.c new file mode 100644 index 00000000000..7ce545e92bc --- /dev/null +++ b/test/fib2.c @@ -0,0 +1,22 @@ +/* -*- mode: c -*- + * $Id$ + * http://www.bagley.org/~doug/shootout/ + */ + +int atoi(char *); +void printf(char *, unsigned long); + +unsigned long +fib(unsigned long n) { + if (n < 2) + return(1); + else + return(fib(n-2) + fib(n-1)); +} + +int +main(int argc, char *argv[]) { + int N = ((argc == 2) ? atoi(argv[1]) : 15); + printf("%ld\n", fib(N)); + return(0); +} diff --git a/test/fib2.ll b/test/fib2.ll new file mode 100644 index 00000000000..f91c6d967d1 --- /dev/null +++ b/test/fib2.ll @@ -0,0 +1,69 @@ +%__intern_LC0 = constant [sbyte] c"fib returned: " +%__intern_LC1 = constant [sbyte] c"\0A\00" + +implementation + +declare void "__main"() + +declare int "atoi"(sbyte *) + +declare void "printVal"([sbyte] *) +declare void "printVal"(uint) + +int "main"(int %argc, sbyte * * %argv) +begin +bb1: ;[#uses=1] + call void () * %__main( ) + %cond1003 = setne int %argc, 2 ; [#uses=1] + br bool %cond1003, label %bb4, label %bb2 + +bb2: ;[#uses=2] + %cast1006 = cast ulong 8 to sbyte * * ; [#uses=1] + %reg1004 = add sbyte * * %argv, %cast1006 ; [#uses=1] + %reg110 = load sbyte * * %reg1004 ; [#uses=1] + %reg109 = call int (sbyte *) * %atoi( sbyte * %reg110 ) ; [#uses=1] + br label %bb4 + +bb4: ;[#uses=3] + %reg126 = phi int [ %reg109, %bb2 ], [ 15, %bb1 ] ; [#uses=3] + %cast1007 = cast int %reg126 to uint ; [#uses=1] + %cond1005 = setgt uint %cast1007, 1 ; [#uses=1] + br bool %cond1005, label %bb6, label %bb7 + +bb6: ;[#uses=2] + %reg115 = add int %reg126, -2 ; [#uses=1] + %cast1008 = cast int %reg115 to uint ; [#uses=1] + %reg116 = call uint (uint) * %fib( uint %cast1008 ) ; [#uses=1] + %reg118 = add int %reg126, -1 ; [#uses=1] + %cast1009 = cast int %reg118 to uint ; [#uses=1] + %reg119 = call uint (uint) * %fib( uint %cast1009 ) ; [#uses=1] + %reg127 = add uint %reg116, %reg119 ; [#uses=1] + br label %bb7 + +bb7: ;[#uses=2] + %reg128 = phi uint [ %reg127, %bb6 ], [ 1, %bb4 ] ; [#uses=1] + call void %printVal([sbyte] * %__intern_LC0) + call void %printVal(uint %reg128 ) + call void %printVal([sbyte] * %__intern_LC1) + ret int 0 +end + +uint "fib"(uint %n) +begin +bb1: ;[#uses=0] + %cond1000 = setgt uint %n, 1 ; [#uses=1] + br bool %cond1000, label %bb3, label %bb2 + +bb2: ;[#uses=1] + ret uint 1 + +bb3: ;[#uses=1] + %cast1001 = cast long -2 to uint ; [#uses=1] + %reg112 = add uint %n, %cast1001 ; [#uses=1] + %reg113 = call uint (uint) * %fib( uint %reg112 ) ; [#uses=1] + %cast1002 = cast long -1 to uint ; [#uses=1] + %reg115 = add uint %n, %cast1002 ; [#uses=1] + %reg116 = call uint (uint) * %fib( uint %reg115 ) ; [#uses=1] + %reg110 = add uint %reg113, %reg116 ; [#uses=1] + ret uint %reg110 +end