It's not necessary to do rounding for alloca operations when the requested
alignment is equal to the stack alignment.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40004 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Transforms/SimplifyLibCalls/2005-05-20-sprintf-crash.ll b/test/Transforms/SimplifyLibCalls/2005-05-20-sprintf-crash.ll
new file mode 100644
index 0000000..5b4fde8
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/2005-05-20-sprintf-crash.ll
@@ -0,0 +1,10 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -simplify-libcalls -disable-output
+
+%G = constant [3 x sbyte] c"%s\00"
+
+declare int %sprintf(sbyte*, sbyte*, ...)
+
+void %foo(sbyte*%P, int *%X) {
+  call int(sbyte*,sbyte*, ...)* %sprintf(sbyte* %P, sbyte* getelementptr ([3 x sbyte]* %G, int 0, int 0), int* %X)
+  ret void
+}
diff --git a/test/Transforms/SimplifyLibCalls/2007-04-06-strchr-miscompile.ll b/test/Transforms/SimplifyLibCalls/2007-04-06-strchr-miscompile.ll
new file mode 100644
index 0000000..5a56d24
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/2007-04-06-strchr-miscompile.ll
@@ -0,0 +1,29 @@
+; PR1307
+; RUN: llvm-as < %s | opt -simplify-libcalls -instcombine | llvm-dis > %t
+; RUN: grep {@str,.*i64 3} %t
+; RUN: grep {@str1,.*i64 7} %t
+; RUN: grep {ret i8.*null} %t
+; END.
+
+@str = internal constant [5 x i8] c"foog\00"
+@str1 = internal constant [8 x i8] c"blahhh!\00"
+@str2 = internal constant [5 x i8] c"Ponk\00"
+
+define i8* @test1() {
+        %tmp3 = tail call i8* @strchr( i8* getelementptr ([5 x i8]* @str, i32 0, i32 2), i32 103 )              ; <i8*> [#uses=1]
+        ret i8* %tmp3
+}
+
+declare i8* @strchr(i8*, i32)
+
+define i8* @test2() {
+        %tmp3 = tail call i8* @strchr( i8* getelementptr ([8 x i8]* @str1, i32 0, i32 2), i32 0 )               ; <i8*> [#uses=1]
+        ret i8* %tmp3
+}
+
+define i8* @test3() {
+entry:
+        %tmp3 = tail call i8* @strchr( i8* getelementptr ([5 x i8]* @str2, i32 0, i32 1), i32 80 )              ; <i8*> [#uses=1]
+        ret i8* %tmp3
+}
+
diff --git a/test/Transforms/SimplifyLibCalls/ExitInMain.ll b/test/Transforms/SimplifyLibCalls/ExitInMain.ll
new file mode 100644
index 0000000..13f1a11
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/ExitInMain.ll
@@ -0,0 +1,15 @@
+; Test that the ExitInMainOptimization pass works correctly
+; RUN: llvm-upgrade < %s | llvm-as | opt -simplify-libcalls | llvm-dis | \
+; RUN:    grep -c {ret i32 3} | grep 1
+; END.
+
+declare void %exit(int)
+declare void %exitonly(int)
+
+implementation   ; Functions:
+
+int %main () {
+        call void %exitonly ( int 3 )
+        call void %exit ( int 3 )
+        ret int 0
+}
diff --git a/test/Transforms/SimplifyLibCalls/FFS.ll b/test/Transforms/SimplifyLibCalls/FFS.ll
new file mode 100644
index 0000000..7049b5a
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/FFS.ll
@@ -0,0 +1,29 @@
+; Test that the ToAsciiOptimizer works correctly
+; RUN: llvm-upgrade < %s | llvm-as | opt -simplify-libcalls | llvm-dis | \
+; RUN:   not grep {call.*%ffs}
+
+declare int %ffs(int)
+declare int %ffsl(int)
+declare int %ffsll(long)
+
+%non_const = external global int
+
+implementation   ; Functions:
+
+int %main () {
+  %arg  = load int* %non_const
+  %val0 = call int %ffs(int %arg)
+  %val1 = call int %ffs(int 1)
+  %val2 = call int %ffs(int 2048)
+  %val3 = call int %ffsl(int 65536)
+  %val4 = call int %ffsll(long 1024)
+  %val5 = call int %ffsll(long 17179869184)
+  %val6 = call int %ffsll(long 1152921504606846976)
+  %rslt1 = add int %val1, %val2
+  %rslt2 = add int %val3, %val4
+  %rslt3 = add int %val5, %val6
+  %rslt4 = add int %rslt1, %rslt2
+  %rslt5 = add int %rslt4, %rslt3
+  %rslt6 = add int %rslt5, %val0
+  ret int %rslt5
+}
diff --git a/test/Transforms/SimplifyLibCalls/FPrintF.ll b/test/Transforms/SimplifyLibCalls/FPrintF.ll
new file mode 100644
index 0000000..53b751f
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/FPrintF.ll
@@ -0,0 +1,29 @@
+; Test that the FPrintFOptimizer works correctly
+; RUN: llvm-upgrade < %s | llvm-as | opt -simplify-libcalls | llvm-dis | \
+; RUN:   not grep {call.*fprintf}
+;
+
+%struct._IO_FILE = type { int, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, %struct._IO_marker*, %struct._IO_FILE*, int, int, int, ushort, sbyte, [1 x sbyte], sbyte*, long, sbyte*, sbyte*, int, [52 x sbyte] }
+%struct._IO_marker = type { %struct._IO_marker*, %struct._IO_FILE*, int }
+
+%str = constant [3 x sbyte] c"%s\00"		
+%chr = constant [3 x sbyte] c"%c\00"		
+%hello = constant [13 x sbyte] c"hello world\0A\00"
+%stdout = external global %struct._IO_FILE*		
+
+declare int %fprintf(%struct._IO_FILE*, sbyte*, ...)
+
+implementation  
+
+int %foo() 
+{
+entry:
+	%tmp.1 = load %struct._IO_FILE** %stdout
+	%tmp.0 = call int (%struct._IO_FILE*, sbyte*, ...)* %fprintf( %struct._IO_FILE* %tmp.1, sbyte* getelementptr ([13 x sbyte]* %hello, int 0, int 0) )
+	%tmp.4 = load %struct._IO_FILE** %stdout
+	%tmp.3 = call int (%struct._IO_FILE*, sbyte*, ...)* %fprintf( %struct._IO_FILE* %tmp.4, sbyte* getelementptr ([3 x sbyte]* %str, int 0, int 0), sbyte* getelementptr ([13 x sbyte]* %hello, int 0, int 0) )
+	%tmp.8 = load %struct._IO_FILE** %stdout
+	%tmp.7 = call int (%struct._IO_FILE*, sbyte*, ...)* %fprintf( %struct._IO_FILE* %tmp.8, sbyte* getelementptr ([3 x sbyte]* %chr, int 0, int 0), int 33 )
+	ret int 0
+}
+
diff --git a/test/Transforms/SimplifyLibCalls/IsDigit.ll b/test/Transforms/SimplifyLibCalls/IsDigit.ll
new file mode 100644
index 0000000..bcdb60c
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/IsDigit.ll
@@ -0,0 +1,21 @@
+; Test that the IsDigitOptimizer works correctly
+; RUN: llvm-upgrade < %s | llvm-as | opt -simplify-libcalls | llvm-dis | \
+; RUN:   not grep call
+
+declare int %isdigit(int)
+declare int %isascii(int)
+
+implementation   ; Functions:
+
+int %main () {
+  %val1 = call int %isdigit(int 47)
+  %val2 = call int %isdigit(int 48)
+  %val3 = call int %isdigit(int 57)
+  %val4 = call int %isdigit(int 58)
+  %rslt1 = add int %val1, %val2
+  %rslt2 = add int %val3, %val4
+  %sum = add int %rslt1, %rslt2
+  %rslt = call int %isdigit(int %sum)
+  %tmp = call int %isascii(int %rslt)
+  ret int %tmp
+}
diff --git a/test/Transforms/SimplifyLibCalls/MemCpy.ll b/test/Transforms/SimplifyLibCalls/MemCpy.ll
new file mode 100644
index 0000000..0a99488
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/MemCpy.ll
@@ -0,0 +1,22 @@
+; Test that the StrCatOptimizer works correctly
+; RUN: llvm-upgrade < %s | llvm-as | opt -constprop -simplify-libcalls | \
+; RUN:   llvm-dis | not grep {call.*llvm.memcpy.i32}
+
+declare void %llvm.memcpy.i32(sbyte*,sbyte*,uint,uint)
+%h = constant [2 x sbyte] c"h\00"
+%hel = constant [4 x sbyte] c"hel\00"
+%hello_u = constant [8 x sbyte] c"hello_u\00"
+
+implementation   ; Functions:
+
+int %main () {
+  %h_p = getelementptr [2 x sbyte]* %h, int 0, int 0
+  %hel_p = getelementptr [4 x sbyte]* %hel, int 0, int 0
+  %hello_u_p = getelementptr [8 x sbyte]* %hello_u, int 0, int 0
+  %target = alloca [1024 x sbyte]
+  %target_p = getelementptr [1024 x sbyte]* %target, int 0, int 0
+  call void %llvm.memcpy.i32(sbyte* %target_p, sbyte* %h_p, uint 2, uint 2)
+  call void %llvm.memcpy.i32(sbyte* %target_p, sbyte* %hel_p, uint 4, uint 4)
+  call void %llvm.memcpy.i32(sbyte* %target_p, sbyte* %hello_u_p, uint 8, uint 8)
+  ret int 0
+}
diff --git a/test/Transforms/SimplifyLibCalls/MemMove.ll b/test/Transforms/SimplifyLibCalls/MemMove.ll
new file mode 100644
index 0000000..7c89d91
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/MemMove.ll
@@ -0,0 +1,22 @@
+; Test that the StrCatOptimizer works correctly
+; RUN: llvm-upgrade < %s | llvm-as | opt -constprop -simplify-libcalls | \
+; RUN:   llvm-dis | not grep {call.*llvm.memmove.i32}
+
+declare void %llvm.memmove.i32(sbyte*,sbyte*,uint,uint)
+%h = constant [2 x sbyte] c"h\00"
+%hel = constant [4 x sbyte] c"hel\00"
+%hello_u = constant [8 x sbyte] c"hello_u\00"
+
+implementation   ; Functions:
+
+int %main () {
+  %h_p = getelementptr [2 x sbyte]* %h, int 0, int 0
+  %hel_p = getelementptr [4 x sbyte]* %hel, int 0, int 0
+  %hello_u_p = getelementptr [8 x sbyte]* %hello_u, int 0, int 0
+  %target = alloca [1024 x sbyte]
+  %target_p = getelementptr [1024 x sbyte]* %target, int 0, int 0
+  call void %llvm.memmove.i32(sbyte* %target_p, sbyte* %h_p, uint 2, uint 2)
+  call void %llvm.memmove.i32(sbyte* %target_p, sbyte* %hel_p, uint 4, uint 4)
+  call void %llvm.memmove.i32(sbyte* %target_p, sbyte* %hello_u_p, uint 8, uint 8)
+  ret int 0
+}
diff --git a/test/Transforms/SimplifyLibCalls/MemSet.ll b/test/Transforms/SimplifyLibCalls/MemSet.ll
new file mode 100644
index 0000000..dbeef9d
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/MemSet.ll
@@ -0,0 +1,19 @@
+; Test that the LLVMMemSetOptimizer works correctly
+; RUN: llvm-upgrade < %s | llvm-as | opt -simplify-libcalls | llvm-dis | \
+; RUN:   not grep {call.*llvm.memset}
+; END.
+
+declare void %llvm.memset.i32(sbyte*,ubyte,uint,uint)
+
+implementation   ; Functions:
+
+int %main () {
+  %target = alloca [1024 x sbyte]
+  %target_p = getelementptr [1024 x sbyte]* %target, int 0, int 0
+  call void %llvm.memset.i32(sbyte* %target_p, ubyte 1, uint 0, uint 1)
+  call void %llvm.memset.i32(sbyte* %target_p, ubyte 1, uint 1, uint 1)
+  call void %llvm.memset.i32(sbyte* %target_p, ubyte 1, uint 2, uint 2)
+  call void %llvm.memset.i32(sbyte* %target_p, ubyte 1, uint 4, uint 4)
+  call void %llvm.memset.i32(sbyte* %target_p, ubyte 1, uint 8, uint 8)
+  ret int 0
+}
diff --git a/test/Transforms/SimplifyLibCalls/Pow.ll b/test/Transforms/SimplifyLibCalls/Pow.ll
new file mode 100644
index 0000000..773ba1e
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/Pow.ll
@@ -0,0 +1,24 @@
+; Testcase for calls to the standard C "pow" function
+;
+; Equivalent to: http://gcc.gnu.org/ml/gcc-patches/2003-02/msg01786.html
+; RUN: llvm-upgrade < %s | llvm-as | opt -simplify-libcalls | llvm-dis | \
+; RUN:   not grep {call double .pow}
+; END.
+
+declare double %pow(double, double)
+
+double %test1(double %X) {
+	%Y = call double %pow(double %X, double 0.0)
+	ret double %Y    ; x^0.0 always equals 1.0
+}
+
+double %test2(double %X) {
+	%Y = call double %pow(double %X, double -0.0)
+	ret double %Y    ; x^-0.0 always equals 1.0
+}
+
+double %test3(double %X) {
+	%Y = call double %pow(double 1.0, double %X)
+	ret double %Y    ; 1.0^x always equals 1.0
+}
+
diff --git a/test/Transforms/SimplifyLibCalls/Printf.ll b/test/Transforms/SimplifyLibCalls/Printf.ll
new file mode 100644
index 0000000..c892f03
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/Printf.ll
@@ -0,0 +1,21 @@
+; RUN: llvm-as < %s | opt -simplify-libcalls | llvm-dis | grep putchar
+; RUN: llvm-as < %s | opt -simplify-libcalls | llvm-dis | \
+; RUN:   not grep {call.*printf}
+
+@str = internal constant [13 x i8] c"hello world\0A\00"         ; <[13 x i8]*> [#uses=1]
+@str1 = internal constant [2 x i8] c"h\00"              ; <[2 x i8]*> [#uses=1]
+
+define void @foo() {
+entry:
+        %tmp1 = tail call i32 (i8*, ...)* @printf( i8* getelementptr ([13 x i8]* @str, i32 0, i32 0) )         ; <i32> [#uses=0]
+        ret void
+}
+
+declare i32 @printf(i8*, ...)
+
+define void @bar() {
+entry:
+        %tmp1 = tail call i32 (i8*, ...)* @printf( i8* getelementptr ([2 x i8]* @str1, i32 0, i32 0) )         ; <i32> [#uses=0]
+        ret void
+}
+
diff --git a/test/Transforms/SimplifyLibCalls/Puts.ll b/test/Transforms/SimplifyLibCalls/Puts.ll
new file mode 100644
index 0000000..795b15c
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/Puts.ll
@@ -0,0 +1,27 @@
+; Test that the PutsCatOptimizer works correctly
+; RUN: llvm-upgrade < %s | llvm-as | opt -simplify-libcalls | llvm-dis | \
+; RUN:   not grep {call.*fputs}
+;
+%struct._IO_FILE = type { int, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, sbyte*, %struct._IO_marker*, %struct._IO_FILE*, int, int, int, ushort, sbyte, [1 x sbyte], sbyte*, long, sbyte*, sbyte*, int, [52 x sbyte] }
+%struct._IO_marker = type { %struct._IO_marker*, %struct._IO_FILE*, int }
+%stdout = external global %struct._IO_FILE*		; <%struct._IO_FILE**> [#uses=1]
+
+declare int %fputs(sbyte*, %struct._IO_FILE*)
+
+%empty = constant [1 x sbyte] c"\00"
+%len1  = constant [2 x sbyte] c"A\00"
+%long  = constant [7 x sbyte] c"hello\0A\00"
+
+implementation   ; Functions:
+
+int %main() {
+entry:
+  %out = load %struct._IO_FILE** %stdout
+  %s1 = getelementptr [1 x sbyte]* %empty, int 0, int 0
+  %s2 = getelementptr [2 x sbyte]* %len1, int 0, int 0
+  %s3 = getelementptr [7 x sbyte]* %long, int 0, int 0
+  %a = call int %fputs( sbyte* %s1, %struct._IO_FILE* %out )
+  %b = call int %fputs( sbyte* %s2, %struct._IO_FILE* %out )
+  %c = call int %fputs( sbyte* %s3, %struct._IO_FILE* %out )
+  ret int 0
+}
diff --git a/test/Transforms/SimplifyLibCalls/SPrintF.ll b/test/Transforms/SimplifyLibCalls/SPrintF.ll
new file mode 100644
index 0000000..a8ad369
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/SPrintF.ll
@@ -0,0 +1,36 @@
+; Test that the SPrintFOptimizer works correctly
+; RUN: llvm-upgrade < %s | llvm-as | opt -simplify-libcalls | llvm-dis | \
+; RUN:   not grep {call.*sprintf}
+
+declare int %sprintf(sbyte*,sbyte*,...)
+declare int %puts(sbyte*)
+%hello = constant [6 x sbyte] c"hello\00"
+%null = constant [1 x sbyte] c"\00"
+%null_hello = constant [7 x sbyte] c"\00hello\00"
+%fmt1 = constant [3 x sbyte] c"%s\00"
+%fmt2 = constant [3 x sbyte] c"%c\00"
+
+implementation   ; Functions:
+
+int %foo (sbyte* %p) {
+  %target = alloca [1024 x sbyte]
+  %target_p = getelementptr [1024 x sbyte]* %target, int 0, int 0
+  %hello_p = getelementptr [6 x sbyte]* %hello, int 0, int 0
+  %null_p = getelementptr [1 x sbyte]* %null, int 0, int 0
+  %nh_p = getelementptr [7 x sbyte]* %null_hello, int 0, int 0
+  %fmt1_p = getelementptr [3 x sbyte]* %fmt1, int 0, int 0
+  %fmt2_p = getelementptr [3 x sbyte]* %fmt2, int 0, int 0
+  store sbyte 0, sbyte* %target_p
+  %r1 = call int (sbyte*,sbyte*,...)* %sprintf(sbyte* %target_p, sbyte* %hello_p)
+  %r2 = call int (sbyte*,sbyte*,...)* %sprintf(sbyte* %target_p, sbyte* %null_p)
+  %r3 = call int (sbyte*,sbyte*,...)* %sprintf(sbyte* %target_p, sbyte* %nh_p)
+  %r4 = call int (sbyte*,sbyte*,...)* %sprintf(sbyte* %target_p, sbyte* %fmt1_p, sbyte* %hello_p)
+  %r4.1 = call int (sbyte*,sbyte*,...)* %sprintf(sbyte* %target_p, sbyte* %fmt1_p, sbyte* %p)
+  %r5 = call int (sbyte*,sbyte*,...)* %sprintf(sbyte* %target_p, sbyte* %fmt2_p, int 82)
+  %r6 = add int %r1, %r2
+  %r7 = add int %r3, %r6
+  %r8 = add int %r5, %r7
+  %r9 = add int %r8, %r4
+  %r10 = add int %r9, %r4.1
+  ret int %r10
+}
diff --git a/test/Transforms/SimplifyLibCalls/StrCat.ll b/test/Transforms/SimplifyLibCalls/StrCat.ll
new file mode 100644
index 0000000..06bc833
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/StrCat.ll
@@ -0,0 +1,25 @@
+; Test that the StrCatOptimizer works correctly
+; RUN: llvm-upgrade < %s | llvm-as | opt -simplify-libcalls | llvm-dis | \
+; RUN:   not grep {call.*strcat}
+
+declare sbyte* %strcat(sbyte*,sbyte*)
+declare int %puts(sbyte*)
+%hello = constant [6 x sbyte] c"hello\00"
+%null = constant [1 x sbyte] c"\00"
+%null_hello = constant [7 x sbyte] c"\00hello\00"
+
+implementation   ; Functions:
+
+int %main () {
+  %target = alloca [1024 x sbyte]
+  %arg1 = getelementptr [1024 x sbyte]* %target, int 0, int 0
+  store sbyte 0, sbyte* %arg1
+  %arg2 = getelementptr [6 x sbyte]* %hello, int 0, int 0
+  %rslt1 = call sbyte* %strcat(sbyte* %arg1, sbyte* %arg2)
+  %arg3 = getelementptr [1 x sbyte]* %null, int 0, int 0
+  %rslt2 = call sbyte* %strcat(sbyte* %rslt1, sbyte* %arg3)
+  %arg4 = getelementptr [7 x sbyte]* %null_hello, int 0, int 0
+  %rslt3 = call sbyte* %strcat(sbyte* %rslt2, sbyte* %arg4)
+  call int %puts(sbyte* %rslt3)
+  ret int 0
+}
diff --git a/test/Transforms/SimplifyLibCalls/StrChr.ll b/test/Transforms/SimplifyLibCalls/StrChr.ll
new file mode 100644
index 0000000..56e6248
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/StrChr.ll
@@ -0,0 +1,22 @@
+; Test that the StrChrOptimizer works correctly
+; RUN: llvm-upgrade < %s | llvm-as | opt -simplify-libcalls | llvm-dis | \
+; RUN:   not grep {call.*%strchr}
+
+declare sbyte* %strchr(sbyte*,int)
+declare int %puts(sbyte*)
+%hello = constant [14 x sbyte] c"hello world\n\00"
+%null = constant [1 x sbyte] c"\00"
+
+implementation   ; Functions:
+
+int %main () {
+  %hello_p = getelementptr [14 x sbyte]* %hello, int 0, int 0
+  %null_p = getelementptr [1 x sbyte]* %null, int 0, int 0
+
+  %world  = call sbyte* %strchr(sbyte* %hello_p, int 119 )
+  %ignore = call sbyte* %strchr(sbyte* %null_p, int 119 )
+  %len = call int %puts(sbyte* %world)
+  %index = add int %len, 112
+  %result = call sbyte* %strchr(sbyte* %hello_p, int %index)
+  ret int %index
+}
diff --git a/test/Transforms/SimplifyLibCalls/StrCmp.ll b/test/Transforms/SimplifyLibCalls/StrCmp.ll
new file mode 100644
index 0000000..ba2a4e0
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/StrCmp.ll
@@ -0,0 +1,27 @@
+; Test that the StrCmpOptimizer works correctly
+; RUN: llvm-upgrade < %s | llvm-as | opt -simplify-libcalls | llvm-dis | \
+; RUN:   not grep {call.*strcmp}
+
+declare int %strcmp(sbyte*,sbyte*)
+declare int %puts(sbyte*)
+%hello = constant [6 x sbyte] c"hello\00"
+%hell = constant [5 x sbyte] c"hell\00"
+%null = constant [1 x sbyte] c"\00"
+
+implementation   ; Functions:
+
+int %main () {
+  %hello_p = getelementptr [6 x sbyte]* %hello, int 0, int 0
+  %hell_p  = getelementptr [5 x sbyte]* %hell, int 0, int 0
+  %null_p  = getelementptr [1 x sbyte]* %null, int 0, int 0
+  %temp1 = call int %strcmp(sbyte* %hello_p, sbyte* %hello_p)
+  %temp2 = call int %strcmp(sbyte* %null_p, sbyte* %null_p)
+  %temp3 = call int %strcmp(sbyte* %hello_p, sbyte* %null_p)
+  %temp4 = call int %strcmp(sbyte* %null_p, sbyte* %hello_p)
+  %temp5 = call int %strcmp(sbyte* %hell_p, sbyte* %hello_p)
+  %rslt1 = add int %temp1, %temp2
+  %rslt2 = add int %rslt1, %temp3
+  %rslt3 = add int %rslt2, %temp4
+  %rslt4 = add int %rslt3, %temp5
+  ret int %rslt4
+}
diff --git a/test/Transforms/SimplifyLibCalls/StrCpy.ll b/test/Transforms/SimplifyLibCalls/StrCpy.ll
new file mode 100644
index 0000000..481dccf
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/StrCpy.ll
@@ -0,0 +1,25 @@
+; Test that the StrCpyOptimizer works correctly
+; RUN: llvm-upgrade < %s | llvm-as | opt -simplify-libcalls | llvm-dis | \
+; RUN:   not grep {call.*strcpy}
+
+declare sbyte* %strcpy(sbyte*,sbyte*)
+declare int %puts(sbyte*)
+%hello = constant [6 x sbyte] c"hello\00"
+%null = constant [1 x sbyte] c"\00"
+%null_hello = constant [7 x sbyte] c"\00hello\00"
+
+implementation   ; Functions:
+
+int %main () {
+  %target = alloca [1024 x sbyte]
+  %arg1 = getelementptr [1024 x sbyte]* %target, int 0, int 0
+  store sbyte 0, sbyte* %arg1
+  %arg2 = getelementptr [6 x sbyte]* %hello, int 0, int 0
+  %rslt1 = call sbyte* %strcpy(sbyte* %arg1, sbyte* %arg2)
+  %arg3 = getelementptr [1 x sbyte]* %null, int 0, int 0
+  %rslt2 = call sbyte* %strcpy(sbyte* %rslt1, sbyte* %arg3)
+  %arg4 = getelementptr [7 x sbyte]* %null_hello, int 0, int 0
+  %rslt3 = call sbyte* %strcpy(sbyte* %rslt2, sbyte* %arg4)
+  call int %puts(sbyte* %rslt3)
+  ret int 0
+}
diff --git a/test/Transforms/SimplifyLibCalls/StrLen.ll b/test/Transforms/SimplifyLibCalls/StrLen.ll
new file mode 100644
index 0000000..98a76c8
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/StrLen.ll
@@ -0,0 +1,58 @@
+; Test that the StrCatOptimizer works correctly
+; RUN: llvm-upgrade < %s | llvm-as | opt -simplify-libcalls | llvm-dis | \
+; RUN:    not grep {call.*strlen}
+
+target datalayout = "e-p:32:32"
+
+declare uint %strlen(sbyte*)
+%hello      = constant [6 x sbyte] c"hello\00"
+%null       = constant [1 x sbyte] c"\00"
+%null_hello = constant [7 x sbyte] c"\00hello\00"
+
+implementation   ; Functions:
+
+uint %test1() {
+  %hello_p      = getelementptr [6 x sbyte]* %hello, int 0, int 0
+  %hello_l      = call uint %strlen(sbyte* %hello_p)
+  ret uint %hello_l
+}
+
+uint %test2() {
+  %null_p       = getelementptr [1 x sbyte]* %null, int 0, int 0
+  %null_l       = call uint %strlen(sbyte* %null_p)
+  ret uint %null_l
+}
+
+uint %test3() {
+  %null_hello_p = getelementptr [7 x sbyte]* %null_hello, int 0, int 0
+  %null_hello_l = call uint %strlen(sbyte* %null_hello_p)
+  ret uint %null_hello_l
+}
+
+bool %test4() {
+  %hello_p      = getelementptr [6 x sbyte]* %hello, int 0, int 0
+  %hello_l      = call uint %strlen(sbyte* %hello_p)
+  %eq_hello     = seteq uint %hello_l, 0
+  ret bool %eq_hello
+}
+
+bool %test5() {
+  %null_p       = getelementptr [1 x sbyte]* %null, int 0, int 0
+  %null_l       = call uint %strlen(sbyte* %null_p)
+  %eq_null      = seteq uint %null_l, 0
+  ret bool %eq_null
+}
+
+bool %test6() {
+  %hello_p      = getelementptr [6 x sbyte]* %hello, int 0, int 0
+  %hello_l      = call uint %strlen(sbyte* %hello_p)
+  %ne_hello     = setne uint %hello_l, 0
+  ret bool %ne_hello
+}
+
+bool %test7() {
+  %null_p       = getelementptr [1 x sbyte]* %null, int 0, int 0
+  %null_l       = call uint %strlen(sbyte* %null_p)
+  %ne_null      = setne uint %null_l, 0
+  ret bool %ne_null
+}
diff --git a/test/Transforms/SimplifyLibCalls/StrNCmp.ll b/test/Transforms/SimplifyLibCalls/StrNCmp.ll
new file mode 100644
index 0000000..7de3410f
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/StrNCmp.ll
@@ -0,0 +1,27 @@
+; Test that the StrNCmpOptimizer works correctly
+; RUN: llvm-upgrade < %s | llvm-as | opt -simplify-libcalls | llvm-dis | \
+; RUN:   not grep {call.*strncmp}
+
+declare int %strncmp(sbyte*,sbyte*,int)
+declare int %puts(sbyte*)
+%hello = constant [6 x sbyte] c"hello\00"
+%hell = constant [5 x sbyte] c"hell\00"
+%null = constant [1 x sbyte] c"\00"
+
+implementation   ; Functions:
+
+int %main () {
+  %hello_p = getelementptr [6 x sbyte]* %hello, int 0, int 0
+  %hell_p  = getelementptr [5 x sbyte]* %hell, int 0, int 0
+  %null_p  = getelementptr [1 x sbyte]* %null, int 0, int 0
+  %temp1 = call int %strncmp(sbyte* %hello_p, sbyte* %hello_p,int 5)
+  %temp2 = call int %strncmp(sbyte* %null_p, sbyte* %null_p,int 0)
+  %temp3 = call int %strncmp(sbyte* %hello_p, sbyte* %null_p,int 0)
+  %temp4 = call int %strncmp(sbyte* %null_p, sbyte* %hello_p,int 0)
+  %temp5 = call int %strncmp(sbyte* %hell_p, sbyte* %hello_p,int 4)
+  %rslt1 = add int %temp1, %temp2
+  %rslt2 = add int %rslt1, %temp3
+  %rslt3 = add int %rslt2, %temp4
+  %rslt4 = add int %rslt3, %temp5
+  ret int %rslt4
+}
diff --git a/test/Transforms/SimplifyLibCalls/ToAscii.ll b/test/Transforms/SimplifyLibCalls/ToAscii.ll
new file mode 100644
index 0000000..0bc2664
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/ToAscii.ll
@@ -0,0 +1,22 @@
+; Test that the ToAsciiOptimizer works correctly
+; RUN: llvm-upgrade < %s | llvm-as | opt -simplify-libcalls | llvm-dis | \
+; RUN:   not grep {call.*toascii}
+
+declare int %toascii(int)
+
+implementation   ; Functions:
+
+int %main () {
+  %val1 = call int %toascii(int 1)
+  %val2 = call int %toascii(int 0)
+  %val3 = call int %toascii(int 127)
+  %val4 = call int %toascii(int 128)
+  %val5 = call int %toascii(int 255)
+  %val6 = call int %toascii(int 256)
+  %rslt1 = add int %val1, %val2
+  %rslt2 = add int %val3, %val4
+  %rslt3 = add int %val5, %val6
+  %rslt4 = add int %rslt1, %rslt2
+  %rslt5 = add int %rslt4, %rslt3
+  ret int %rslt5
+}
diff --git a/test/Transforms/SimplifyLibCalls/dg.exp b/test/Transforms/SimplifyLibCalls/dg.exp
new file mode 100644
index 0000000..879685c
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,llx,c,cpp,tr}]]
diff --git a/test/Transforms/SimplifyLibCalls/floor.ll b/test/Transforms/SimplifyLibCalls/floor.ll
new file mode 100644
index 0000000..2b940fd
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/floor.ll
@@ -0,0 +1,34 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -simplify-libcalls | llvm-dis > %t
+; RUN: not grep {call.*floor(} %t
+; RUN: grep {call.*floorf(} %t
+; RUN: not grep {call.*ceil(} %t
+; RUN: grep {call.*ceilf(} %t
+; RUN: not grep {call.*nearbyint(} %t
+; RUN: grep {call.*nearbyintf(} %t
+; XFAIL: sparc
+
+declare double %floor(double)
+declare double %ceil(double)
+declare double %nearbyint(double)
+
+float %test_floor(float %C) {
+	%D = cast float %C to double
+	%E = call double %floor(double %D)  ; --> floorf
+	%F = cast double %E to float
+	ret float %F
+}
+
+float %test_ceil(float %C) {
+	%D = cast float %C to double
+	%E = call double %ceil(double %D)  ; --> ceilf
+	%F = cast double %E to float
+	ret float %F
+}
+
+float %test_nearbyint(float %C) {
+	%D = cast float %C to double
+	%E = call double %nearbyint(double %D)  ; --> floorf
+	%F = cast double %E to float
+	ret float %F
+}
+
diff --git a/test/Transforms/SimplifyLibCalls/memcmp.ll b/test/Transforms/SimplifyLibCalls/memcmp.ll
new file mode 100644
index 0000000..bea9eed
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/memcmp.ll
@@ -0,0 +1,24 @@
+; Test that the memcmpOptimizer works correctly
+; RUN: llvm-upgrade < %s | llvm-as | opt -simplify-libcalls | llvm-dis | \
+; RUN:   not grep {call.*memcmp}
+; RUN: llvm-upgrade < %s | llvm-as | opt -simplify-libcalls -disable-output
+
+declare int %memcmp(sbyte*,sbyte*,int)
+%h = constant [2 x sbyte] c"h\00"
+%hel = constant [4 x sbyte] c"hel\00"
+%hello_u = constant [8 x sbyte] c"hello_u\00"
+
+implementation
+
+void %test(sbyte *%P, sbyte *%Q, int %N, int* %IP, bool *%BP) {
+  %A = call int %memcmp(sbyte *%P, sbyte* %P, int %N)
+  volatile store int %A, int* %IP
+  %B = call int %memcmp(sbyte *%P, sbyte* %Q, int 0)
+  volatile store int %B, int* %IP
+  %C = call int %memcmp(sbyte *%P, sbyte* %Q, int 1)
+  volatile store int %C, int* %IP
+  %D = call int %memcmp(sbyte *%P, sbyte* %Q, int 2)
+  %E = seteq int %D, 0
+  volatile store bool %E, bool* %BP
+  ret void
+}