diff options
author | ed <ed@FreeBSD.org> | 2009-06-02 17:52:33 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2009-06-02 17:52:33 +0000 |
commit | 3277b69d734b9c90b44ebde4ede005717e2c3b2e (patch) | |
tree | 64ba909838c23261cace781ece27d106134ea451 /test/Feature | |
download | FreeBSD-src-3277b69d734b9c90b44ebde4ede005717e2c3b2e.zip FreeBSD-src-3277b69d734b9c90b44ebde4ede005717e2c3b2e.tar.gz |
Import LLVM, at r72732.
Diffstat (limited to 'test/Feature')
55 files changed, 1362 insertions, 0 deletions
diff --git a/test/Feature/README.txt b/test/Feature/README.txt new file mode 100644 index 0000000..5947bb2 --- /dev/null +++ b/test/Feature/README.txt @@ -0,0 +1,6 @@ +This directory contains test cases for individual source features of LLVM. +It is designed to make sure that the major components of LLVM support all of the +features of LLVM, for very small examples. Entire programs should not go here. + +Regression tests for individual bug fixes should go into the test/Regression dir. + diff --git a/test/Feature/aliases.ll b/test/Feature/aliases.ll new file mode 100644 index 0000000..d44dff4 --- /dev/null +++ b/test/Feature/aliases.ll @@ -0,0 +1,32 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +@bar = external global i32 +@foo1 = alias i32* @bar +@foo2 = alias i32* @bar +@foo3 = alias i32* @foo2 + +%FunTy = type i32() + +declare i32 @foo_f() +@bar_f = alias weak %FunTy* @foo_f +@bar_ff = alias i32()* @bar_f + +@bar_i = alias internal i32* @bar + +@A = alias bitcast (i32* @bar to i64*) + +define i32 @test() { +entry: + %tmp = load i32* @foo1 + %tmp1 = load i32* @foo2 + %tmp0 = load i32* @bar_i + %tmp2 = call i32 @foo_f() + %tmp3 = add i32 %tmp, %tmp2 + %tmp4 = call %FunTy* @bar_f() + %tmp5 = add i32 %tmp3, %tmp4 + %tmp6 = add i32 %tmp1, %tmp5 + %tmp7 = add i32 %tmp6, %tmp0 + ret i32 %tmp7 +} diff --git a/test/Feature/alignment.ll b/test/Feature/alignment.ll new file mode 100644 index 0000000..409efeb --- /dev/null +++ b/test/Feature/alignment.ll @@ -0,0 +1,21 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +@X = global i32 4, align 16 ; <i32*> [#uses=0] + +define i32* @test() align 32 { + %X = alloca i32, align 4 ; <i32*> [#uses=1] + %Y = alloca i32, i32 42, align 16 ; <i32*> [#uses=0] + %Z = alloca i32 ; <i32*> [#uses=0] + ret i32* %X +} + +define i32* @test2() { + %X = malloc i32, align 4 ; <i32*> [#uses=1] + %Y = malloc i32, i32 42, align 16 ; <i32*> [#uses=0] + %Z = malloc i32 ; <i32*> [#uses=0] + %T = malloc i32, align 256 ; <i32*> [#uses=0] + ret i32* %X +} + diff --git a/test/Feature/basictest.ll b/test/Feature/basictest.ll new file mode 100644 index 0000000..2303b59 --- /dev/null +++ b/test/Feature/basictest.ll @@ -0,0 +1,31 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +; Test "stripped" format where nothing is symbolic... this is how the bytecode +; format looks anyways (except for negative vs positive offsets)... +; + +define void @void(i32, i32) { + add i32 0, 0 ; <i32>:3 [#uses=2] + sub i32 0, 4 ; <i32>:4 [#uses=2] + br label %5 + +; <label>:5 ; preds = %5, %2 + add i32 %0, %1 ; <i32>:6 [#uses=2] + sub i32 %6, %4 ; <i32>:7 [#uses=1] + icmp sle i32 %7, %3 ; <i1>:8 [#uses=1] + br i1 %8, label %9, label %5 + +; <label>:9 ; preds = %5 + add i32 %0, %1 ; <i32>:10 [#uses=0] + sub i32 %6, %4 ; <i32>:11 [#uses=1] + icmp sle i32 %11, %3 ; <i1>:12 [#uses=0] + ret void +} + +; This function always returns zero +define i32 @zarro() { +Startup: + ret i32 0 +} diff --git a/test/Feature/callingconventions.ll b/test/Feature/callingconventions.ll new file mode 100644 index 0000000..d2e9de4 --- /dev/null +++ b/test/Feature/callingconventions.ll @@ -0,0 +1,50 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +define fastcc void @foo() { + ret void +} + +define coldcc void @bar() { + call fastcc void @foo( ) + ret void +} + +define void @structret({ i8 }* sret %P) { + call void @structret( { i8 }* sret %P ) + ret void +} + +define void @foo2() { + ret void +} + +define coldcc void @bar2() { + call fastcc void @foo( ) + ret void +} + +define cc42 void @bar3() { + invoke fastcc void @foo( ) + to label %Ok unwind label %U + +Ok: ; preds = %0 + ret void + +U: ; preds = %0 + unwind +} + +define void @bar4() { + call cc42 void @bar( ) + invoke cc42 void @bar3( ) + to label %Ok unwind label %U + +Ok: ; preds = %0 + ret void + +U: ; preds = %0 + unwind +} + diff --git a/test/Feature/calltest.ll b/test/Feature/calltest.ll new file mode 100644 index 0000000..feafd3c --- /dev/null +++ b/test/Feature/calltest.ll @@ -0,0 +1,32 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +%FunTy = type i32 (i32) + +declare i32 @test(i32) ; Test forward declaration merging + +define void @invoke(%FunTy* %x) { + %foo = call i32 %x( i32 123 ) ; <i32> [#uses=0] + %foo2 = tail call i32 %x( i32 123 ) ; <i32> [#uses=0] + ret void +} + +define i32 @main(i32 %argc) { + %retval = call i32 @test( i32 %argc ) ; <i32> [#uses=2] + %two = add i32 %retval, %retval ; <i32> [#uses=1] + %retval2 = invoke i32 @test( i32 %argc ) + to label %Next unwind label %Error ; <i32> [#uses=1] + +Next: ; preds = %0 + %two2 = add i32 %two, %retval2 ; <i32> [#uses=1] + call void @invoke( %FunTy* @test ) + ret i32 %two2 + +Error: ; preds = %0 + ret i32 -1 +} + +define i32 @test(i32 %i0) { + ret i32 %i0 +} diff --git a/test/Feature/casttest.ll b/test/Feature/casttest.ll new file mode 100644 index 0000000..d9c22ff --- /dev/null +++ b/test/Feature/casttest.ll @@ -0,0 +1,12 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +define i16 @FunFunc(i64 %x, i8 %z) { +bb0: + %cast110 = sext i8 %z to i16 ; <i16> [#uses=1] + %cast10 = trunc i64 %x to i16 ; <i16> [#uses=1] + %reg109 = add i16 %cast110, %cast10 ; <i16> [#uses=1] + ret i16 %reg109 +} + diff --git a/test/Feature/cfgstructures.ll b/test/Feature/cfgstructures.ll new file mode 100644 index 0000000..e667f6d --- /dev/null +++ b/test/Feature/cfgstructures.ll @@ -0,0 +1,53 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +;; This is an irreducible flow graph +define void @irreducible(i1 %cond) { + br i1 %cond, label %X, label %Y + +X: ; preds = %Y, %0 + br label %Y + +Y: ; preds = %X, %0 + br label %X +} + +;; This is a pair of loops that share the same header +define void @sharedheader(i1 %cond) { + br label %A + +A: ; preds = %Y, %X, %0 + br i1 %cond, label %X, label %Y + +X: ; preds = %A + br label %A + +Y: ; preds = %A + br label %A +} + + +;; This is a simple nested loop +define void @nested(i1 %cond1, i1 %cond2, i1 %cond3) { + br label %Loop1 + +Loop1: ; preds = %L2Exit, %0 + br label %Loop2 + +Loop2: ; preds = %L3Exit, %Loop1 + br label %Loop3 + +Loop3: ; preds = %Loop3, %Loop2 + br i1 %cond3, label %Loop3, label %L3Exit + +L3Exit: ; preds = %Loop3 + br i1 %cond2, label %Loop2, label %L2Exit + +L2Exit: ; preds = %L3Exit + br i1 %cond1, label %Loop1, label %L1Exit + +L1Exit: ; preds = %L2Exit + ret void +} + diff --git a/test/Feature/constexpr.ll b/test/Feature/constexpr.ll new file mode 100644 index 0000000..13e6f36 --- /dev/null +++ b/test/Feature/constexpr.ll @@ -0,0 +1,80 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +; This testcase is for testing expressions constructed from +; constant values, including constant pointers to globals. +; + +;;------------------------------- +;; Test constant cast expressions +;;------------------------------- + +global i64 u0x00001 ; hexadecimal unsigned integer constants +global i64 s0x0012312 ; hexadecimal signed integer constants + +@t2 = global i32* @t1 ;; Forward reference without cast +@t3 = global i32* bitcast (i32* @t1 to i32*) ;; Forward reference with cast +@t1 = global i32 4 ;; i32* @0 +@t4 = global i32** bitcast (i32** @t3 to i32**) ;; Cast of a previous cast +@t5 = global i32** @t3 ;; Reference to a previous cast +@t6 = global i32*** @t4 ;; Different ref. to a previous cast +@t7 = global float* inttoptr (i32 12345678 to float*) ;; Cast ordinary value to ptr +@t9 = global i32 bitcast (float bitcast (i32 8 to float) to i32) ;; Nested cast expression + +global i32* bitcast (float* @4 to i32*) ;; Forward numeric reference +global float* @4 ;; Duplicate forward numeric reference +global float 0.0 + + +;;--------------------------------------------------- +;; Test constant getelementpr expressions for arrays +;;--------------------------------------------------- + +@array = constant [2 x i32] [ i32 12, i32 52 ] +@arrayPtr = global i32* getelementptr ([2 x i32]* @array, i64 0, i64 0) ;; i32* &@array[0][0] +@arrayPtr5 = global i32** getelementptr (i32** @arrayPtr, i64 5) ;; i32* &@arrayPtr[5] + +@somestr = constant [11x i8] c"hello world" +@char5 = global i8* getelementptr([11x i8]* @somestr, i64 0, i64 5) + +;; cast of getelementptr +@char8a = global i32* bitcast (i8* getelementptr([11x i8]* @somestr, i64 0, i64 8) to i32*) + +;; getelementptr containing casts +@char8b = global i8* getelementptr([11x i8]* @somestr, i64 sext (i8 0 to i64), i64 sext (i8 8 to i64)) + +;;------------------------------------------------------- +;; TODO: Test constant getelementpr expressions for structures +;;------------------------------------------------------- + +%SType = type { i32 , {float, {i8} }, i64 } ;; struct containing struct +%SAType = type { i32 , {[2x float], i64} } ;; struct containing array + +@S1 = global %SType* null ;; Global initialized to NULL +@S2c = constant %SType { i32 1, {float,{i8}} {float 2.0, {i8} {i8 3}}, i64 4} + +@S3c = constant %SAType { i32 1, {[2x float], i64} {[2x float] [float 2.0, float 3.0], i64 4} } + +@S1ptr = global %SType** @S1 ;; Ref. to global S1 +@S2 = global %SType* @S2c ;; Ref. to constant S2 +@S3 = global %SAType* @S3c ;; Ref. to constant S3 + + ;; Pointer to float (**@S1).1.0 +@S1fld1a = global float* getelementptr (%SType* @S2c, i64 0, i32 1, i32 0) + ;; Another ptr to the same! +@S1fld1b = global float* getelementptr (%SType* @S2c, i64 0, i32 1, i32 0) + +@S1fld1bptr = global float** @S1fld1b ;; Ref. to previous pointer + + ;; Pointer to i8 (**@S2).1.1.0 +@S2fld3 = global i8* getelementptr (%SType* @S2c, i64 0, i32 1, i32 1, i32 0) + + ;; Pointer to float (**@S2).1.0[0] +;@S3fld3 = global float* getelementptr (%SAType** @S3, i64 0, i64 0, i32 1, i32 0, i64 0) + +;;--------------------------------------------------------- +;; TODO: Test constant expressions for unary and binary operators +;;--------------------------------------------------------- + +;;--------------------------------------------------- diff --git a/test/Feature/constpointer.ll b/test/Feature/constpointer.ll new file mode 100644 index 0000000..5c1bed1 --- /dev/null +++ b/test/Feature/constpointer.ll @@ -0,0 +1,31 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +; This testcase is primarily used for testing that global values can be used as +; constant pointer initializers. This is tricky because they can be forward +; declared and involves an icky bytecode encoding. There is no meaningful +; optimization that can be performed on this file, it is just here to test +; assembly and disassembly. +; + + +@t3 = global i32* @t1 ;; Forward reference +@t1 = global i32 4 +@t4 = global i32** @t3 ;; reference to reference + +@t2 = global i32* @t1 + +global float * @2 ;; Forward numeric reference +global float * @2 ;; Duplicate forward numeric reference +global float 0.0 +global float * @2 ;; Numeric reference + + +@fptr = global void() * @f ;; Forward ref method defn +declare void @f() ;; External method + +@sptr1 = global [11x i8]* @somestr ;; Forward ref to a constant +@somestr = constant [11x i8] c"hello world" +@sptr2 = global [11x i8]* @somestr + diff --git a/test/Feature/dg.exp b/test/Feature/dg.exp new file mode 100644 index 0000000..f200589 --- /dev/null +++ b/test/Feature/dg.exp @@ -0,0 +1,3 @@ +load_lib llvm.exp + +RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]] diff --git a/test/Feature/embeddedmetadata.ll b/test/Feature/embeddedmetadata.ll new file mode 100644 index 0000000..75977c0 --- /dev/null +++ b/test/Feature/embeddedmetadata.ll @@ -0,0 +1,11 @@ +; RUN: llvm-as < %s | llvm-dis | not grep undef + +declare i8 @llvm.something(metadata %a) + +@llvm.foo = internal constant metadata !{i17 123, null, metadata !"foobar"} + +define void @foo() { + %x = call i8 @llvm.something(metadata !{metadata !"f\00oa", i42 123}) + ret void +} + diff --git a/test/Feature/escaped_label.ll b/test/Feature/escaped_label.ll new file mode 100644 index 0000000..7f5f619 --- /dev/null +++ b/test/Feature/escaped_label.ll @@ -0,0 +1,11 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +define i32 @foo() { + br label %"foo`~!@#$%^&*()-_=+{}[]\\\\|;:',<.>/?" + +"foo`~!@#$%^&*()-_=+{}[]\\\\|;:',<.>/?": ; preds = %0 + ret i32 17 +} + diff --git a/test/Feature/float.ll b/test/Feature/float.ll new file mode 100644 index 0000000..632cfb7 --- /dev/null +++ b/test/Feature/float.ll @@ -0,0 +1,6 @@ +; RUN: llvm-as < %s | llvm-dis > t1.ll +; RUN: llvm-as t1.ll -o - | llvm-dis > t2.ll +; RUN: diff t1.ll t2.ll + +@F1 = global float 0x4010000000000000 +@D1 = global double 0x4010000000000000 diff --git a/test/Feature/fold-fpcast.ll b/test/Feature/fold-fpcast.ll new file mode 100644 index 0000000..cdf8da6 --- /dev/null +++ b/test/Feature/fold-fpcast.ll @@ -0,0 +1,18 @@ +; RUN: llvm-as < %s | llvm-dis | not grep bitcast + +define i32 @test1() { + ret i32 bitcast(float 0x400D9999A0000000 to i32) +} + +define float @test2() { + ret float bitcast(i32 17 to float) +} + +define i64 @test3() { + ret i64 bitcast (double 0x400921FB4D12D84A to i64) +} + +define double @test4() { + ret double bitcast (i64 42 to double) +} + diff --git a/test/Feature/forwardreftest.ll b/test/Feature/forwardreftest.ll new file mode 100644 index 0000000..26d214a --- /dev/null +++ b/test/Feature/forwardreftest.ll @@ -0,0 +1,29 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +%myty = type i32 +%myfn = type float (i32,double,i32,i16) +type i32(%myfn*) +type i32(i32) +type i32(i32(i32)*) + + %thisfuncty = type i32 (i32) * + +declare void @F(%thisfuncty, %thisfuncty, %thisfuncty) + +define i32 @zarro(i32 %Func) { +Startup: + add i32 0, 10 ; <i32>:0 [#uses=0] + ret i32 0 +} + +define i32 @test(i32) { + call void @F( %thisfuncty @zarro, %thisfuncty @test, %thisfuncty @foozball ) + ret i32 0 +} + +define i32 @foozball(i32) { + ret i32 0 +} + diff --git a/test/Feature/global_section.ll b/test/Feature/global_section.ll new file mode 100644 index 0000000..b8f5eb1 --- /dev/null +++ b/test/Feature/global_section.ll @@ -0,0 +1,10 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +@X = global i32 4, section "foo", align 16 ; <i32*> [#uses=0] + +define void @test() section "bar" { + ret void +} + diff --git a/test/Feature/globalredefinition.ll b/test/Feature/globalredefinition.ll new file mode 100644 index 0000000..42e2d1a --- /dev/null +++ b/test/Feature/globalredefinition.ll @@ -0,0 +1,18 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +; Test forward references and redefinitions of globals + +@A = global i32* @B ; <i32**> [#uses=0] +@B = global i32 7 ; <i32*> [#uses=1] + +declare void @X() + +declare void @X() + +define void @X() { + ret void +} + +declare void @X() diff --git a/test/Feature/globalredefinition3.ll b/test/Feature/globalredefinition3.ll new file mode 100644 index 0000000..0183e5a --- /dev/null +++ b/test/Feature/globalredefinition3.ll @@ -0,0 +1,4 @@ +; RUN: not llvm-as %s -o /dev/null -f |& grep {redefinition of global '@B'} + +@B = global i32 7 +@B = global i32 7 diff --git a/test/Feature/globalvars.ll b/test/Feature/globalvars.ll new file mode 100644 index 0000000..9a23775 --- /dev/null +++ b/test/Feature/globalvars.ll @@ -0,0 +1,18 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +@MyVar = external global i32 ; <i32*> [#uses=1] +@MyIntList = external global { \2*, i32 } ; <{ \2*, i32 }*> [#uses=1] +external global i32 ; <i32*>:0 [#uses=0] +@AConst = constant i32 123 ; <i32*> [#uses=0] +@AString = constant [4 x i8] c"test" ; <[4 x i8]*> [#uses=0] +@ZeroInit = global { [100 x i32], [40 x float] } zeroinitializer ; <{ [100 x i32], [40 x float] }*> [#uses=0] + +define i32 @foo(i32 %blah) { + store i32 5, i32* @MyVar + %idx = getelementptr { \2*, i32 }* @MyIntList, i64 0, i32 1 ; <i32*> [#uses=1] + store i32 12, i32* %idx + ret i32 %blah +} + diff --git a/test/Feature/indirectcall.ll b/test/Feature/indirectcall.ll new file mode 100644 index 0000000..c1cf39f --- /dev/null +++ b/test/Feature/indirectcall.ll @@ -0,0 +1,49 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +declare i32 @atoi(i8*) + +define i64 @fib(i64 %n) { + icmp ult i64 %n, 2 ; <i1>:1 [#uses=1] + br i1 %1, label %BaseCase, label %RecurseCase + +BaseCase: ; preds = %0 + ret i64 1 + +RecurseCase: ; preds = %0 + %n2 = sub i64 %n, 2 ; <i64> [#uses=1] + %n1 = sub i64 %n, 1 ; <i64> [#uses=1] + %f2 = call i64 @fib( i64 %n2 ) ; <i64> [#uses=1] + %f1 = call i64 @fib( i64 %n1 ) ; <i64> [#uses=1] + %result = add i64 %f2, %f1 ; <i64> [#uses=1] + ret i64 %result +} + +define i64 @realmain(i32 %argc, i8** %argv) { +; <label>:0 + icmp eq i32 %argc, 2 ; <i1>:1 [#uses=1] + br i1 %1, label %HasArg, label %Continue + +HasArg: ; preds = %0 + %n1 = add i32 1, 1 ; <i32> [#uses=1] + br label %Continue + +Continue: ; preds = %HasArg, %0 + %n = phi i32 [ %n1, %HasArg ], [ 1, %0 ] ; <i32> [#uses=1] + %N = sext i32 %n to i64 ; <i64> [#uses=1] + %F = call i64 @fib( i64 %N ) ; <i64> [#uses=1] + ret i64 %F +} + +define i64 @trampoline(i64 %n, i64 (i64)* %fibfunc) { + %F = call i64 %fibfunc( i64 %n ) ; <i64> [#uses=1] + ret i64 %F +} + +define i32 @main() { + %Result = call i64 @trampoline( i64 10, i64 (i64)* @fib ) ; <i64> [#uses=1] + %Result.upgrd.1 = trunc i64 %Result to i32 ; <i32> [#uses=1] + ret i32 %Result.upgrd.1 +} + diff --git a/test/Feature/indirectcall2.ll b/test/Feature/indirectcall2.ll new file mode 100644 index 0000000..1b949fc --- /dev/null +++ b/test/Feature/indirectcall2.ll @@ -0,0 +1,22 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +define i64 @test(i64 %X) { + ret i64 %X +} + +define i64 @fib(i64 %n) { +; <label>:0 + %T = icmp ult i64 %n, 2 ; <i1> [#uses=1] + br i1 %T, label %BaseCase, label %RecurseCase + +RecurseCase: ; preds = %0 + %result = call i64 @test( i64 %n ) ; <i64> [#uses=0] + br label %BaseCase + +BaseCase: ; preds = %RecurseCase, %0 + %X = phi i64 [ 1, %0 ], [ 2, %RecurseCase ] ; <i64> [#uses=1] + ret i64 %X +} + diff --git a/test/Feature/inlineasm.ll b/test/Feature/inlineasm.ll new file mode 100644 index 0000000..e4318f7 --- /dev/null +++ b/test/Feature/inlineasm.ll @@ -0,0 +1,13 @@ +; RUN: llvm-as < %s | llvm-dis > t1.ll +; RUN: llvm-as t1.ll -o - | llvm-dis > t2.ll +; RUN: diff t1.ll t2.ll + +module asm "this is an inline asm block" +module asm "this is another inline asm block" + +define i32 @test() { + %X = call i32 asm "tricky here $0, $1", "=r,r"( i32 4 ) ; <i32> [#uses=1] + call void asm sideeffect "eieio", ""( ) + ret i32 %X +} + diff --git a/test/Feature/instructions.ll b/test/Feature/instructions.ll new file mode 100644 index 0000000..d0c303d --- /dev/null +++ b/test/Feature/instructions.ll @@ -0,0 +1,24 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +define i32 @test_extractelement(<4 x i32> %V) { + %R = extractelement <4 x i32> %V, i32 1 ; <i32> [#uses=1] + ret i32 %R +} + +define <4 x i32> @test_insertelement(<4 x i32> %V) { + %R = insertelement <4 x i32> %V, i32 0, i32 0 ; <<4 x i32>> [#uses=1] + ret <4 x i32> %R +} + +define <4 x i32> @test_shufflevector_u(<4 x i32> %V) { + %R = shufflevector <4 x i32> %V, <4 x i32> %V, <4 x i32> < i32 1, i32 undef, i32 7, i32 2 > ; <<4 x i32>> [#uses=1] + ret <4 x i32> %R +} + +define <4 x float> @test_shufflevector_f(<4 x float> %V) { + %R = shufflevector <4 x float> %V, <4 x float> undef, <4 x i32> < i32 1, i32 undef, i32 7, i32 2 > ; <<4 x float>> [#uses=1] + ret <4 x float> %R +} + diff --git a/test/Feature/intrinsics.ll b/test/Feature/intrinsics.ll new file mode 100644 index 0000000..2dd6b53 --- /dev/null +++ b/test/Feature/intrinsics.ll @@ -0,0 +1,62 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +declare i1 @llvm.isunordered.f32(float, float) + +declare i1 @llvm.isunordered.f64(double, double) + +declare void @llvm.prefetch(i8*, i32, i32) + +declare i8 @llvm.ctpop.i8(i8) + +declare i16 @llvm.ctpop.i16(i16) + +declare i32 @llvm.ctpop.i32(i32) + +declare i64 @llvm.ctpop.i64(i64) + +declare i8 @llvm.cttz.i8(i8) + +declare i16 @llvm.cttz.i16(i16) + +declare i32 @llvm.cttz.i32(i32) + +declare i64 @llvm.cttz.i64(i64) + +declare i8 @llvm.ctlz.i8(i8) + +declare i16 @llvm.ctlz.i16(i16) + +declare i32 @llvm.ctlz.i32(i32) + +declare i64 @llvm.ctlz.i64(i64) + +declare float @llvm.sqrt.f32(float) + +declare double @llvm.sqrt.f64(double) + +; Test llvm intrinsics +; +define void @libm() { + fcmp uno float 1.000000e+00, 2.000000e+00 ; <i1>:1 [#uses=0] + fcmp uno double 3.000000e+00, 4.000000e+00 ; <i1>:2 [#uses=0] + call void @llvm.prefetch( i8* null, i32 1, i32 3 ) + call float @llvm.sqrt.f32( float 5.000000e+00 ) ; <float>:3 [#uses=0] + call double @llvm.sqrt.f64( double 6.000000e+00 ) ; <double>:4 [#uses=0] + call i8 @llvm.ctpop.i8( i8 10 ) ; <i32>:5 [#uses=0] + call i16 @llvm.ctpop.i16( i16 11 ) ; <i32>:6 [#uses=0] + call i32 @llvm.ctpop.i32( i32 12 ) ; <i32>:7 [#uses=0] + call i64 @llvm.ctpop.i64( i64 13 ) ; <i32>:8 [#uses=0] + call i8 @llvm.ctlz.i8( i8 14 ) ; <i32>:9 [#uses=0] + call i16 @llvm.ctlz.i16( i16 15 ) ; <i32>:10 [#uses=0] + call i32 @llvm.ctlz.i32( i32 16 ) ; <i32>:11 [#uses=0] + call i64 @llvm.ctlz.i64( i64 17 ) ; <i32>:12 [#uses=0] + call i8 @llvm.cttz.i8( i8 18 ) ; <i32>:13 [#uses=0] + call i16 @llvm.cttz.i16( i16 19 ) ; <i32>:14 [#uses=0] + call i32 @llvm.cttz.i32( i32 20 ) ; <i32>:15 [#uses=0] + call i64 @llvm.cttz.i64( i64 21 ) ; <i32>:16 [#uses=0] + ret void +} + +; FIXME: test ALL the intrinsics in this file. diff --git a/test/Feature/llvm2cpp.exp b/test/Feature/llvm2cpp.exp new file mode 100644 index 0000000..de0126c --- /dev/null +++ b/test/Feature/llvm2cpp.exp @@ -0,0 +1,3 @@ +load_lib llvm2cpp.exp + +llvm2cpp-test [lsort [glob -nocomplain $srcdir/$subdir/*.ll]] diff --git a/test/Feature/load_module.ll b/test/Feature/load_module.ll new file mode 100644 index 0000000..356eceb --- /dev/null +++ b/test/Feature/load_module.ll @@ -0,0 +1,10 @@ +; PR1318 +; RUN: llvm-as < %s | opt -load=%llvmlibsdir/LLVMHello%shlibext -hello \ +; RUN: -disable-output - |& grep Hello + +@junk = global i32 0 + +define i32* @somefunk() { + ret i32* @junk +} + diff --git a/test/Feature/newcasts.ll b/test/Feature/newcasts.ll new file mode 100644 index 0000000..4cfc8bc --- /dev/null +++ b/test/Feature/newcasts.ll @@ -0,0 +1,33 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +define void @"NewCasts" (i16 %x) { + %a = zext i16 %x to i32 + %b = sext i16 %x to i32 + %c = trunc i16 %x to i8 + %d = uitofp i16 %x to float + %e = sitofp i16 %x to double + %f = fptoui float %d to i16 + %g = fptosi double %e to i16 + %i = fpext float %d to double + %j = fptrunc double %i to float + %k = bitcast i32 %a to float + %l = inttoptr i16 %x to i32* + %m = ptrtoint i32* %l to i64 + %n = insertelement <4 x i32> undef, i32 %a, i32 0 + %o = sitofp <4 x i32> %n to <4 x float> + %p = uitofp <4 x i32> %n to <4 x float> + %q = fptosi <4 x float> %p to <4 x i32> + %r = fptoui <4 x float> %p to <4 x i32> + ret void +} + + +define i16 @"ZExtConst" () { + ret i16 trunc ( i32 zext ( i16 42 to i32) to i16 ) +} + +define i16 @"SExtConst" () { + ret i16 trunc (i32 sext (i16 42 to i32) to i16 ) +} diff --git a/test/Feature/noalias-ret.ll b/test/Feature/noalias-ret.ll new file mode 100644 index 0000000..d88452b --- /dev/null +++ b/test/Feature/noalias-ret.ll @@ -0,0 +1,6 @@ +; RUN: llvm-as < %s + +define noalias i8* @_Znwj(i32 %x) nounwind { + %A = malloc i8, i32 %x + ret i8* %A +} diff --git a/test/Feature/opaquetypes.ll b/test/Feature/opaquetypes.ll new file mode 100644 index 0000000..6539c1a --- /dev/null +++ b/test/Feature/opaquetypes.ll @@ -0,0 +1,55 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +; This test case is used to test opaque type processing, forward references, +; and recursive types. Oh my. +; + +%SQ1 = type { i32 } +%SQ2 = type { %ITy } +%ITy = type i32 + + +%CCC = type { \2* } +%BBB = type { \2*, \2 * } +%AAA = type { \2*, {\2*}, [12x{\2*}], {[1x{\2*}]} } + +; Test numbered types +type %CCC +type %BBB +%Composite = type { %0, %1 } + +; Test simple opaque type resolution... +%intty = type i32 + +; Perform a simple forward reference... +%ty1 = type { %ty2, i32 } +%ty2 = type float + +; Do a recursive type... +%list = type { %list * } +%listp = type { %listp } * + +; Do two mutually recursive types... +%TyA = type { %ty2, %TyB * } +%TyB = type { double, %TyA * } + +; A complex recursive type... +%Y = type { {%Y*}, %Y* } +%Z = type { { %Z * }, [12x%Z] *, {{{ %Z * }}} } + +; More ridiculous test cases... +%A = type [ 123x %A*] +%M = type %M (%M, %M) * +%P = type %P* + +; Recursive ptrs +%u = type %v* +%v = type %u* + +; Test the parser for unnamed recursive types... +%P1 = type \1 * +%Y1 = type { { \3 * }, \2 * } +%Z1 = type { { \3 * }, [12x\3] *, { { { \5 * } } } } + diff --git a/test/Feature/packed.ll b/test/Feature/packed.ll new file mode 100644 index 0000000..b86a227 --- /dev/null +++ b/test/Feature/packed.ll @@ -0,0 +1,15 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +@foo1 = external global <4 x float> ; <<4 x float>*> [#uses=2] +@foo2 = external global <2 x i32> ; <<2 x i32>*> [#uses=2] + +define void @main() { + store <4 x float> < float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00 >, <4 x float>* @foo1 + store <2 x i32> < i32 4, i32 4 >, <2 x i32>* @foo2 + %l1 = load <4 x float>* @foo1 ; <<4 x float>> [#uses=0] + %l2 = load <2 x i32>* @foo2 ; <<2 x i32>> [#uses=0] + ret void +} + diff --git a/test/Feature/packed_struct.ll b/test/Feature/packed_struct.ll new file mode 100644 index 0000000..4d4ace9 --- /dev/null +++ b/test/Feature/packed_struct.ll @@ -0,0 +1,33 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll +; RUN: not grep cast %t2.ll +; RUN: grep {\\}>} %t2.ll +; END. + +%struct.anon = type <{ i8, i32, i32, i32 }> +@foos = external global %struct.anon +@bara = external global [2 x <{ i32, i8 }>] + +;initializers should work for packed and non-packed the same way +@E1 = global <{i8, i32, i32}> <{i8 1, i32 2, i32 3}> +@E2 = global {i8, i32, i32} {i8 4, i32 5, i32 6} + + +define i32 @main() +{ + %tmp = load i32* getelementptr (%struct.anon* @foos, i32 0, i32 1) ; <i32> [#uses=1] + %tmp3 = load i32* getelementptr (%struct.anon* @foos, i32 0, i32 2) ; <i32> [#uses=1] + %tmp6 = load i32* getelementptr (%struct.anon* @foos, i32 0, i32 3) ; <i32> [#uses=1] + %tmp4 = add i32 %tmp3, %tmp ; <i32> [#uses=1] + %tmp7 = add i32 %tmp4, %tmp6 ; <i32> [#uses=1] + ret i32 %tmp7 +} + +define i32 @bar() { +entry: + %tmp = load i32* getelementptr([2 x <{ i32, i8 }>]* @bara, i32 0, i32 0, i32 0 ) ; <i32> [#uses=1] + %tmp4 = load i32* getelementptr ([2 x <{ i32, i8 }>]* @bara, i32 0, i32 1, i32 0) ; <i32> [#uses=1] + %tmp5 = add i32 %tmp4, %tmp ; <i32> [#uses=1] + ret i32 %tmp5 +} diff --git a/test/Feature/paramattrs.ll b/test/Feature/paramattrs.ll new file mode 100644 index 0000000..3bee617 --- /dev/null +++ b/test/Feature/paramattrs.ll @@ -0,0 +1,22 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +%ZFunTy = type i32(i8 zeroext) +%SFunTy = type i32(i8 signext) + +declare i16 @"test"(i16 signext %arg) signext +declare i8 @"test2" (i16 zeroext %a2) zeroext + +declare i32 @"test3"(i32* noalias %p) + +declare void @exit(i32) noreturn nounwind + +define i32 @main(i32 inreg %argc, i8 ** inreg %argv) nounwind { + %val = trunc i32 %argc to i16 + %res1 = call i16 (i16 signext) signext *@test(i16 signext %val) signext + %two = add i16 %res1, %res1 + %res2 = call i8 @test2(i16 %two zeroext) zeroext + %retVal = sext i16 %two to i32 + ret i32 %retVal +} diff --git a/test/Feature/ppcld.ll b/test/Feature/ppcld.ll new file mode 100644 index 0000000..f21eb43 --- /dev/null +++ b/test/Feature/ppcld.ll @@ -0,0 +1,26 @@ +; RUN: llvm-as < %s | llvm-dis > %t +; RUN: llvm-as < %t | llvm-dis > %t2 +; RUN: diff %t %t2 +; ModuleID = '<stdin>' +target datalayout = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64" +target triple = "powerpc-apple-darwin8" +@ld = external global ppc_fp128 ; <ppc_fp128*> [#uses=1] +@d = global double 4.050000e+00, align 8 ; <double*> [#uses=1] +@f = global float 0x4010333340000000 ; <float*> [#uses=1] + +define i32 @foo() { +entry: + %retval = alloca i32, align 4 ; <i32*> [#uses=1] + %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0] + %tmp = load float* @f ; <float> [#uses=1] + %tmp1 = fpext float %tmp to double ; <double> [#uses=1] + %tmp2 = load double* @d ; <double> [#uses=1] + %tmp3 = mul double %tmp1, %tmp2 ; <double> [#uses=1] + %tmp4 = fpext double %tmp3 to ppc_fp128 ; <ppc_fp128> [#uses=1] + store ppc_fp128 %tmp4, ppc_fp128* @ld + br label %return + +return: ; preds = %entry + %retval4 = load i32* %retval ; <i32> [#uses=1] + ret i32 %retval4 +} diff --git a/test/Feature/properties.ll b/test/Feature/properties.ll new file mode 100644 index 0000000..c688d68 --- /dev/null +++ b/test/Feature/properties.ll @@ -0,0 +1,7 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +target datalayout = "e-p:32:32" +target triple = "proc-vend-sys" +deplibs = [ "m", "c" ] diff --git a/test/Feature/prototype.ll b/test/Feature/prototype.ll new file mode 100644 index 0000000..3754a1d --- /dev/null +++ b/test/Feature/prototype.ll @@ -0,0 +1,11 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +declare i32 @bar(i32) + +define i32 @foo(i32 %blah) { + %xx = call i32 @bar( i32 %blah ) ; <i32> [#uses=1] + ret i32 %xx +} + diff --git a/test/Feature/recursivetype.ll b/test/Feature/recursivetype.ll new file mode 100644 index 0000000..43db5f0 --- /dev/null +++ b/test/Feature/recursivetype.ll @@ -0,0 +1,103 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +; This file contains the output from the following compiled C code: +; typedef struct list { +; struct list *Next; +; int Data; +; } list; +; +; // Iterative insert fn +; void InsertIntoListTail(list **L, int Data) { +; while (*L) +; L = &(*L)->Next; +; *L = (list*)malloc(sizeof(list)); +; (*L)->Data = Data; +; (*L)->Next = 0; +; } +; +; // Recursive list search fn +; list *FindData(list *L, int Data) { +; if (L == 0) return 0; +; if (L->Data == Data) return L; +; return FindData(L->Next, Data); +; } +; +; void DoListStuff() { +; list *MyList = 0; +; InsertIntoListTail(&MyList, 100); +; InsertIntoListTail(&MyList, 12); +; InsertIntoListTail(&MyList, 42); +; InsertIntoListTail(&MyList, 1123); +; InsertIntoListTail(&MyList, 1213); +; +; if (FindData(MyList, 75)) foundIt(); +; if (FindData(MyList, 42)) foundIt(); +; if (FindData(MyList, 700)) foundIt(); +; } + +%list = type { %list*, i32 } + +declare i8* @malloc(i32) + +define void @InsertIntoListTail(%list** %L, i32 %Data) { +bb1: + %reg116 = load %list** %L ; <%list*> [#uses=1] + %cast1004 = inttoptr i64 0 to %list* ; <%list*> [#uses=1] + %cond1000 = icmp eq %list* %reg116, %cast1004 ; <i1> [#uses=1] + br i1 %cond1000, label %bb3, label %bb2 + +bb2: ; preds = %bb2, %bb1 + %reg117 = phi %list** [ %reg118, %bb2 ], [ %L, %bb1 ] ; <%list**> [#uses=1] + %cast1010 = bitcast %list** %reg117 to %list*** ; <%list***> [#uses=1] + %reg118 = load %list*** %cast1010 ; <%list**> [#uses=3] + %reg109 = load %list** %reg118 ; <%list*> [#uses=1] + %cast1005 = inttoptr i64 0 to %list* ; <%list*> [#uses=1] + %cond1001 = icmp ne %list* %reg109, %cast1005 ; <i1> [#uses=1] + br i1 %cond1001, label %bb2, label %bb3 + +bb3: ; preds = %bb2, %bb1 + %reg119 = phi %list** [ %reg118, %bb2 ], [ %L, %bb1 ] ; <%list**> [#uses=1] + %cast1006 = bitcast %list** %reg119 to i8** ; <i8**> [#uses=1] + %reg111 = call i8* @malloc( i32 16 ) ; <i8*> [#uses=3] + store i8* %reg111, i8** %cast1006 + %reg111.upgrd.1 = ptrtoint i8* %reg111 to i64 ; <i64> [#uses=1] + %reg1002 = add i64 %reg111.upgrd.1, 8 ; <i64> [#uses=1] + %reg1002.upgrd.2 = inttoptr i64 %reg1002 to i8* ; <i8*> [#uses=1] + %cast1008 = bitcast i8* %reg1002.upgrd.2 to i32* ; <i32*> [#uses=1] + store i32 %Data, i32* %cast1008 + %cast1003 = inttoptr i64 0 to i64* ; <i64*> [#uses=1] + %cast1009 = bitcast i8* %reg111 to i64** ; <i64**> [#uses=1] + store i64* %cast1003, i64** %cast1009 + ret void +} + +define %list* @FindData(%list* %L, i32 %Data) { +bb1: + br label %bb2 + +bb2: ; preds = %bb6, %bb1 + %reg115 = phi %list* [ %reg116, %bb6 ], [ %L, %bb1 ] ; <%list*> [#uses=4] + %cast1014 = inttoptr i64 0 to %list* ; <%list*> [#uses=1] + %cond1011 = icmp ne %list* %reg115, %cast1014 ; <i1> [#uses=1] + br i1 %cond1011, label %bb4, label %bb3 + +bb3: ; preds = %bb2 + ret %list* null + +bb4: ; preds = %bb2 + %idx = getelementptr %list* %reg115, i64 0, i32 1 ; <i32*> [#uses=1] + %reg111 = load i32* %idx ; <i32> [#uses=1] + %cond1013 = icmp ne i32 %reg111, %Data ; <i1> [#uses=1] + br i1 %cond1013, label %bb6, label %bb5 + +bb5: ; preds = %bb4 + ret %list* %reg115 + +bb6: ; preds = %bb4 + %idx2 = getelementptr %list* %reg115, i64 0, i32 0 ; <%list**> [#uses=1] + %reg116 = load %list** %idx2 ; <%list*> [#uses=1] + br label %bb2 +} + diff --git a/test/Feature/simplecalltest.ll b/test/Feature/simplecalltest.ll new file mode 100644 index 0000000..6452286 --- /dev/null +++ b/test/Feature/simplecalltest.ll @@ -0,0 +1,24 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + + %FunTy = type i32 (i32) + +define void @invoke(%FunTy* %x) { + %foo = call i32 %x( i32 123 ) ; <i32> [#uses=0] + ret void +} + +define i32 @main(i32 %argc, i8** %argv, i8** %envp) { + %retval = call i32 @test( i32 %argc ) ; <i32> [#uses=2] + %two = add i32 %retval, %retval ; <i32> [#uses=1] + %retval2 = call i32 @test( i32 %argc ) ; <i32> [#uses=1] + %two2 = add i32 %two, %retval2 ; <i32> [#uses=1] + call void @invoke( %FunTy* @test ) + ret i32 %two2 +} + +define i32 @test(i32 %i0) { + ret i32 %i0 +} + diff --git a/test/Feature/small.ll b/test/Feature/small.ll new file mode 100644 index 0000000..4644f64 --- /dev/null +++ b/test/Feature/small.ll @@ -0,0 +1,11 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +%x = type i32 + +define i32 @foo(i32 %in) { +label: + ret i32 2 +} + diff --git a/test/Feature/smallest.ll b/test/Feature/smallest.ll new file mode 100644 index 0000000..5dd023c --- /dev/null +++ b/test/Feature/smallest.ll @@ -0,0 +1,4 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + diff --git a/test/Feature/sparcld.ll b/test/Feature/sparcld.ll new file mode 100644 index 0000000..2e99bda --- /dev/null +++ b/test/Feature/sparcld.ll @@ -0,0 +1,24 @@ +; RUN: llvm-as < %s | llvm-dis > %t +; RUN: llvm-as < %t | llvm-dis > %t2 +; RUN: diff %t %t2 +; ModuleID = '<stdin>' +@ld = external global fp128 ; <fp128*> [#uses=1] +@d = global double 4.050000e+00, align 8 ; <double*> [#uses=1] +@f = global float 0x4010333340000000 ; <float*> [#uses=1] + +define i32 @foo() { +entry: + %retval = alloca i32, align 4 ; <i32*> [#uses=1] + %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0] + %tmp = load float* @f ; <float> [#uses=1] + %tmp1 = fpext float %tmp to double ; <double> [#uses=1] + %tmp2 = load double* @d ; <double> [#uses=1] + %tmp3 = mul double %tmp1, %tmp2 ; <double> [#uses=1] + %tmp4 = fpext double %tmp3 to fp128 ; <fp128> [#uses=1] + store fp128 %tmp4, fp128* @ld + br label %return + +return: ; preds = %entry + %retval4 = load i32* %retval ; <i32> [#uses=1] + ret i32 %retval4 +} diff --git a/test/Feature/testalloca.ll b/test/Feature/testalloca.ll new file mode 100644 index 0000000..230b5a9 --- /dev/null +++ b/test/Feature/testalloca.ll @@ -0,0 +1,22 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + + %inners = type { float, { i8 } } + %struct = type { i32, %inners, i64 } + +define i32 @testfunction(i32 %i0, i32 %j0) { + alloca i8, i32 5 ; <i8*>:1 [#uses=0] + %ptr = alloca i32 ; <i32*> [#uses=2] + store i32 3, i32* %ptr + %val = load i32* %ptr ; <i32> [#uses=0] + %sptr = alloca %struct ; <%struct*> [#uses=2] + %nsptr = getelementptr %struct* %sptr, i64 0, i32 1 ; <%inners*> [#uses=1] + %ubsptr = getelementptr %inners* %nsptr, i64 0, i32 1 ; <{ i8 }*> [#uses=1] + %idx = getelementptr { i8 }* %ubsptr, i64 0, i32 0 ; <i8*> [#uses=1] + store i8 4, i8* %idx + %fptr = getelementptr %struct* %sptr, i64 0, i32 1, i32 0 ; <float*> [#uses=1] + store float 4.000000e+00, float* %fptr + ret i32 3 +} + diff --git a/test/Feature/testconstants.ll b/test/Feature/testconstants.ll new file mode 100644 index 0000000..6810f3d --- /dev/null +++ b/test/Feature/testconstants.ll @@ -0,0 +1,29 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +@somestr = constant [11 x i8] c"hello world" ; <[11 x i8]*> [#uses=1] +@array = constant [2 x i32] [ i32 12, i32 52 ] ; <[2 x i32]*> [#uses=1] +constant { i32, i32 } { i32 4, i32 3 } ; <{ i32, i32 }*>:0 [#uses=0] + +define [2 x i32]* @testfunction(i32 %i0, i32 %j0) { + ret [2 x i32]* @array +} + +define i8* @otherfunc(i32, double) { + %somestr = getelementptr [11 x i8]* @somestr, i64 0, i64 0 ; <i8*> [#uses=1] + ret i8* %somestr +} + +define i8* @yetanotherfunc(i32, double) { + ret i8* null +} + +define i32 @negativeUnsigned() { + ret i32 -1 +} + +define i32 @largeSigned() { + ret i32 -394967296 +} + diff --git a/test/Feature/testlogical.ll b/test/Feature/testlogical.ll new file mode 100644 index 0000000..a064869 --- /dev/null +++ b/test/Feature/testlogical.ll @@ -0,0 +1,11 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +define i32 @simpleAdd(i32 %i0, i32 %j0) { + %t1 = xor i32 %i0, %j0 ; <i32> [#uses=1] + %t2 = or i32 %i0, %j0 ; <i32> [#uses=1] + %t3 = and i32 %t1, %t2 ; <i32> [#uses=1] + ret i32 %t3 +} + diff --git a/test/Feature/testmemory.ll b/test/Feature/testmemory.ll new file mode 100644 index 0000000..a9019f0 --- /dev/null +++ b/test/Feature/testmemory.ll @@ -0,0 +1,36 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + + + %complexty = type { i32, { [4 x i8*], float }, double } + %struct = type { i32, { float, { i8 } }, i64 } + +define i32 @main() { + call i32 @testfunction( i64 0, i64 1 ) ; <i32>:1 [#uses=0] + ret i32 0 +} + +define i32 @testfunction(i64 %i0, i64 %j0) { + %array0 = malloc [4 x i8] ; <[4 x i8]*> [#uses=2] + %size = add i32 2, 2 ; <i32> [#uses=1] + %array1 = malloc i8, i32 4 ; <i8*> [#uses=1] + %array2 = malloc i8, i32 %size ; <i8*> [#uses=1] + %idx = getelementptr [4 x i8]* %array0, i64 0, i64 2 ; <i8*> [#uses=1] + store i8 123, i8* %idx + free [4 x i8]* %array0 + free i8* %array1 + free i8* %array2 + %aa = alloca %complexty, i32 5 ; <%complexty*> [#uses=1] + %idx2 = getelementptr %complexty* %aa, i64 %i0, i32 1, i32 0, i64 %j0 ; <i8**> [#uses=1] + store i8* null, i8** %idx2 + %ptr = alloca i32 ; <i32*> [#uses=2] + store i32 3, i32* %ptr + %val = load i32* %ptr ; <i32> [#uses=0] + %sptr = alloca %struct ; <%struct*> [#uses=1] + %ubsptr = getelementptr %struct* %sptr, i64 0, i32 1, i32 1 ; <{ i8 }*> [#uses=1] + %idx3 = getelementptr { i8 }* %ubsptr, i64 0, i32 0 ; <i8*> [#uses=1] + store i8 4, i8* %idx3 + ret i32 3 +} + diff --git a/test/Feature/testswitch.ll b/test/Feature/testswitch.ll new file mode 100644 index 0000000..417f56b --- /dev/null +++ b/test/Feature/testswitch.ll @@ -0,0 +1,26 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + + %int = type i32 + +define i32 @squared(i32 %i0) { + switch i32 %i0, label %Default [ + i32 1, label %Case1 + i32 2, label %Case2 + i32 4, label %Case4 + ] + +Default: ; preds = %0 + ret i32 -1 + +Case1: ; preds = %0 + ret i32 1 + +Case2: ; preds = %0 + ret i32 4 + +Case4: ; preds = %0 + ret i32 16 +} + diff --git a/test/Feature/testtype.ll b/test/Feature/testtype.ll new file mode 100644 index 0000000..124aa09 --- /dev/null +++ b/test/Feature/testtype.ll @@ -0,0 +1,21 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +%X = type i32* addrspace(4)* + + %inners = type { float, { i8 } } + %struct = type { i32, %inners, i64 } + +%fwdref = type { %fwd* } +%fwd = type %fwdref* + +; same as above with unnamed types +type { %1* } +type %0* +%test = type %1 + +%test2 = type [2 x i32] +;%x = type %undefined* + +%test3 = type i32 (i32()*, float(...)*, ...)* diff --git a/test/Feature/testvarargs.ll b/test/Feature/testvarargs.ll new file mode 100644 index 0000000..a73b7ec --- /dev/null +++ b/test/Feature/testvarargs.ll @@ -0,0 +1,12 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + + +declare i32 @printf(i8*, ...) ;; Prototype for: int __builtin_printf(const char*, ...) + +define i32 @testvarar() { + call i32 (i8*, ...)* @printf( i8* null, i32 12, i8 42 ) ; <i32>:1 [#uses=1] + ret i32 %1 +} + diff --git a/test/Feature/undefined.ll b/test/Feature/undefined.ll new file mode 100644 index 0000000..e63ce41 --- /dev/null +++ b/test/Feature/undefined.ll @@ -0,0 +1,17 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +@X = global i32 undef ; <i32*> [#uses=0] + +declare i32 @atoi(i8*) + +define i32 @test() { + ret i32 undef +} + +define i32 @test2() { + %X = add i32 undef, 1 ; <i32> [#uses=1] + ret i32 %X +} + diff --git a/test/Feature/unreachable.ll b/test/Feature/unreachable.ll new file mode 100644 index 0000000..8bffb4c --- /dev/null +++ b/test/Feature/unreachable.ll @@ -0,0 +1,15 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +declare void @bar() + +define i32 @foo() { + unreachable +} + +define double @xyz() { + call void @bar( ) + unreachable +} + diff --git a/test/Feature/varargs.ll b/test/Feature/varargs.ll new file mode 100644 index 0000000..b9317df --- /dev/null +++ b/test/Feature/varargs.ll @@ -0,0 +1,29 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +; Demonstrate all of the variable argument handling intrinsic functions plus +; the va_arg instruction. + +declare void @llvm.va_start(i8*) + +declare void @llvm.va_copy(i8*, i8*) + +declare void @llvm.va_end(i8*) + +define i32 @test(i32 %X, ...) { + %ap = alloca i8* ; <i8**> [#uses=4] + %va.upgrd.1 = bitcast i8** %ap to i8* ; <i8*> [#uses=1] + call void @llvm.va_start( i8* %va.upgrd.1 ) + %tmp = va_arg i8** %ap, i32 ; <i32> [#uses=1] + %aq = alloca i8* ; <i8**> [#uses=2] + %va0.upgrd.2 = bitcast i8** %aq to i8* ; <i8*> [#uses=1] + %va1.upgrd.3 = bitcast i8** %ap to i8* ; <i8*> [#uses=1] + call void @llvm.va_copy( i8* %va0.upgrd.2, i8* %va1.upgrd.3 ) + %va.upgrd.4 = bitcast i8** %aq to i8* ; <i8*> [#uses=1] + call void @llvm.va_end( i8* %va.upgrd.4 ) + %va.upgrd.5 = bitcast i8** %ap to i8* ; <i8*> [#uses=1] + call void @llvm.va_end( i8* %va.upgrd.5 ) + ret i32 %tmp +} + diff --git a/test/Feature/varargs_new.ll b/test/Feature/varargs_new.ll new file mode 100644 index 0000000..a46f270 --- /dev/null +++ b/test/Feature/varargs_new.ll @@ -0,0 +1,38 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +; Demonstrate all of the variable argument handling intrinsic functions plus +; the va_arg instruction. + +declare void @llvm.va_start(i8*) + +declare void @llvm.va_copy(i8*, i8*) + +declare void @llvm.va_end(i8*) + +define i32 @test(i32 %X, ...) { + ; Allocate two va_list items. On this target, va_list is of type sbyte* + %ap = alloca i8* ; <i8**> [#uses=4] + %aq = alloca i8* ; <i8**> [#uses=2] + + ; Initialize variable argument processing + %va.upgrd.1 = bitcast i8** %ap to i8* ; <i8*> [#uses=1] + call void @llvm.va_start( i8* %va.upgrd.1 ) + + ; Read a single integer argument + %tmp = va_arg i8** %ap, i32 ; <i32> [#uses=1] + + ; Demonstrate usage of llvm.va_copy and llvm_va_end + %apv = load i8** %ap ; <i8*> [#uses=1] + %va0.upgrd.2 = bitcast i8** %aq to i8* ; <i8*> [#uses=1] + %va1.upgrd.3 = bitcast i8* %apv to i8* ; <i8*> [#uses=1] + call void @llvm.va_copy( i8* %va0.upgrd.2, i8* %va1.upgrd.3 ) + %va.upgrd.4 = bitcast i8** %aq to i8* ; <i8*> [#uses=1] + call void @llvm.va_end( i8* %va.upgrd.4 ) + + ; Stop processing of arguments. + %va.upgrd.5 = bitcast i8** %ap to i8* ; <i8*> [#uses=1] + call void @llvm.va_end( i8* %va.upgrd.5 ) + ret i32 %tmp +} diff --git a/test/Feature/weak_constant.ll b/test/Feature/weak_constant.ll new file mode 100644 index 0000000..d27adfe --- /dev/null +++ b/test/Feature/weak_constant.ll @@ -0,0 +1,38 @@ +; RUN: llvm-as < %s | opt -std-compile-opts | llvm-dis > %t +; RUN: grep undef %t | count 1 +; RUN: grep 5 %t | count 1 +; RUN: grep 7 %t | count 1 +; RUN: grep 9 %t | count 1 + + type { i32, i32 } ; type %0 +@a = weak constant i32 undef ; <i32*> [#uses=1] +@b = weak constant i32 5 ; <i32*> [#uses=1] +@c = weak constant %0 { i32 7, i32 9 } ; <%0*> [#uses=1] + +define i32 @la() { + %v = load i32* @a ; <i32> [#uses=1] + ret i32 %v +} + +define i32 @lb() { + %v = load i32* @b ; <i32> [#uses=1] + ret i32 %v +} + +define i32 @lc() { + %g = getelementptr %0* @c, i32 0, i32 0 ; <i32*> [#uses=1] + %u = load i32* %g ; <i32> [#uses=1] + %h = getelementptr %0* @c, i32 0, i32 1 ; <i32*> [#uses=1] + %v = load i32* %h ; <i32> [#uses=1] + %r = add i32 %u, %v + ret i32 %r +} + +define i32 @f() { + %u = call i32 @la() ; <i32> [#uses=1] + %v = call i32 @lb() ; <i32> [#uses=1] + %w = call i32 @lc() ; <i32> [#uses=1] + %r = add i32 %u, %v ; <i32> [#uses=1] + %s = add i32 %r, %w ; <i32> [#uses=1] + ret i32 %s +} diff --git a/test/Feature/weirdnames.ll b/test/Feature/weirdnames.ll new file mode 100644 index 0000000..cc773cd --- /dev/null +++ b/test/Feature/weirdnames.ll @@ -0,0 +1,9 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +; Test using double quotes to form names that are not legal in the % form +%"&^ " = type { i32 } +@"%.*+ foo" = global %"&^ " { i32 5 } +@"0" = global float 0.000000e+00 ; This CANNOT be %0 +@"\\03foo" = global float 0x3FB99999A0000000 ; Make sure funny char gets round trip diff --git a/test/Feature/x86ld.ll b/test/Feature/x86ld.ll new file mode 100644 index 0000000..6904003 --- /dev/null +++ b/test/Feature/x86ld.ll @@ -0,0 +1,26 @@ +; RUN: llvm-as < %s | llvm-dis > %t +; RUN: llvm-as < %t | llvm-dis > %t2 +; RUN: diff %t %t2 +; ModuleID = '<stdin>' +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64" +target triple = "i686-apple-darwin8" +@ld = external global x86_fp80 ; <x86_fp80*> [#uses=1] +@d = global double 4.050000e+00, align 8 ; <double*> [#uses=1] +@f = global float 0x4010333340000000 ; <float*> [#uses=1] + +define i32 @foo() { +entry: + %retval = alloca i32, align 4 ; <i32*> [#uses=1] + %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0] + %tmp = load float* @f ; <float> [#uses=1] + %tmp1 = fpext float %tmp to double ; <double> [#uses=1] + %tmp2 = load double* @d ; <double> [#uses=1] + %tmp3 = mul double %tmp1, %tmp2 ; <double> [#uses=1] + %tmp4 = fpext double %tmp3 to x86_fp80 ; <x86_fp80> [#uses=1] + store x86_fp80 %tmp4, x86_fp80* @ld + br label %return + +return: ; preds = %entry + %retval4 = load i32* %retval ; <i32> [#uses=1] + ret i32 %retval4 +} |