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/LoopRotate/LRAnalysis.ll b/test/Transforms/LoopRotate/LRAnalysis.ll
new file mode 100644
index 0000000..3dc6eda
--- /dev/null
+++ b/test/Transforms/LoopRotate/LRAnalysis.ll
@@ -0,0 +1,21 @@
+; RUN: llvm-as < %s  | opt -loop-rotate -loop-unswitch -disable-output
+
+define i32 @stringSearch_Clib(i32 %count) {
+entry:
+	br i1 false, label %bb36, label %bb44
+
+cond_true20:		; preds = %bb36
+	%tmp33 = add i32 0, 0		; <i32> [#uses=1]
+	br label %bb36
+
+bb36:		; preds = %cond_true20, %entry
+	%c.2 = phi i32 [ %tmp33, %cond_true20 ], [ 0, %entry ]		; <i32> [#uses=1]
+	br i1 false, label %cond_true20, label %bb41
+
+bb41:		; preds = %bb36
+	%c.2.lcssa = phi i32 [ %c.2, %bb36 ]		; <i32> [#uses=0]
+	ret i32 0
+
+bb44:		; preds = %entry
+	ret i32 0
+}
diff --git a/test/Transforms/LoopRotate/LRCrash-1.ll b/test/Transforms/LoopRotate/LRCrash-1.ll
new file mode 100644
index 0000000..0149482
--- /dev/null
+++ b/test/Transforms/LoopRotate/LRCrash-1.ll
@@ -0,0 +1,27 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -loop-rotate -disable-output
+
+
+	%struct.relation = type { [4 x i16], i32, [4 x i16], i32, i32 }
+
+
+
+
+
+
+void @findAllPairs() {
+entry:
+	br i1 false, label %bb139, label %bb10.i44
+
+bb10.i44:		; preds = %entry
+	ret void
+
+bb127:		; preds = %bb139
+	br label %bb139
+
+bb139:		; preds = %bb127, %entry
+	br i1 false, label %bb127, label %bb142
+
+bb142:		; preds = %bb139
+	%r91.0.lcssa = phi %struct.relation* [ null, %bb139 ]		; <%struct.relation*> [#uses=0]
+	ret void
+}
diff --git a/test/Transforms/LoopRotate/LRCrash-2.ll b/test/Transforms/LoopRotate/LRCrash-2.ll
new file mode 100644
index 0000000..bceeb91
--- /dev/null
+++ b/test/Transforms/LoopRotate/LRCrash-2.ll
@@ -0,0 +1,30 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -loop-rotate -disable-output
+
+void @findAllPairs() {
+entry:
+	br i1 false, label %bb139, label %cond_true
+
+cond_true:		; preds = %entry
+	ret void
+
+bb90:		; preds = %bb139
+	br i1 false, label %bb136, label %cond_next121
+
+cond_next121:		; preds = %bb90
+	br i1 false, label %bb136, label %bb127
+
+bb127:		; preds = %cond_next121
+	br label %bb136
+
+bb136:		; preds = %bb127, %cond_next121, %bb90
+	%changes.1 = phi i32 [ %changes.2, %bb90 ], [ %changes.2, %cond_next121 ], [ 1, %bb127 ]		; <i32> [#uses=1]
+	br label %bb139
+
+bb139:		; preds = %bb136, %entry
+	%changes.2 = phi i32 [ %changes.1, %bb136 ], [ 0, %entry ]		; <i32> [#uses=3]
+	br i1 false, label %bb90, label %bb142
+
+bb142:		; preds = %bb139
+	%changes.2.lcssa = phi i32 [ %changes.2, %bb139 ]		; <i32> [#uses=0]
+	ret void
+}
diff --git a/test/Transforms/LoopRotate/LRCrash-3.ll b/test/Transforms/LoopRotate/LRCrash-3.ll
new file mode 100644
index 0000000..e927035
--- /dev/null
+++ b/test/Transforms/LoopRotate/LRCrash-3.ll
@@ -0,0 +1,41 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -loop-rotate -disable-output
+
+
+
+
+void @_ZN9Classfile4readEv() {
+entry:
+	br i1 false, label %cond_false485, label %bb405
+
+bb405:		; preds = %entry
+	ret void
+
+cond_false485:		; preds = %entry
+	br label %bb830
+
+bb511:		; preds = %bb830
+	br i1 false, label %bb816, label %bb830
+
+cond_next667:		; preds = %bb816
+	br i1 false, label %cond_next695, label %bb680
+
+bb676:		; preds = %bb680
+	br label %bb680
+
+bb680:		; preds = %bb676, %cond_next667
+	%iftmp.68.0 = zext i1 false to i8		; <i8> [#uses=1]
+	br i1 false, label %bb676, label %cond_next695
+
+cond_next695:		; preds = %bb680, %cond_next667
+	%iftmp.68.2 = phi i8 [ %iftmp.68.0, %bb680 ], [ undef, %cond_next667 ]		; <i8> [#uses=0]
+	ret void
+
+bb816:		; preds = %bb816, %bb511
+	br i1 false, label %cond_next667, label %bb816
+
+bb830:		; preds = %bb511, %cond_false485
+	br i1 false, label %bb511, label %bb835
+
+bb835:		; preds = %bb830
+	ret void
+}
diff --git a/test/Transforms/LoopRotate/LRCrash-4.ll b/test/Transforms/LoopRotate/LRCrash-4.ll
new file mode 100644
index 0000000..721132d
--- /dev/null
+++ b/test/Transforms/LoopRotate/LRCrash-4.ll
@@ -0,0 +1,20 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -loop-rotate -disable-output
+
+
+void @InterpretSEIMessage(i8* %msg) {
+entry:
+	br label %bb15
+
+bb6:		; preds = %bb15
+	%tmp11 = getelementptr i8* %msg, i32 %offset.1		; <i8*> [#uses=0]
+	br label %bb15
+
+bb15:		; preds = %bb6, %entry
+	%offset.1 = add i32 0, 1		; <i32> [#uses=2]
+	br i1 false, label %bb6, label %bb17
+
+bb17:		; preds = %bb15
+	%offset.1.lcssa = phi i32 [ %offset.1, %bb15 ]		; <i32> [#uses=0]
+	%payload_type.1.lcssa = phi i32 [ 0, %bb15 ]		; <i32> [#uses=0]
+	ret void
+}
diff --git a/test/Transforms/LoopRotate/PhiRename-1.ll b/test/Transforms/LoopRotate/PhiRename-1.ll
new file mode 100644
index 0000000..573e396
--- /dev/null
+++ b/test/Transforms/LoopRotate/PhiRename-1.ll
@@ -0,0 +1,95 @@
+; RUN: llvm-as < %s | opt -loop-rotate | llvm-dis | not grep {\\\[ .tmp224} 
+; END.
+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"
+
+	%struct.FILE = type { i8*, i32, i32, i16, i16, %struct.__sbuf, i32, i8*, i32 (i8*)*, i32 (i8*, i8*, i32)*, i64 (i8*, i64, i32)*, i32 (i8*, i8*, i32)*, %struct.__sbuf, %struct.__sFILEX*, i32, [3 x i8], [1 x i8], %struct.__sbuf, i32, i64 }
+	%struct.Index_Map = type { i32, %struct.item_set** }
+	%struct.Item = type { [4 x i16], %struct.rule* }
+	%struct.__sFILEX = type opaque
+	%struct.__sbuf = type { i8*, i32 }
+	%struct.dimension = type { i16*, %struct.Index_Map, %struct.mapping*, i32, %struct.plankMap* }
+	%struct.item_set = type { i32, i32, %struct.operator*, [2 x %struct.item_set*], %struct.item_set*, i16*, %struct.Item*, %struct.Item* }
+	%struct.list = type { i8*, %struct.list* }
+	%struct.mapping = type { %struct.list**, i32, i32, i32, %struct.item_set** }
+	%struct.nonterminal = type { i8*, i32, i32, i32, %struct.plankMap*, %struct.rule* }
+	%struct.operator = type { i8*, i8, i32, i32, i32, i32, %struct.table* }
+	%struct.pattern = type { %struct.nonterminal*, %struct.operator*, [2 x %struct.nonterminal*] }
+	%struct.plank = type { i8*, %struct.list*, i32 }
+	%struct.plankMap = type { %struct.list*, i32, %struct.stateMap* }
+	%struct.rule = type { [4 x i16], i32, i32, i32, %struct.nonterminal*, %struct.pattern*, i8 }
+	%struct.stateMap = type { i8*, %struct.plank*, i32, i16* }
+	%struct.table = type { %struct.operator*, %struct.list*, i16*, [2 x %struct.dimension*], %struct.item_set** }
+@outfile = external global %struct.FILE*		; <%struct.FILE**> [#uses=1]
+@str1 = external constant [11 x i8]		; <[11 x i8]*> [#uses=1]
+@operators = weak global %struct.list* null		; <%struct.list**> [#uses=1]
+
+
+
+define i32 @opsOfArity(i32 %arity) {
+entry:
+	%arity_addr = alloca i32		; <i32*> [#uses=2]
+	%retval = alloca i32, align 4		; <i32*> [#uses=2]
+	%tmp = alloca i32, align 4		; <i32*> [#uses=2]
+	%c = alloca i32, align 4		; <i32*> [#uses=4]
+	%l = alloca %struct.list*, align 4		; <%struct.list**> [#uses=5]
+	%op = alloca %struct.operator*, align 4		; <%struct.operator**> [#uses=3]
+	"alloca point" = bitcast i32 0 to i32		; <i32> [#uses=0]
+	store i32 %arity, i32* %arity_addr
+	store i32 0, i32* %c
+	%tmp1 = load %struct.list** @operators		; <%struct.list*> [#uses=1]
+	store %struct.list* %tmp1, %struct.list** %l
+	br label %bb21
+
+bb:		; preds = %bb21
+	%tmp3 = getelementptr %struct.list* %tmp22, i32 0, i32 0		; <i8**> [#uses=1]
+	%tmp4 = load i8** %tmp3		; <i8*> [#uses=1]
+	%tmp45 = bitcast i8* %tmp4 to %struct.operator*		; <%struct.operator*> [#uses=1]
+	store %struct.operator* %tmp45, %struct.operator** %op
+	%tmp6 = load %struct.operator** %op		; <%struct.operator*> [#uses=1]
+	%tmp7 = getelementptr %struct.operator* %tmp6, i32 0, i32 5		; <i32*> [#uses=1]
+	%tmp8 = load i32* %tmp7		; <i32> [#uses=1]
+	%tmp9 = load i32* %arity_addr		; <i32> [#uses=1]
+	icmp eq i32 %tmp8, %tmp9		; <i1>:0 [#uses=1]
+	zext i1 %0 to i8		; <i8>:1 [#uses=1]
+	icmp ne i8 %1, 0		; <i1>:2 [#uses=1]
+	br i1 %2, label %cond_true, label %cond_next
+
+cond_true:		; preds = %bb
+	%tmp10 = load %struct.operator** %op		; <%struct.operator*> [#uses=1]
+	%tmp11 = getelementptr %struct.operator* %tmp10, i32 0, i32 2		; <i32*> [#uses=1]
+	%tmp12 = load i32* %tmp11		; <i32> [#uses=1]
+	%tmp13 = load %struct.FILE** @outfile		; <%struct.FILE*> [#uses=1]
+	%tmp14 = getelementptr [11 x i8]* @str1, i32 0, i32 0		; <i8*> [#uses=1]
+	%tmp15 = call i32 (%struct.FILE*, i8*, ...)* @fprintf( %struct.FILE* %tmp13, i8* %tmp14, i32 %tmp12 )		; <i32> [#uses=0]
+	%tmp16 = load i32* %c		; <i32> [#uses=1]
+	%tmp17 = add i32 %tmp16, 1		; <i32> [#uses=1]
+	store i32 %tmp17, i32* %c
+	br label %cond_next
+
+cond_next:		; preds = %cond_true, %bb
+	%tmp19 = getelementptr %struct.list* %tmp22, i32 0, i32 1		; <%struct.list**> [#uses=1]
+	%tmp20 = load %struct.list** %tmp19		; <%struct.list*> [#uses=1]
+	store %struct.list* %tmp20, %struct.list** %l
+	br label %bb21
+
+bb21:		; preds = %cond_next, %entry
+        %l.in = phi %struct.list** [ @operators, %entry ], [ %tmp19, %cond_next ]  ;
+	%tmp22 = load %struct.list** %l.in		; <%struct.list*> [#uses=1]
+	icmp ne %struct.list* %tmp22, null		; <i1>:3 [#uses=1]
+	zext i1 %3 to i8		; <i8>:4 [#uses=1]
+	icmp ne i8 %4, 0		; <i1>:5 [#uses=1]
+	br i1 %5, label %bb, label %bb23
+
+bb23:		; preds = %bb21
+	%tmp24 = load i32* %c		; <i32> [#uses=1]
+	store i32 %tmp24, i32* %tmp
+	%tmp25 = load i32* %tmp		; <i32> [#uses=1]
+	store i32 %tmp25, i32* %retval
+	br label %return
+
+return:		; preds = %bb23
+	%retval26 = load i32* %retval		; <i32> [#uses=1]
+	ret i32 %retval26
+}
+
+declare i32 @fprintf(%struct.FILE*, i8*, ...)
diff --git a/test/Transforms/LoopRotate/PhiSelfRefernce-1.ll b/test/Transforms/LoopRotate/PhiSelfRefernce-1.ll
new file mode 100644
index 0000000..a55704b
--- /dev/null
+++ b/test/Transforms/LoopRotate/PhiSelfRefernce-1.ll
@@ -0,0 +1,39 @@
+; RUN: llvm-as < %s | opt -loop-rotate -disable-output
+; ModuleID = 'PhiSelfRefernce-1.bc'
+
+define void @snrm2(i32 %incx) {
+entry:
+	br i1 false, label %START, label %return
+
+START:		; preds = %entry
+	br i1 false, label %bb85, label %cond_false93
+
+bb52:		; preds = %bb85
+	br i1 false, label %bb307, label %cond_next71
+
+cond_next71:		; preds = %bb52
+	ret void
+
+bb85:		; preds = %START
+	br i1 false, label %bb52, label %bb88
+
+bb88:		; preds = %bb85
+	ret void
+
+cond_false93:		; preds = %START
+	ret void
+
+bb243:		; preds = %bb307
+	br label %bb307
+
+bb307:		; preds = %bb243, %bb52
+	%sx_addr.2.pn = phi float* [ %sx_addr.5, %bb243 ], [ null, %bb52 ]		; <float*> [#uses=1]
+	%sx_addr.5 = getelementptr float* %sx_addr.2.pn, i32 %incx		; <float*> [#uses=1]
+	br i1 false, label %bb243, label %bb310
+
+bb310:		; preds = %bb307
+	ret void
+
+return:		; preds = %entry
+	ret void
+}
diff --git a/test/Transforms/LoopRotate/dg.exp b/test/Transforms/LoopRotate/dg.exp
new file mode 100644
index 0000000..879685c
--- /dev/null
+++ b/test/Transforms/LoopRotate/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/LoopRotate/pr1154.ll b/test/Transforms/LoopRotate/pr1154.ll
new file mode 100644
index 0000000..09c9405
--- /dev/null
+++ b/test/Transforms/LoopRotate/pr1154.ll
@@ -0,0 +1,128 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -std-compile-opts | llvm-dis | \
+; RUN:   %prcontext strstr 2 | grep -v declare | grep bb36.outer:
+; END.
+
+@str = internal constant [68 x i8] c"Dot. date. datum. 123. Some more doubtful demonstration dummy data.\00"		; <[68 x i8]*> [#uses=1]
+@str1 = internal constant [5 x i8] c"ummy\00"		; <[5 x i8]*> [#uses=1]
+@str2 = internal constant [6 x i8] c" data\00"		; <[6 x i8]*> [#uses=1]
+@str3 = internal constant [3 x i8] c"by\00"		; <[3 x i8]*> [#uses=1]
+
+i32 @stringSearch_Clib(i32 %count) {
+entry:
+	%count_addr = alloca i32		; <i32*> [#uses=2]
+	%retval = alloca i32, align 4		; <i32*> [#uses=2]
+	%tmp = alloca i32, align 4		; <i32*> [#uses=2]
+	%i = alloca i32, align 4		; <i32*> [#uses=5]
+	%c = alloca i32, align 4		; <i32*> [#uses=9]
+	%j = alloca i32, align 4		; <i32*> [#uses=4]
+	%p = alloca i8*, align 4		; <i8**> [#uses=6]
+	%b = alloca [68 x i8], align 16		; <[68 x i8]*> [#uses=6]
+	"alloca point" = bitcast i32 0 to i32		; <i32> [#uses=0]
+	store i32 %count, i32* %count_addr
+	store i32 0, i32* %c
+	%b1 = bitcast [68 x i8]* %b to i8*		; <i8*> [#uses=1]
+	%tmp2 = getelementptr [68 x i8]* @str, i32 0, i32 0		; <i8*> [#uses=1]
+	call void @llvm.memcpy.i32( i8* %b1, i8* %tmp2, i32 68, i32 1 )
+	store i32 0, i32* %j
+	br label %bb41
+
+bb:		; preds = %bb41
+	store i32 0, i32* %i
+	%tmp3 = load i32* %i		; <i32> [#uses=1]
+	store i32 %tmp3, i32* %c
+	br label %bb36
+
+bb4:		; preds = %bb36
+	%b5 = bitcast [68 x i8]* %b to i8*		; <i8*> [#uses=1]
+	%tmp6 = getelementptr [5 x i8]* @str1, i32 0, i32 0		; <i8*> [#uses=1]
+	%tmp7 = call i8* @strstr( i8* %b5, i8* %tmp6 )		; <i8*> [#uses=1]
+	store i8* %tmp7, i8** %p
+	%tmp8 = load i8** %p		; <i8*> [#uses=1]
+	%ttmp8 = icmp ne i8* %tmp8, null		; <i1>:0 [#uses=1]
+	%ttmp10 = zext i1 %ttmp8 to i8		; <i8>:1 [#uses=1]
+	%ttmp7 = icmp ne i8 %ttmp10, 0		; <i1>:2 [#uses=1]
+	br i1 %ttmp7, label %cond_true, label %cond_next
+
+cond_true:		; preds = %bb4
+	%tmp9 = load i8** %p		; <i8*> [#uses=1]
+	%tmp910 = ptrtoint i8* %tmp9 to i32		; <i32> [#uses=1]
+	%b11 = bitcast [68 x i8]* %b to i8*		; <i8*> [#uses=1]
+	%b1112 = ptrtoint i8* %b11 to i32		; <i32> [#uses=1]
+	%tmp13 = sub i32 %tmp910, %b1112		; <i32> [#uses=1]
+	%tmp14 = load i32* %c		; <i32> [#uses=1]
+	%tmp15 = add i32 %tmp13, %tmp14		; <i32> [#uses=1]
+	store i32 %tmp15, i32* %c
+	br label %cond_next
+
+cond_next:		; preds = %cond_true, %bb4
+	%b16 = bitcast [68 x i8]* %b to i8*		; <i8*> [#uses=1]
+	%tmp17 = getelementptr [6 x i8]* @str2, i32 0, i32 0		; <i8*> [#uses=1]
+	%tmp18 = call i8* @strstr( i8* %b16, i8* %tmp17 )		; <i8*> [#uses=1]
+	store i8* %tmp18, i8** %p
+	%tmp19 = load i8** %p		; <i8*> [#uses=1]
+	%ttmp6 = icmp ne i8* %tmp19, null		; <i1>:3 [#uses=1]
+	%ttmp9 = zext i1 %ttmp6 to i8		; <i8>:4 [#uses=1]
+	%ttmp4 = icmp ne i8 %ttmp9, 0		; <i1>:5 [#uses=1]
+	br i1 %ttmp4, label %cond_true20, label %cond_next28
+
+cond_true20:		; preds = %cond_next
+	%tmp21 = load i8** %p		; <i8*> [#uses=1]
+	%tmp2122 = ptrtoint i8* %tmp21 to i32		; <i32> [#uses=1]
+	%b23 = bitcast [68 x i8]* %b to i8*		; <i8*> [#uses=1]
+	%b2324 = ptrtoint i8* %b23 to i32		; <i32> [#uses=1]
+	%tmp25 = sub i32 %tmp2122, %b2324		; <i32> [#uses=1]
+	%tmp26 = load i32* %c		; <i32> [#uses=1]
+	%tmp27 = add i32 %tmp25, %tmp26		; <i32> [#uses=1]
+	store i32 %tmp27, i32* %c
+	br label %cond_next28
+
+cond_next28:		; preds = %cond_true20, %cond_next
+	%b29 = bitcast [68 x i8]* %b to i8*		; <i8*> [#uses=1]
+	%tmp30 = getelementptr [3 x i8]* @str3, i32 0, i32 0		; <i8*> [#uses=1]
+	%tmp31 = call i32 @strcspn( i8* %b29, i8* %tmp30 )		; <i32> [#uses=1]
+	%tmp32 = load i32* %c		; <i32> [#uses=1]
+	%tmp33 = add i32 %tmp31, %tmp32		; <i32> [#uses=1]
+	store i32 %tmp33, i32* %c
+	%tmp34 = load i32* %i		; <i32> [#uses=1]
+	%tmp35 = add i32 %tmp34, 1		; <i32> [#uses=1]
+	store i32 %tmp35, i32* %i
+	br label %bb36
+
+bb36:		; preds = %cond_next28, %bb
+	%tmp37 = load i32* %i		; <i32> [#uses=1]
+	%ttmp3= icmp sle i32 %tmp37, 249		; <i1>:6 [#uses=1]
+	%ttmp12 = zext i1 %ttmp3 to i8		; <i8>:7 [#uses=1]
+	%ttmp1 = icmp ne i8 %ttmp12, 0		; <i1>:8 [#uses=1]
+	br i1 %ttmp1, label %bb4, label %bb38
+
+bb38:		; preds = %bb36
+	%tmp39 = load i32* %j		; <i32> [#uses=1]
+	%tmp40 = add i32 %tmp39, 1		; <i32> [#uses=1]
+	store i32 %tmp40, i32* %j
+	br label %bb41
+
+bb41:		; preds = %bb38, %entry
+	%tmp42 = load i32* %j		; <i32> [#uses=1]
+	%tmp43 = load i32* %count_addr		; <i32> [#uses=1]
+	%ttmp2 = icmp slt i32 %tmp42, %tmp43		; <i1>:9 [#uses=1]
+	%ttmp11 = zext i1 %ttmp2 to i8		; <i8>:10 [#uses=1]
+	%ttmp5 = icmp ne i8 %ttmp11, 0		; <i1>:11 [#uses=1]
+	br i1 %ttmp5, label %bb, label %bb44
+
+bb44:		; preds = %bb41
+	%tmp45 = load i32* %c		; <i32> [#uses=1]
+	store i32 %tmp45, i32* %tmp
+	%tmp46 = load i32* %tmp		; <i32> [#uses=1]
+	store i32 %tmp46, i32* %retval
+	br label %return
+
+return:		; preds = %bb44
+	%retval47 = load i32* %retval		; <i32> [#uses=1]
+	ret i32 %retval47
+}
+
+declare void @llvm.memcpy.i32(i8*, i8*, i32, i32)
+
+declare i8* @strstr(i8*, i8*)
+
+declare i32 @strcspn(i8*, i8*)