aboutsummaryrefslogtreecommitdiffstats
path: root/test/Transforms/Mem2Reg
diff options
context:
space:
mode:
Diffstat (limited to 'test/Transforms/Mem2Reg')
-rw-r--r--test/Transforms/Mem2Reg/2002-03-28-UninitializedVal.ll13
-rw-r--r--test/Transforms/Mem2Reg/2002-05-01-ShouldNotPromoteThisAlloca.ll15
-rw-r--r--test/Transforms/Mem2Reg/2003-04-10-DFNotFound.ll11
-rw-r--r--test/Transforms/Mem2Reg/2003-04-18-DeadBlockProblem.ll17
-rw-r--r--test/Transforms/Mem2Reg/2003-04-24-MultipleIdenticalSuccessors.ll15
-rw-r--r--test/Transforms/Mem2Reg/2003-06-26-IterativePromote.ll16
-rw-r--r--test/Transforms/Mem2Reg/2003-10-05-DeadPHIInsertion.ll21
-rw-r--r--test/Transforms/Mem2Reg/2005-06-30-ReadBeforeWrite.ll51
-rw-r--r--test/Transforms/Mem2Reg/2005-11-28-Crash.ll88
-rw-r--r--test/Transforms/Mem2Reg/PromoteMemToRegister.ll24
-rw-r--r--test/Transforms/Mem2Reg/UndefValuesMerge.ll14
-rw-r--r--test/Transforms/Mem2Reg/dg.exp3
12 files changed, 288 insertions, 0 deletions
diff --git a/test/Transforms/Mem2Reg/2002-03-28-UninitializedVal.ll b/test/Transforms/Mem2Reg/2002-03-28-UninitializedVal.ll
new file mode 100644
index 0000000..b277659
--- /dev/null
+++ b/test/Transforms/Mem2Reg/2002-03-28-UninitializedVal.ll
@@ -0,0 +1,13 @@
+; Uninitialized values are not handled correctly.
+;
+; RUN: llvm-upgrade < %s | llvm-as | opt -mem2reg
+;
+
+implementation
+
+int "test"()
+begin
+ %X = alloca int ; To be promoted
+ %Y = load int* %X
+ ret int %Y
+end
diff --git a/test/Transforms/Mem2Reg/2002-05-01-ShouldNotPromoteThisAlloca.ll b/test/Transforms/Mem2Reg/2002-05-01-ShouldNotPromoteThisAlloca.ll
new file mode 100644
index 0000000..c3d803c
--- /dev/null
+++ b/test/Transforms/Mem2Reg/2002-05-01-ShouldNotPromoteThisAlloca.ll
@@ -0,0 +1,15 @@
+; This input caused the mem2reg pass to die because it was trying to promote
+; the %r alloca, even though it is invalid to do so in this case!
+;
+; RUN: llvm-upgrade < %s | llvm-as | opt -mem2reg
+
+
+implementation
+
+void "test"()
+begin
+ %r = alloca int ; <int*> [#uses=2]
+ store int 4, int* %r
+ store int* %r, int** null
+ ret void
+end
diff --git a/test/Transforms/Mem2Reg/2003-04-10-DFNotFound.ll b/test/Transforms/Mem2Reg/2003-04-10-DFNotFound.ll
new file mode 100644
index 0000000..918431a
--- /dev/null
+++ b/test/Transforms/Mem2Reg/2003-04-10-DFNotFound.ll
@@ -0,0 +1,11 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -mem2reg
+
+implementation ; Functions:
+
+void %_Z3barv() {
+ %result = alloca int
+ ret void
+
+ store int 0, int* %result ; DF not set!
+ ret void
+}
diff --git a/test/Transforms/Mem2Reg/2003-04-18-DeadBlockProblem.ll b/test/Transforms/Mem2Reg/2003-04-18-DeadBlockProblem.ll
new file mode 100644
index 0000000..d6f1b77
--- /dev/null
+++ b/test/Transforms/Mem2Reg/2003-04-18-DeadBlockProblem.ll
@@ -0,0 +1,17 @@
+; This testcases makes sure that mem2reg can handle unreachable blocks.
+; RUN: llvm-upgrade < %s | llvm-as | opt -mem2reg
+
+int %test() {
+ %X = alloca int
+
+ store int 6, int* %X
+ br label %Loop
+Loop:
+ store int 5, int* %X
+ br label %EndOfLoop
+Unreachable:
+ br label %EndOfLoop
+
+EndOfLoop:
+ br label %Loop
+}
diff --git a/test/Transforms/Mem2Reg/2003-04-24-MultipleIdenticalSuccessors.ll b/test/Transforms/Mem2Reg/2003-04-24-MultipleIdenticalSuccessors.ll
new file mode 100644
index 0000000..7cd38c2
--- /dev/null
+++ b/test/Transforms/Mem2Reg/2003-04-24-MultipleIdenticalSuccessors.ll
@@ -0,0 +1,15 @@
+; Mem2reg used to only add one incoming value to a PHI node, even if it had
+; multiple incoming edges from a block.
+;
+; RUN: llvm-upgrade < %s | llvm-as | opt -mem2reg -disable-output
+
+int %test(bool %c1, bool %c2) {
+ %X = alloca int
+ br bool %c1, label %Exit, label %B2
+B2:
+ store int 2, int* %X
+ br bool %c2, label %Exit, label %Exit
+Exit:
+ %Y = load int *%X
+ ret int %Y
+}
diff --git a/test/Transforms/Mem2Reg/2003-06-26-IterativePromote.ll b/test/Transforms/Mem2Reg/2003-06-26-IterativePromote.ll
new file mode 100644
index 0000000..ce274fa
--- /dev/null
+++ b/test/Transforms/Mem2Reg/2003-06-26-IterativePromote.ll
@@ -0,0 +1,16 @@
+; Promoting some values allows promotion of other values.
+; RUN: llvm-upgrade < %s | llvm-as | opt -mem2reg | llvm-dis | not grep alloca
+
+int %test2() {
+ %result = alloca int ; ty=int*
+ %a = alloca int ; ty=int*
+ %p = alloca int* ; ty=int**
+ store int 0, int* %a
+ store int* %a, int** %p
+ %tmp.0 = load int** %p ; ty=int*
+ %tmp.1 = load int* %tmp.0 ; ty=int
+ store int %tmp.1, int* %result
+ %tmp.2 = load int* %result ; ty=int
+ ret int %tmp.2
+}
+
diff --git a/test/Transforms/Mem2Reg/2003-10-05-DeadPHIInsertion.ll b/test/Transforms/Mem2Reg/2003-10-05-DeadPHIInsertion.ll
new file mode 100644
index 0000000..ab4b661
--- /dev/null
+++ b/test/Transforms/Mem2Reg/2003-10-05-DeadPHIInsertion.ll
@@ -0,0 +1,21 @@
+; Mem2reg should not insert dead PHI nodes! The naive algorithm inserts a PHI
+; node in L3, even though there is no load of %A in anything dominated by L3.
+
+; RUN: llvm-upgrade < %s | llvm-as | opt -mem2reg | llvm-dis | not grep phi
+
+void %test(int %B, bool %C) {
+ %A = alloca int
+ store int %B, int* %A
+ br bool %C, label %L1, label %L2
+L1:
+ store int %B, int* %A
+ %D = load int* %A
+ call void %test(int %D, bool false)
+ br label %L3
+L2:
+ %E = load int* %A
+ call void %test(int %E, bool true)
+ br label %L3
+L3:
+ ret void
+}
diff --git a/test/Transforms/Mem2Reg/2005-06-30-ReadBeforeWrite.ll b/test/Transforms/Mem2Reg/2005-06-30-ReadBeforeWrite.ll
new file mode 100644
index 0000000..c64d848
--- /dev/null
+++ b/test/Transforms/Mem2Reg/2005-06-30-ReadBeforeWrite.ll
@@ -0,0 +1,51 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -mem2reg -instcombine | llvm-dis | grep store
+; PR590
+
+void %zero(sbyte* %p, int %n) {
+entry:
+ %p_addr = alloca sbyte* ; <sbyte**> [#uses=2]
+ %n_addr = alloca int ; <int*> [#uses=2]
+ %i = alloca int ; <int*> [#uses=6]
+ %out = alloca int ; <int*> [#uses=2]
+ %undef = alloca int ; <int*> [#uses=2]
+ store sbyte* %p, sbyte** %p_addr
+ store int %n, int* %n_addr
+ store int 0, int* %i
+ br label %loopentry
+
+loopentry: ; preds = %endif, %entry
+ %tmp.0 = load int* %n_addr ; <int> [#uses=1]
+ %tmp.1 = add int %tmp.0, 1 ; <int> [#uses=1]
+ %tmp.2 = load int* %i ; <int> [#uses=1]
+ %tmp.3 = setgt int %tmp.1, %tmp.2 ; <bool> [#uses=2]
+ %tmp.4 = cast bool %tmp.3 to int ; <int> [#uses=0]
+ br bool %tmp.3, label %no_exit, label %return
+
+no_exit: ; preds = %loopentry
+ %tmp.5 = load int* %undef ; <int> [#uses=1]
+ store int %tmp.5, int* %out
+ store int 0, int* %undef
+ %tmp.6 = load int* %i ; <int> [#uses=1]
+ %tmp.7 = setgt int %tmp.6, 0 ; <bool> [#uses=2]
+ %tmp.8 = cast bool %tmp.7 to int ; <int> [#uses=0]
+ br bool %tmp.7, label %then, label %endif
+
+then: ; preds = %no_exit
+ %tmp.9 = load sbyte** %p_addr ; <sbyte*> [#uses=1]
+ %tmp.10 = load int* %i ; <int> [#uses=1]
+ %tmp.11 = sub int %tmp.10, 1 ; <int> [#uses=1]
+ %tmp.12 = getelementptr sbyte* %tmp.9, int %tmp.11 ; <sbyte*> [#uses=1]
+ %tmp.13 = load int* %out ; <int> [#uses=1]
+ %tmp.14 = cast int %tmp.13 to sbyte ; <sbyte> [#uses=1]
+ store sbyte %tmp.14, sbyte* %tmp.12
+ br label %endif
+
+endif: ; preds = %then, %no_exit
+ %tmp.15 = load int* %i ; <int> [#uses=1]
+ %inc = add int %tmp.15, 1 ; <int> [#uses=1]
+ store int %inc, int* %i
+ br label %loopentry
+
+return: ; preds = %loopentry
+ ret void
+}
diff --git a/test/Transforms/Mem2Reg/2005-11-28-Crash.ll b/test/Transforms/Mem2Reg/2005-11-28-Crash.ll
new file mode 100644
index 0000000..01e8b85
--- /dev/null
+++ b/test/Transforms/Mem2Reg/2005-11-28-Crash.ll
@@ -0,0 +1,88 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -mem2reg -disable-output
+; PR670
+
+void %printk(int, ...) {
+entry:
+ %flags = alloca uint ; <uint*> [#uses=2]
+ br bool false, label %then.0, label %endif.0
+
+then.0: ; preds = %entry
+ br label %endif.0
+
+endif.0: ; preds = %then.0, %entry
+ store uint 0, uint* %flags
+ br label %loopentry
+
+loopentry: ; preds = %endif.3, %endif.0
+ br bool false, label %no_exit, label %loopexit
+
+no_exit: ; preds = %loopentry
+ br bool false, label %then.1, label %endif.1
+
+then.1: ; preds = %no_exit
+ br bool false, label %shortcirc_done.0, label %shortcirc_next.0
+
+shortcirc_next.0: ; preds = %then.1
+ br label %shortcirc_done.0
+
+shortcirc_done.0: ; preds = %shortcirc_next.0, %then.1
+ br bool false, label %shortcirc_done.1, label %shortcirc_next.1
+
+shortcirc_next.1: ; preds = %shortcirc_done.0
+ br label %shortcirc_done.1
+
+shortcirc_done.1: ; preds = %shortcirc_next.1, %shortcirc_done.0
+ br bool false, label %shortcirc_done.2, label %shortcirc_next.2
+
+shortcirc_next.2: ; preds = %shortcirc_done.1
+ br label %shortcirc_done.2
+
+shortcirc_done.2: ; preds = %shortcirc_next.2, %shortcirc_done.1
+ br bool false, label %then.2, label %endif.2
+
+then.2: ; preds = %shortcirc_done.2
+ br label %endif.2
+
+endif.2: ; preds = %then.2, %shortcirc_done.2
+ br label %endif.1
+
+endif.1: ; preds = %endif.2, %no_exit
+ br bool false, label %then.3, label %endif.3
+
+then.3: ; preds = %endif.1
+ br label %endif.3
+
+endif.3: ; preds = %then.3, %endif.1
+ br label %loopentry
+
+loopexit: ; preds = %loopentry
+ br label %endif.4
+
+then.4: ; No predecessors!
+ %tmp.61 = load uint* %flags ; <uint> [#uses=0]
+ br label %out
+
+dead_block_after_goto: ; No predecessors!
+ br label %endif.4
+
+endif.4: ; preds = %dead_block_after_goto, %loopexit
+ br bool false, label %then.5, label %else
+
+then.5: ; preds = %endif.4
+ br label %endif.5
+
+else: ; preds = %endif.4
+ br label %endif.5
+
+endif.5: ; preds = %else, %then.5
+ br label %out
+
+out: ; preds = %endif.5, %then.4
+ br label %return
+
+after_ret: ; No predecessors!
+ br label %return
+
+return: ; preds = %after_ret, %out
+ ret void
+}
diff --git a/test/Transforms/Mem2Reg/PromoteMemToRegister.ll b/test/Transforms/Mem2Reg/PromoteMemToRegister.ll
new file mode 100644
index 0000000..8bf7b51
--- /dev/null
+++ b/test/Transforms/Mem2Reg/PromoteMemToRegister.ll
@@ -0,0 +1,24 @@
+; Simple sanity check testcase. Both alloca's should be eliminated.
+; RUN: llvm-upgrade < %s | llvm-as | opt -mem2reg | llvm-dis | not grep alloca
+
+implementation
+
+double "testfunc"(int %i, double %j)
+begin
+ %I = alloca int
+ %J = alloca double
+
+ store int %i, int* %I
+ store double %j, double* %J
+
+ %t1 = load int* %I
+ %t2 = add int %t1, 1
+ store int %t2, int* %I
+
+ %t3 = load int* %I
+ %t4 = cast int %t3 to double
+ %t5 = load double* %J
+ %t6 = mul double %t4, %t5
+
+ ret double %t6
+end
diff --git a/test/Transforms/Mem2Reg/UndefValuesMerge.ll b/test/Transforms/Mem2Reg/UndefValuesMerge.ll
new file mode 100644
index 0000000..dc2f011
--- /dev/null
+++ b/test/Transforms/Mem2Reg/UndefValuesMerge.ll
@@ -0,0 +1,14 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -mem2reg | llvm-dis | not grep phi
+
+implementation
+
+int %testfunc(bool %C, int %i, sbyte %j) {
+ %I = alloca int
+ br bool %C, label %T, label %Cont
+T:
+ store int %i, int* %I
+ br label %Cont
+Cont:
+ %Y = load int* %I ;; %Y = phi %i, undef -> %Y = %i
+ ret int %Y
+}
diff --git a/test/Transforms/Mem2Reg/dg.exp b/test/Transforms/Mem2Reg/dg.exp
new file mode 100644
index 0000000..879685c
--- /dev/null
+++ b/test/Transforms/Mem2Reg/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,llx,c,cpp,tr}]]