summaryrefslogtreecommitdiff
path: root/test/Transforms/GlobalOpt
diff options
context:
space:
mode:
authorVictor Hernandez <vhernandez@apple.com>2009-11-05 00:03:03 +0000
committerVictor Hernandez <vhernandez@apple.com>2009-11-05 00:03:03 +0000
commit24f934d0551e33508c4ffd24318ea0e970db9810 (patch)
tree0d40c74486a929769f400842743d2e3c2d23100f /test/Transforms/GlobalOpt
parent61ecbd196c0128abb8c588aebc456ed96cdf1d63 (diff)
downloadllvm-24f934d0551e33508c4ffd24318ea0e970db9810.tar.gz
llvm-24f934d0551e33508c4ffd24318ea0e970db9810.tar.bz2
llvm-24f934d0551e33508c4ffd24318ea0e970db9810.tar.xz
Update CreateMalloc so that its callers specify the size to allocate:
MallocInst-autoupgrade users use non-TargetData-computed allocation sizes. Optimization uses use TargetData to compute the allocation size. Now that malloc calls can have constant sizes, update isArrayMallocHelper() to use TargetData to determine the size of the malloced type and the size of malloced arrays. Extend getMallocType() to support malloc calls that have non-bitcast uses. Update OptimizeGlobalAddressOfMalloc() to optimize malloc calls that have non-bitcast uses. The bitcast use of a malloc call has to be treated specially here because the uses of the bitcast need to be replaced and the bitcast needs to be erased (just like the malloc call) for OptimizeGlobalAddressOfMalloc() to work correctly. Update PerformHeapAllocSRoA() to optimize malloc calls that have non-bitcast uses. The bitcast use of the malloc is not handled specially here because ReplaceUsesOfMallocWithGlobal replaces through the bitcast use. Update OptimizeOnceStoredGlobal() to not care about the malloc calls' bitcast use. Update all globalopt malloc tests to not rely on autoupgraded-MallocInsts, but instead use explicit malloc calls with correct allocation sizes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86077 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Transforms/GlobalOpt')
-rw-r--r--test/Transforms/GlobalOpt/2009-06-01-RecursivePHI.ll7
-rw-r--r--test/Transforms/GlobalOpt/heap-sra-1.ll16
-rw-r--r--test/Transforms/GlobalOpt/heap-sra-2.ll14
-rw-r--r--test/Transforms/GlobalOpt/heap-sra-3.ll14
-rw-r--r--test/Transforms/GlobalOpt/heap-sra-4.ll14
-rw-r--r--test/Transforms/GlobalOpt/heap-sra-phi.ll8
-rw-r--r--test/Transforms/GlobalOpt/malloc-promote-1.ll9
-rw-r--r--test/Transforms/GlobalOpt/malloc-promote-2.ll8
-rw-r--r--test/Transforms/GlobalOpt/malloc-promote-3.ll8
9 files changed, 58 insertions, 40 deletions
diff --git a/test/Transforms/GlobalOpt/2009-06-01-RecursivePHI.ll b/test/Transforms/GlobalOpt/2009-06-01-RecursivePHI.ll
index abd31094bf..d3c3ff59fe 100644
--- a/test/Transforms/GlobalOpt/2009-06-01-RecursivePHI.ll
+++ b/test/Transforms/GlobalOpt/2009-06-01-RecursivePHI.ll
@@ -1,4 +1,5 @@
; RUN: opt < %s -globalopt
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
%struct.s_annealing_sched = type { i32, float, float, float, float }
%struct.s_bb = type { i32, i32, i32, i32 }
@@ -96,7 +97,9 @@ bb.i34: ; preds = %bb
unreachable
bb1.i38: ; preds = %bb
- %0 = malloc %struct.s_net, i32 undef ; <%struct.s_net*> [#uses=1]
+ %mallocsize = mul i64 28, undef ; <i64> [#uses=1]
+ %malloccall = tail call i8* @malloc(i64 %mallocsize) ; <i8*> [#uses=1]
+ %0 = bitcast i8* %malloccall to %struct.s_net* ; <%struct.s_net*> [#uses=1]
br i1 undef, label %bb.i1.i39, label %my_malloc.exit2.i
bb.i1.i39: ; preds = %bb1.i38
@@ -115,3 +118,5 @@ my_malloc.exit8.i: ; preds = %my_malloc.exit2.i
bb7: ; preds = %bb6.preheader
unreachable
}
+
+declare noalias i8* @malloc(i64)
diff --git a/test/Transforms/GlobalOpt/heap-sra-1.ll b/test/Transforms/GlobalOpt/heap-sra-1.ll
index 6df559e456..9d5148f9be 100644
--- a/test/Transforms/GlobalOpt/heap-sra-1.ll
+++ b/test/Transforms/GlobalOpt/heap-sra-1.ll
@@ -1,18 +1,22 @@
-; RUN: opt < %s -globalopt -S | grep {@X.f0}
-; RUN: opt < %s -globalopt -S | grep {@X.f1}
-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-f80:128:128"
-target triple = "i386-apple-darwin7"
+; RUN: opt < %s -globalopt -S | FileCheck %s
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
%struct.foo = type { i32, i32 }
@X = internal global %struct.foo* null
+; CHECK: @X.f0
+; CHECK: @X.f1
-define void @bar(i32 %Size) nounwind noinline {
+define void @bar(i64 %Size) nounwind noinline {
entry:
- %.sub = malloc %struct.foo, i32 %Size
+ %mallocsize = mul i64 %Size, 8 ; <i64> [#uses=1]
+ %malloccall = tail call i8* @malloc(i64 %mallocsize) ; <i8*> [#uses=1]
+ %.sub = bitcast i8* %malloccall to %struct.foo* ; <%struct.foo*> [#uses=1]
store %struct.foo* %.sub, %struct.foo** @X, align 4
ret void
}
+declare noalias i8* @malloc(i64)
+
define i32 @baz() nounwind readonly noinline {
bb1.thread:
%0 = load %struct.foo** @X, align 4
diff --git a/test/Transforms/GlobalOpt/heap-sra-2.ll b/test/Transforms/GlobalOpt/heap-sra-2.ll
index 5a3c3cd1c0..fa8c36281e 100644
--- a/test/Transforms/GlobalOpt/heap-sra-2.ll
+++ b/test/Transforms/GlobalOpt/heap-sra-2.ll
@@ -1,20 +1,22 @@
-; RUN: opt < %s -globalopt -S | grep {@X.f0}
-; RUN: opt < %s -globalopt -S | grep {@X.f1}
+; RUN: opt < %s -globalopt -S | FileCheck %s
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
-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-f80:128:128"
-target triple = "i386-apple-darwin7"
%struct.foo = type { i32, i32 }
@X = internal global %struct.foo* null ; <%struct.foo**> [#uses=2]
+; CHECK: @X.f0
+; CHECK: @X.f1
define void @bar(i32 %Size) nounwind noinline {
entry:
- %0 = malloc [1000000 x %struct.foo]
- ;%.sub = bitcast [1000000 x %struct.foo]* %0 to %struct.foo*
+ %malloccall = tail call i8* @malloc(i64 8000000) ; <i8*> [#uses=1]
+ %0 = bitcast i8* %malloccall to [1000000 x %struct.foo]* ; <[1000000 x %struct.foo]*> [#uses=1]
%.sub = getelementptr [1000000 x %struct.foo]* %0, i32 0, i32 0 ; <%struct.foo*> [#uses=1]
store %struct.foo* %.sub, %struct.foo** @X, align 4
ret void
}
+declare noalias i8* @malloc(i64)
+
define i32 @baz() nounwind readonly noinline {
bb1.thread:
%0 = load %struct.foo** @X, align 4 ; <%struct.foo*> [#uses=1]
diff --git a/test/Transforms/GlobalOpt/heap-sra-3.ll b/test/Transforms/GlobalOpt/heap-sra-3.ll
index 14964853c7..cbbcdfcaf7 100644
--- a/test/Transforms/GlobalOpt/heap-sra-3.ll
+++ b/test/Transforms/GlobalOpt/heap-sra-3.ll
@@ -1,24 +1,22 @@
; RUN: opt < %s -globalopt -S | FileCheck %s
-
-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-f80:128:128"
-target triple = "i386-apple-darwin10"
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
%struct.foo = type { i32, i32 }
@X = internal global %struct.foo* null
; CHECK: @X.f0
; CHECK: @X.f1
-define void @bar(i32 %Size) nounwind noinline {
+define void @bar(i64 %Size) nounwind noinline {
entry:
- %mallocsize = mul i32 ptrtoint (%struct.foo* getelementptr (%struct.foo* null, i32 1) to i32), %Size, ; <i32> [#uses=1]
-; CHECK: mul i32 %Size
- %malloccall = tail call i8* @malloc(i32 %mallocsize) ; <i8*> [#uses=1]
+ %mallocsize = mul i64 8, %Size, ; <i64> [#uses=1]
+; CHECK: mul i64 %Size, 4
+ %malloccall = tail call i8* @malloc(i64 %mallocsize) ; <i8*> [#uses=1]
%.sub = bitcast i8* %malloccall to %struct.foo* ; <%struct.foo*> [#uses=1]
store %struct.foo* %.sub, %struct.foo** @X, align 4
ret void
}
-declare noalias i8* @malloc(i32)
+declare noalias i8* @malloc(i64)
define i32 @baz() nounwind readonly noinline {
bb1.thread:
diff --git a/test/Transforms/GlobalOpt/heap-sra-4.ll b/test/Transforms/GlobalOpt/heap-sra-4.ll
index ae97ef1aad..d5a58288e1 100644
--- a/test/Transforms/GlobalOpt/heap-sra-4.ll
+++ b/test/Transforms/GlobalOpt/heap-sra-4.ll
@@ -1,24 +1,22 @@
; RUN: opt < %s -globalopt -S | FileCheck %s
-
-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-f80:128:128"
-target triple = "i386-apple-darwin7"
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
%struct.foo = type { i32, i32 }
@X = internal global %struct.foo* null
; CHECK: @X.f0
; CHECK: @X.f1
-define void @bar(i32 %Size) nounwind noinline {
+define void @bar(i64 %Size) nounwind noinline {
entry:
- %mallocsize = shl i32 ptrtoint (%struct.foo* getelementptr (%struct.foo* null, i32 1) to i32), 9, ; <i32> [#uses=1]
- %malloccall = tail call i8* @malloc(i32 %mallocsize) ; <i8*> [#uses=1]
-; CHECK: @malloc(i32 mul (i32 512
+ %mallocsize = shl i64 %Size, 3 ; <i64> [#uses=1]
+ %malloccall = tail call i8* @malloc(i64 %mallocsize) ; <i8*> [#uses=1]
+; CHECK: mul i64 %Size, 4
%.sub = bitcast i8* %malloccall to %struct.foo* ; <%struct.foo*> [#uses=1]
store %struct.foo* %.sub, %struct.foo** @X, align 4
ret void
}
-declare noalias i8* @malloc(i32)
+declare noalias i8* @malloc(i64)
define i32 @baz() nounwind readonly noinline {
bb1.thread:
diff --git a/test/Transforms/GlobalOpt/heap-sra-phi.ll b/test/Transforms/GlobalOpt/heap-sra-phi.ll
index 2eba944cfd..6188e5af98 100644
--- a/test/Transforms/GlobalOpt/heap-sra-phi.ll
+++ b/test/Transforms/GlobalOpt/heap-sra-phi.ll
@@ -1,19 +1,21 @@
; RUN: opt < %s -globalopt -S | grep {tmp.f1 = phi i32. }
; RUN: opt < %s -globalopt -S | grep {tmp.f0 = phi i32. }
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
-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-f80:128:128"
-target triple = "i386-apple-darwin7"
%struct.foo = type { i32, i32 }
@X = internal global %struct.foo* null ; <%struct.foo**> [#uses=2]
define void @bar(i32 %Size) nounwind noinline {
entry:
- %tmp = malloc [1000000 x %struct.foo] ; <[1000000 x %struct.foo]*> [#uses=1]
+ %malloccall = tail call i8* @malloc(i64 8000000) ; <i8*> [#uses=1]
+ %tmp = bitcast i8* %malloccall to [1000000 x %struct.foo]* ; <[1000000 x %struct.foo]*> [#uses=1]
%.sub = getelementptr [1000000 x %struct.foo]* %tmp, i32 0, i32 0 ; <%struct.foo*> [#uses=1]
store %struct.foo* %.sub, %struct.foo** @X, align 4
ret void
}
+declare noalias i8* @malloc(i64)
+
define i32 @baz() nounwind readonly noinline {
bb1.thread:
%tmpLD1 = load %struct.foo** @X, align 4 ; <%struct.foo*> [#uses=1]
diff --git a/test/Transforms/GlobalOpt/malloc-promote-1.ll b/test/Transforms/GlobalOpt/malloc-promote-1.ll
index fd510e3b57..51ccbbd43c 100644
--- a/test/Transforms/GlobalOpt/malloc-promote-1.ll
+++ b/test/Transforms/GlobalOpt/malloc-promote-1.ll
@@ -1,19 +1,24 @@
-; RUN: opt < %s -globalopt -S | not grep global
+; RUN: opt < %s -globalopt -S | FileCheck %s
target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
@G = internal global i32* null ; <i32**> [#uses=3]
+; CHECK-NOT: global
define void @init() {
- %P = malloc i32 ; <i32*> [#uses=1]
+ %malloccall = tail call i8* @malloc(i64 4) ; <i8*> [#uses=1]
+ %P = bitcast i8* %malloccall to i32* ; <i32*> [#uses=1]
store i32* %P, i32** @G
%GV = load i32** @G ; <i32*> [#uses=1]
store i32 0, i32* %GV
ret void
}
+declare noalias i8* @malloc(i64)
+
define i32 @get() {
%GV = load i32** @G ; <i32*> [#uses=1]
%V = load i32* %GV ; <i32> [#uses=1]
ret i32 %V
+; CHECK: ret i32 0
}
diff --git a/test/Transforms/GlobalOpt/malloc-promote-2.ll b/test/Transforms/GlobalOpt/malloc-promote-2.ll
index d3d225260a..f989b798b4 100644
--- a/test/Transforms/GlobalOpt/malloc-promote-2.ll
+++ b/test/Transforms/GlobalOpt/malloc-promote-2.ll
@@ -1,11 +1,11 @@
; RUN: opt < %s -globalopt -globaldce -S | not grep malloc
-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-f80:128:128"
-target triple = "i686-apple-darwin8"
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
@G = internal global i32* null ; <i32**> [#uses=3]
define void @init() {
- %P = malloc i32, i32 100 ; <i32*> [#uses=1]
+ %malloccall = tail call i8* @malloc(i64 mul (i64 100, i64 4)) ; <i8*> [#uses=1]
+ %P = bitcast i8* %malloccall to i32* ; <i32*> [#uses=1]
store i32* %P, i32** @G
%GV = load i32** @G ; <i32*> [#uses=1]
%GVe = getelementptr i32* %GV, i32 40 ; <i32*> [#uses=1]
@@ -13,6 +13,8 @@ define void @init() {
ret void
}
+declare noalias i8* @malloc(i64)
+
define i32 @get() {
%GV = load i32** @G ; <i32*> [#uses=1]
%GVe = getelementptr i32* %GV, i32 40 ; <i32*> [#uses=1]
diff --git a/test/Transforms/GlobalOpt/malloc-promote-3.ll b/test/Transforms/GlobalOpt/malloc-promote-3.ll
index a920b61150..57f937d8c9 100644
--- a/test/Transforms/GlobalOpt/malloc-promote-3.ll
+++ b/test/Transforms/GlobalOpt/malloc-promote-3.ll
@@ -1,11 +1,11 @@
; RUN: opt < %s -globalopt -globaldce -S | not grep malloc
-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-f80:128:128"
-target triple = "i686-apple-darwin8"
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
@G = internal global i32* null ; <i32**> [#uses=4]
define void @init() {
- %P = malloc i32, i32 100 ; <i32*> [#uses=1]
+ %malloccall = tail call i8* @malloc(i64 mul (i64 100, i64 4)) ; <i8*> [#uses=1]
+ %P = bitcast i8* %malloccall to i32* ; <i32*> [#uses=1]
store i32* %P, i32** @G
%GV = load i32** @G ; <i32*> [#uses=1]
%GVe = getelementptr i32* %GV, i32 40 ; <i32*> [#uses=1]
@@ -13,6 +13,8 @@ define void @init() {
ret void
}
+declare noalias i8* @malloc(i64)
+
define i32 @get() {
%GV = load i32** @G ; <i32*> [#uses=1]
%GVe = getelementptr i32* %GV, i32 40 ; <i32*> [#uses=1]