diff options
Diffstat (limited to 'test/Transforms/FunctionAttrs')
10 files changed, 190 insertions, 0 deletions
diff --git a/test/Transforms/FunctionAttrs/2008-09-03-Mutual.ll b/test/Transforms/FunctionAttrs/2008-09-03-Mutual.ll new file mode 100644 index 0000000..5261ac4 --- /dev/null +++ b/test/Transforms/FunctionAttrs/2008-09-03-Mutual.ll @@ -0,0 +1,11 @@ +; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | grep readnone + +define i32 @a() { + %tmp = call i32 @b( ) ; <i32> [#uses=1] + ret i32 %tmp +} + +define i32 @b() { + %tmp = call i32 @a( ) ; <i32> [#uses=1] + ret i32 %tmp +} diff --git a/test/Transforms/FunctionAttrs/2008-09-03-ReadNone.ll b/test/Transforms/FunctionAttrs/2008-09-03-ReadNone.ll new file mode 100644 index 0000000..a17d381 --- /dev/null +++ b/test/Transforms/FunctionAttrs/2008-09-03-ReadNone.ll @@ -0,0 +1,18 @@ +; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | grep readnone | count 4 +@x = global i32 0 + +declare i32 @e() readnone + +define i32 @f() { + %tmp = call i32 @e( ) ; <i32> [#uses=1] + ret i32 %tmp +} + +define i32 @g() readonly { + ret i32 0 +} + +define i32 @h() readnone { + %tmp = load i32* @x ; <i32> [#uses=1] + ret i32 %tmp +} diff --git a/test/Transforms/FunctionAttrs/2008-09-03-ReadOnly.ll b/test/Transforms/FunctionAttrs/2008-09-03-ReadOnly.ll new file mode 100644 index 0000000..cebfdac --- /dev/null +++ b/test/Transforms/FunctionAttrs/2008-09-03-ReadOnly.ll @@ -0,0 +1,9 @@ +; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | grep readonly | count 2 + +define i32 @f() { +entry: + %tmp = call i32 @e( ) ; <i32> [#uses=1] + ret i32 %tmp +} + +declare i32 @e() readonly diff --git a/test/Transforms/FunctionAttrs/2008-09-13-VolatileRead.ll b/test/Transforms/FunctionAttrs/2008-09-13-VolatileRead.ll new file mode 100644 index 0000000..b6077fd --- /dev/null +++ b/test/Transforms/FunctionAttrs/2008-09-13-VolatileRead.ll @@ -0,0 +1,9 @@ +; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | not grep read +; PR2792 + +@g = global i32 0 ; <i32*> [#uses=1] + +define i32 @f() { + %t = volatile load i32* @g ; <i32> [#uses=1] + ret i32 %t +} diff --git a/test/Transforms/FunctionAttrs/2008-10-04-LocalMemory.ll b/test/Transforms/FunctionAttrs/2008-10-04-LocalMemory.ll new file mode 100644 index 0000000..50ca641 --- /dev/null +++ b/test/Transforms/FunctionAttrs/2008-10-04-LocalMemory.ll @@ -0,0 +1,10 @@ +; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | grep readnone | count 2 + +declare i32 @g(i32*) readnone + +define i32 @f() { + %x = alloca i32 ; <i32*> [#uses=2] + store i32 0, i32* %x + %y = call i32 @g(i32* %x) ; <i32> [#uses=1] + ret i32 %y +} diff --git a/test/Transforms/FunctionAttrs/2008-12-29-Constant.ll b/test/Transforms/FunctionAttrs/2008-12-29-Constant.ll new file mode 100644 index 0000000..d9c0117 --- /dev/null +++ b/test/Transforms/FunctionAttrs/2008-12-29-Constant.ll @@ -0,0 +1,8 @@ +; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | grep readnone + +@s = external constant i8 ; <i8*> [#uses=1] + +define i8 @f() { + %tmp = load i8* @s ; <i8> [#uses=1] + ret i8 %tmp +} diff --git a/test/Transforms/FunctionAttrs/2008-12-31-NoCapture.ll b/test/Transforms/FunctionAttrs/2008-12-31-NoCapture.ll new file mode 100644 index 0000000..39a64e6 --- /dev/null +++ b/test/Transforms/FunctionAttrs/2008-12-31-NoCapture.ll @@ -0,0 +1,101 @@ +; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | not grep {nocapture *%%q} +; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | grep {nocapture *%%p} | count 6 +@g = global i32* null ; <i32**> [#uses=1] + +define i32* @c1(i32* %q) { + ret i32* %q +} + +define void @c2(i32* %q) { + store i32* %q, i32** @g + ret void +} + +define void @c3(i32* %q) { + call void @c2(i32* %q) + ret void +} + +define i1 @c4(i32* %q, i32 %bitno) { + %tmp = ptrtoint i32* %q to i32 + %tmp2 = lshr i32 %tmp, %bitno + %bit = trunc i32 %tmp2 to i1 + br i1 %bit, label %l1, label %l0 +l0: + ret i1 0 ; escaping value not caught by def-use chaining. +l1: + ret i1 1 ; escaping value not caught by def-use chaining. +} + +@lookup_table = global [2 x i1] [ i1 0, i1 1 ] + +define i1 @c5(i32* %q, i32 %bitno) { + %tmp = ptrtoint i32* %q to i32 + %tmp2 = lshr i32 %tmp, %bitno + %bit = and i32 %tmp2, 1 + ; subtle escape mechanism follows + %lookup = getelementptr [2 x i1]* @lookup_table, i32 0, i32 %bit + %val = load i1* %lookup + ret i1 %val +} + +declare void @throw_if_bit_set(i8*, i8) readonly +define i1 @c6(i8* %q, i8 %bit) { + invoke void @throw_if_bit_set(i8* %q, i8 %bit) + to label %ret0 unwind label %ret1 +ret0: + ret i1 0 +ret1: + ret i1 1 +} + +define i1* @lookup_bit(i32* %q, i32 %bitno) readnone nounwind { + %tmp = ptrtoint i32* %q to i32 + %tmp2 = lshr i32 %tmp, %bitno + %bit = and i32 %tmp2, 1 + %lookup = getelementptr [2 x i1]* @lookup_table, i32 0, i32 %bit + ret i1* %lookup +} + +define i1 @c7(i32* %q, i32 %bitno) { + %ptr = call i1* @lookup_bit(i32* %q, i32 %bitno) + %val = load i1* %ptr + ret i1 %val +} + + +define i32 @nc1(i32* %q, i32* %p, i1 %b) { +e: + br label %l +l: + %x = phi i32* [ %p, %e ] + %y = phi i32* [ %q, %e ] + %tmp = bitcast i32* %x to i32* ; <i32*> [#uses=2] + %tmp2 = select i1 %b, i32* %tmp, i32* %y + %val = load i32* %tmp2 ; <i32> [#uses=1] + store i32 0, i32* %tmp + store i32* %y, i32** @g + ret i32 %val +} + +define void @nc2(i32* %p, i32* %q) { + %1 = call i32 @nc1(i32* %q, i32* %p, i1 0) ; <i32> [#uses=0] + ret void +} + +define void @nc3(void ()* %p) { + call void %p() + ret void +} + +declare void @external(i8*) readonly nounwind +define void @nc4(i8* %p) { + call void @external(i8* %p) + ret void +} + +define void @nc5(void (i8*)* %f, i8* %p) { + call void %f(i8* %p) readonly nounwind + call void %f(i8* nocapture %p) + ret void +} diff --git a/test/Transforms/FunctionAttrs/2009-01-02-LocalStores.ll b/test/Transforms/FunctionAttrs/2009-01-02-LocalStores.ll new file mode 100644 index 0000000..68a232f --- /dev/null +++ b/test/Transforms/FunctionAttrs/2009-01-02-LocalStores.ll @@ -0,0 +1,14 @@ +; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | not grep {nocapture *%%q} +; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | grep {nocapture *%%p} + +define i32* @a(i32** %p) { + %tmp = load i32** %p + ret i32* %tmp +} + +define i32* @b(i32 *%q) { + %mem = alloca i32* + store i32* %q, i32** %mem + %tmp = call i32* @a(i32** %mem) + ret i32* %tmp +} diff --git a/test/Transforms/FunctionAttrs/2009-05-06-Malloc.ll b/test/Transforms/FunctionAttrs/2009-05-06-Malloc.ll new file mode 100644 index 0000000..4022033 --- /dev/null +++ b/test/Transforms/FunctionAttrs/2009-05-06-Malloc.ll @@ -0,0 +1,7 @@ +; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | not grep read +; PR3754 + +define i8* @m(i32 %size) { + %tmp = malloc i8, i32 %size ; <i8*> [#uses=1] + ret i8* %tmp +} diff --git a/test/Transforms/FunctionAttrs/dg.exp b/test/Transforms/FunctionAttrs/dg.exp new file mode 100644 index 0000000..f200589 --- /dev/null +++ b/test/Transforms/FunctionAttrs/dg.exp @@ -0,0 +1,3 @@ +load_lib llvm.exp + +RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]] |