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/LoopSimplify/2003-04-25-AssertFail.ll b/test/Transforms/LoopSimplify/2003-04-25-AssertFail.ll
new file mode 100644
index 0000000..90de721
--- /dev/null
+++ b/test/Transforms/LoopSimplify/2003-04-25-AssertFail.ll
@@ -0,0 +1,25 @@
+; This testcase exposed a problem with the loop identification pass (LoopInfo).
+; Basically, it was incorrectly calculating the loop nesting information.
+;
+; RUN: llvm-upgrade < %s | llvm-as | opt -loopsimplify
+
+implementation   ; Functions:
+
+int %yylex() {		; No predecessors!
+	br label %loopentry.0
+
+loopentry.0:		; preds = %0, %yy_find_action, %else.4
+	br label %loopexit.2
+
+loopexit.2:		; preds = %loopentry.0, %else.4, %loopexit.2
+	br bool false, label %loopexit.2, label %else.4
+
+yy_find_action:		; preds = %loopexit.2, %else.4
+	br label %else.4
+
+else.4:		; preds = %yy_find_action
+	switch uint 0, label %loopexit.2 [
+		 uint 2, label %yy_find_action
+		 uint 0, label %loopentry.0
+	]
+}
diff --git a/test/Transforms/LoopSimplify/2003-05-12-PreheaderExitOfChild.ll b/test/Transforms/LoopSimplify/2003-05-12-PreheaderExitOfChild.ll
new file mode 100644
index 0000000..0880da6
--- /dev/null
+++ b/test/Transforms/LoopSimplify/2003-05-12-PreheaderExitOfChild.ll
@@ -0,0 +1,57 @@
+; This (complex) testcase causes an assertion failure because a preheader is 
+; inserted for the "fail" loop, but the exit block of a loop is not updated
+; to be the preheader instead of the exit loop itself.
+
+; RUN: llvm-upgrade < %s | llvm-as | opt -loopsimplify
+
+int %re_match_2() {
+	br label %loopentry.1
+
+loopentry.1:		; preds = %then.6, %endif.7, %loopexit.20, %endif.83
+	br label %shortcirc_done.36
+
+shortcirc_done.36:		; preds = %label.13, %shortcirc_next.36
+	br bool false, label %fail, label %endif.40
+
+endif.40:		; preds = %shortcirc_done.36
+	br label %loopexit.20
+
+loopentry.20:		; preds = %shortcirc_done.40, %endif.46
+	br label %loopexit.20
+
+loopexit.20:		; preds = %loopentry.20
+	br label %loopentry.21
+
+loopentry.21:		; preds = %loopexit.20, %no_exit.19
+	br bool false, label %no_exit.19, label %loopexit.21
+
+no_exit.19:		; preds = %loopentry.21
+	br bool false, label %fail, label %loopentry.21
+
+loopexit.21:		; preds = %loopentry.21
+	br label %endif.45
+
+endif.45:		; preds = %loopexit.21
+	br label %cond_true.15
+
+cond_true.15:		; preds = %endif.45
+	br bool false, label %fail, label %endif.46
+
+endif.46:		; preds = %cond_true.15
+	br label %loopentry.20
+
+fail:		; preds = %shortcirc_done.36, %loopexit.37, %cond_true.15, %no_exit.19
+	br label %then.80
+
+then.80:		; preds = %fail
+	br label %endif.81
+
+endif.81:		; preds = %then.80
+	br label %loopexit.37
+
+loopexit.37:		; preds = %endif.81
+	br bool false, label %fail, label %endif.82
+
+endif.82:		; preds = %loopexit.37
+	br label %loopentry.1
+}
diff --git a/test/Transforms/LoopSimplify/2003-08-15-PreheadersFail.ll b/test/Transforms/LoopSimplify/2003-08-15-PreheadersFail.ll
new file mode 100644
index 0000000..59f49e3
--- /dev/null
+++ b/test/Transforms/LoopSimplify/2003-08-15-PreheadersFail.ll
@@ -0,0 +1,65 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -tailduplicate -instcombine -simplifycfg -licm -disable-output
+
+target endian = little
+target pointersize = 32
+%yy_base = external global [787 x short]		; <[787 x short]*> [#uses=1]
+%yy_state_ptr = external global int*		; <int**> [#uses=3]
+%yy_state_buf = external global [16386 x int]		; <[16386 x int]*> [#uses=1]
+%yy_lp = external global int		; <int*> [#uses=1]
+
+implementation   ; Functions:
+
+int %_yylex() {		; No predecessors!
+	br label %loopentry.0
+
+loopentry.0:		; preds = %0, %else.26
+	store int* getelementptr ([16386 x int]* %yy_state_buf, long 0, long 0), int** %yy_state_ptr
+	%tmp.35 = load int** %yy_state_ptr		; <int*> [#uses=2]
+	%inc.0 = getelementptr int* %tmp.35, long 1		; <int*> [#uses=1]
+	store int* %inc.0, int** %yy_state_ptr
+	%tmp.36 = load int* null		; <int> [#uses=1]
+	store int %tmp.36, int* %tmp.35
+	br label %loopexit.2
+
+loopexit.2:		; preds = %loopentry.0, %else.26, %loopexit.2
+	store sbyte* null, sbyte** null
+	%tmp.91 = load int* null		; <int> [#uses=1]
+	%tmp.92 = cast int %tmp.91 to long		; <long> [#uses=1]
+	%tmp.93 = getelementptr [787 x short]* %yy_base, long 0, long %tmp.92		; <short*> [#uses=1]
+	%tmp.94 = load short* %tmp.93		; <short> [#uses=1]
+	%tmp.95 = setne short %tmp.94, 4394		; <bool> [#uses=1]
+	br bool %tmp.95, label %loopexit.2, label %yy_find_action
+
+yy_find_action:		; preds = %loopexit.2, %else.26
+	br label %loopentry.3
+
+loopentry.3:		; preds = %yy_find_action, %shortcirc_done.0, %then.9
+	%tmp.105 = load int* %yy_lp		; <int> [#uses=1]
+	%tmp.106 = setne int %tmp.105, 0		; <bool> [#uses=1]
+	br bool %tmp.106, label %shortcirc_next.0, label %shortcirc_done.0
+
+shortcirc_next.0:		; preds = %loopentry.3
+	%tmp.114 = load short* null		; <short> [#uses=1]
+	%tmp.115 = cast short %tmp.114 to int		; <int> [#uses=1]
+	%tmp.116 = setlt int 0, %tmp.115		; <bool> [#uses=1]
+	br label %shortcirc_done.0
+
+shortcirc_done.0:		; preds = %loopentry.3, %shortcirc_next.0
+	%shortcirc_val.0 = phi bool [ false, %loopentry.3 ], [ %tmp.116, %shortcirc_next.0 ]		; <bool> [#uses=1]
+	br bool %shortcirc_val.0, label %else.0, label %loopentry.3
+
+else.0:		; preds = %shortcirc_done.0
+	%tmp.144 = load int* null		; <int> [#uses=1]
+	%tmp.145 = and int %tmp.144, 8192		; <int> [#uses=1]
+	%tmp.146 = setne int %tmp.145, 0		; <bool> [#uses=1]
+	br bool %tmp.146, label %then.9, label %else.26
+
+then.9:		; preds = %else.0
+	br label %loopentry.3
+
+else.26:		; preds = %else.1
+	switch uint 0, label %loopentry.0 [
+		 uint 2, label %yy_find_action
+		 uint 0, label %loopexit.2
+	]
+}
diff --git a/test/Transforms/LoopSimplify/2003-12-10-ExitBlocksProblem.ll b/test/Transforms/LoopSimplify/2003-12-10-ExitBlocksProblem.ll
new file mode 100644
index 0000000..e47112b
--- /dev/null
+++ b/test/Transforms/LoopSimplify/2003-12-10-ExitBlocksProblem.ll
@@ -0,0 +1,42 @@
+; LoopSimplify is breaking LICM on this testcase because the exit blocks from
+; the loop are reachable from more than just the exit nodes: the exit blocks
+; have predecessors from outside of the loop!
+;
+; This is distilled from a monsterous crafty example.
+
+; RUN: llvm-upgrade < %s | llvm-as | opt -licm -disable-output
+
+%G = weak global int 0		; <int*> [#uses=13]
+
+implementation   ; Functions:
+
+int %main() {
+entry:
+	store int 123, int* %G
+	br label %loopentry.i
+
+loopentry.i:		; preds = %entry, %endif.1.i
+	%tmp.0.i = load int* %G		; <int> [#uses=1]
+	%tmp.1.i = seteq int %tmp.0.i, 123		; <bool> [#uses=1]
+	br bool %tmp.1.i, label %Out.i, label %endif.0.i
+
+endif.0.i:		; preds = %loopentry.i
+	%tmp.3.i = load int* %G		; <int> [#uses=1]
+	%tmp.4.i = seteq int %tmp.3.i, 126		; <bool> [#uses=1]
+	br bool %tmp.4.i, label %ExitBlock.i, label %endif.1.i
+
+endif.1.i:		; preds = %endif.0.i
+	%tmp.6.i = load int* %G		; <int> [#uses=1]
+	%inc.i = add int %tmp.6.i, 1		; <int> [#uses=1]
+	store int %inc.i, int* %G
+	br label %loopentry.i
+
+Out.i:		; preds = %loopentry.i
+	store int 0, int* %G
+	br label %ExitBlock.i
+
+ExitBlock.i:		; preds = %endif.0.i, %Out.i
+	%tmp.7.i = load int* %G		; <int> [#uses=1]
+	ret int %tmp.7.i
+}
+
diff --git a/test/Transforms/LoopSimplify/2004-02-05-DominatorInfoCorruption.ll b/test/Transforms/LoopSimplify/2004-02-05-DominatorInfoCorruption.ll
new file mode 100644
index 0000000..f25460e
--- /dev/null
+++ b/test/Transforms/LoopSimplify/2004-02-05-DominatorInfoCorruption.ll
@@ -0,0 +1,17 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -loopsimplify -verify -licm -disable-output
+implementation   ; Functions:
+
+void %.subst_48() {
+entry:
+	br label %loopentry.0
+
+loopentry.0:            ; preds = %entry, %loopentry.0
+        br bool false, label %loopentry.0, label %loopentry.2
+
+loopentry.2:            ; preds = %loopentry.0, %loopentry.2
+        %tmp.968 = setle int 0, 3               ; <bool> [#uses=1]
+        br bool %tmp.968, label %loopentry.2, label %UnifiedReturnBlock
+
+UnifiedReturnBlock:             ; preds = %entry, %loopentry.2
+        ret void
+}
diff --git a/test/Transforms/LoopSimplify/2004-03-15-IncorrectDomUpdate.ll b/test/Transforms/LoopSimplify/2004-03-15-IncorrectDomUpdate.ll
new file mode 100644
index 0000000..607f1fe
--- /dev/null
+++ b/test/Transforms/LoopSimplify/2004-03-15-IncorrectDomUpdate.ll
@@ -0,0 +1,12 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -loopsimplify -licm -disable-output
+void %main() {
+entry:
+	br bool false, label %Out, label %loop
+
+loop:
+	%LI = setgt int 0, 0
+	br bool %LI, label %loop, label %Out
+
+Out:
+	ret void
+}
diff --git a/test/Transforms/LoopSimplify/2004-04-01-IncorrectDomUpdate.ll b/test/Transforms/LoopSimplify/2004-04-01-IncorrectDomUpdate.ll
new file mode 100644
index 0000000..b984313
--- /dev/null
+++ b/test/Transforms/LoopSimplify/2004-04-01-IncorrectDomUpdate.ll
@@ -0,0 +1,24 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -loopsimplify -licm -disable-output
+
+; This is PR306
+
+void %NormalizeCoeffsVecFFE() {
+entry:
+        br label %loopentry.0
+
+loopentry.0:            ; preds = %entry, %no_exit.0
+        br bool false, label %loopentry.1, label %no_exit.0
+
+no_exit.0:              ; preds = %loopentry.0
+        br bool false, label %loopentry.0, label %loopentry.1
+
+loopentry.1:            ; preds = %loopentry.0, %no_exit.0, %no_exit.1
+        br bool false, label %no_exit.1, label %loopexit.1
+
+no_exit.1:              ; preds = %loopentry.1
+        %tmp.43 = seteq ushort 0, 0             ; <bool> [#uses=1]
+        br bool %tmp.43, label %loopentry.1, label %loopexit.1
+
+loopexit.1:             ; preds = %loopentry.1, %no_exit.1
+        ret void
+}
diff --git a/test/Transforms/LoopSimplify/2004-04-12-LoopSimplify-SwitchBackedges.ll b/test/Transforms/LoopSimplify/2004-04-12-LoopSimplify-SwitchBackedges.ll
new file mode 100644
index 0000000..12250b7
--- /dev/null
+++ b/test/Transforms/LoopSimplify/2004-04-12-LoopSimplify-SwitchBackedges.ll
@@ -0,0 +1,22 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -loopsimplify -disable-output
+
+implementation   
+
+void %test() {
+loopentry.0:
+	br label %loopentry.1
+
+loopentry.1:
+	%pixel.4 = phi int [ 0, %loopentry.0 ], [ %pixel.4, %loopentry.1], [ %tmp.370, %then.6 ], [ %tmp.370, %then.6 ]
+	br bool false, label %then.6, label %loopentry.1
+
+then.6:
+	%tmp.370 = add int 0, 0		; <int> [#uses=2]
+	switch uint 0, label %label.7 [
+		 uint 6408, label %loopentry.1
+		 uint 32841, label %loopentry.1
+	]
+
+label.7:		; preds = %then.6
+	ret void
+}
diff --git a/test/Transforms/LoopSimplify/2004-04-13-LoopSimplifyUpdateDomFrontier.ll b/test/Transforms/LoopSimplify/2004-04-13-LoopSimplifyUpdateDomFrontier.ll
new file mode 100644
index 0000000..7f16400
--- /dev/null
+++ b/test/Transforms/LoopSimplify/2004-04-13-LoopSimplifyUpdateDomFrontier.ll
@@ -0,0 +1,22 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -scalarrepl -loopsimplify -licm -disable-output
+
+implementation   ; Functions:
+
+void %inflate() {
+entry:
+	br label %loopentry.0.outer1111
+
+loopentry.0.outer1111:		; preds = %entry, %loopentry.0.outer1111, %label.11, %then.41
+	%left.0.ph1107 = phi uint [ %tmp.1172, %then.41 ], [ 0, %entry ], [ %tmp.1172, %label.11 ], [ %left.0.ph1107, %loopentry.0.outer1111 ]		; <uint> [#uses=2]
+	%tmp.1172 = sub uint %left.0.ph1107, 0		; <uint> [#uses=2]
+	switch uint 0, label %label.11 [
+		 uint 23, label %loopentry.0.outer1111
+		 uint 13, label %then.41
+	]
+
+label.11:		; preds = %loopentry.0.outer1111
+	br label %loopentry.0.outer1111
+
+then.41:		; preds = %loopentry.0.outer1111
+	br label %loopentry.0.outer1111
+}
diff --git a/test/Transforms/LoopSimplify/basictest.ll b/test/Transforms/LoopSimplify/basictest.ll
new file mode 100644
index 0000000..2b01b47
--- /dev/null
+++ b/test/Transforms/LoopSimplify/basictest.ll
@@ -0,0 +1,17 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -loopsimplify
+
+implementation
+
+; This function should get a preheader inserted before BB3, that is jumped
+; to by BB1 & BB2
+;
+void "test"()
+begin
+	br bool true, label %BB1, label %BB2
+BB1:    br label %BB3
+BB2:    br label %BB3
+
+
+BB3:
+	br label %BB3
+end
diff --git a/test/Transforms/LoopSimplify/dg.exp b/test/Transforms/LoopSimplify/dg.exp
new file mode 100644
index 0000000..879685c
--- /dev/null
+++ b/test/Transforms/LoopSimplify/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/LoopSimplify/hardertest.ll b/test/Transforms/LoopSimplify/hardertest.ll
new file mode 100644
index 0000000..a4465b7
--- /dev/null
+++ b/test/Transforms/LoopSimplify/hardertest.ll
@@ -0,0 +1,17 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -loopsimplify
+
+void %foo(bool %C) {
+	br bool %C, label %T, label %F
+T:
+	br label %Loop
+F: 
+	br label %Loop
+
+Loop:    ; Two backedges, two incoming edges.
+	%Val = phi int [0, %T], [1, %F], [2, %Loop], [3, %L2]
+
+	br bool %C, label %Loop, label %L2
+
+L2:
+	br label %Loop
+}
diff --git a/test/Transforms/LoopSimplify/phi-node-simplify.ll b/test/Transforms/LoopSimplify/phi-node-simplify.ll
new file mode 100644
index 0000000..aa52d66
--- /dev/null
+++ b/test/Transforms/LoopSimplify/phi-node-simplify.ll
@@ -0,0 +1,59 @@
+; Loop Simplify should turn phi nodes like X = phi [X, Y]  into just Y, eliminating them.
+; RUN: llvm-upgrade < %s | llvm-as | opt -loopsimplify | llvm-dis | grep phi | wc -l | grep 6
+
+%A = weak global [3000000 x int] zeroinitializer		; <[3000000 x int]*> [#uses=1]
+%B = weak global [20000 x int] zeroinitializer		; <[20000 x int]*> [#uses=1]
+%C = weak global [100 x int] zeroinitializer		; <[100 x int]*> [#uses=1]
+%Z = weak global int 0		; <int*> [#uses=2]
+
+implementation   ; Functions:
+
+int %main() {
+entry:
+	tail call void %__main( )
+	br label %loopentry.1
+
+loopentry.1:		; preds = %loopexit.1, %entry
+	%indvar20 = phi uint [ 0, %entry ], [ %indvar.next21, %loopexit.1 ]		; <uint> [#uses=1]
+	%a.1 = phi int* [ getelementptr ([3000000 x int]* %A, int 0, int 0), %entry ], [ %inc.0, %loopexit.1 ]		; <int*> [#uses=1]
+	br label %no_exit.2
+
+no_exit.2:		; preds = %loopexit.2, %no_exit.2, %loopentry.1
+	%a.0.4.ph = phi int* [ %a.1, %loopentry.1 ], [ %inc.0, %loopexit.2 ], [ %a.0.4.ph, %no_exit.2 ]		; <int*> [#uses=3]
+	%b.1.4.ph = phi int* [ getelementptr ([20000 x int]* %B, int 0, int 0), %loopentry.1 ], [ %inc.1, %loopexit.2 ], [ %b.1.4.ph, %no_exit.2 ]		; <int*> [#uses=3]
+	%indvar17 = phi uint [ 0, %loopentry.1 ], [ %indvar.next18, %loopexit.2 ], [ %indvar17, %no_exit.2 ]		; <uint> [#uses=2]
+	%indvar = phi uint [ %indvar.next, %no_exit.2 ], [ 0, %loopexit.2 ], [ 0, %loopentry.1 ]		; <uint> [#uses=5]
+	%b.1.4.rec = cast uint %indvar to int		; <int> [#uses=1]
+	%c.2.4 = getelementptr [100 x int]* %C, int 0, uint %indvar		; <int*> [#uses=1]
+	%a.0.4 = getelementptr int* %a.0.4.ph, uint %indvar		; <int*> [#uses=1]
+	%b.1.4 = getelementptr int* %b.1.4.ph, uint %indvar		; <int*> [#uses=1]
+	%inc.0.rec = add int %b.1.4.rec, 1		; <int> [#uses=2]
+	%inc.0 = getelementptr int* %a.0.4.ph, int %inc.0.rec		; <int*> [#uses=2]
+	%tmp.13 = load int* %a.0.4		; <int> [#uses=1]
+	%inc.1 = getelementptr int* %b.1.4.ph, int %inc.0.rec		; <int*> [#uses=1]
+	%tmp.15 = load int* %b.1.4		; <int> [#uses=1]
+	%tmp.18 = load int* %c.2.4		; <int> [#uses=1]
+	%tmp.16 = mul int %tmp.15, %tmp.13		; <int> [#uses=1]
+	%tmp.19 = mul int %tmp.16, %tmp.18		; <int> [#uses=1]
+	%tmp.20 = load int* %Z		; <int> [#uses=1]
+	%tmp.21 = add int %tmp.19, %tmp.20		; <int> [#uses=1]
+	store int %tmp.21, int* %Z
+	%indvar.next = add uint %indvar, 1		; <uint> [#uses=2]
+	%exitcond = seteq uint %indvar.next, 100		; <bool> [#uses=1]
+	br bool %exitcond, label %loopexit.2, label %no_exit.2
+
+loopexit.2:		; preds = %no_exit.2
+	%indvar.next18 = add uint %indvar17, 1		; <uint> [#uses=2]
+	%exitcond19 = seteq uint %indvar.next18, 200		; <bool> [#uses=1]
+	br bool %exitcond19, label %loopexit.1, label %no_exit.2
+
+loopexit.1:		; preds = %loopexit.2
+	%indvar.next21 = add uint %indvar20, 1		; <uint> [#uses=2]
+	%exitcond22 = seteq uint %indvar.next21, 300		; <bool> [#uses=1]
+	br bool %exitcond22, label %return, label %loopentry.1
+
+return:		; preds = %loopexit.1
+	ret int undef
+}
+
+declare void %__main()
diff --git a/test/Transforms/LoopSimplify/single-backedge.ll b/test/Transforms/LoopSimplify/single-backedge.ll
new file mode 100644
index 0000000..53a6ffb
--- /dev/null
+++ b/test/Transforms/LoopSimplify/single-backedge.ll
@@ -0,0 +1,17 @@
+; The loop canonicalization pass should guarantee that there is one backedge 
+; for all loops.  This allows the -indvars pass to recognize the %IV 
+; induction variable in this testcase.
+
+; RUN: llvm-upgrade < %s | llvm-as | opt -indvars | llvm-dis | grep indvar
+
+int %test(bool %C) {
+	br label %Loop
+Loop:
+	%IV = phi uint [1, %0], [%IV2, %BE1], [%IV2, %BE2]
+	%IV2 = add uint %IV, 2
+	br bool %C, label %BE1, label %BE2
+BE1:
+	br label %Loop
+BE2:
+	br label %Loop
+}