summaryrefslogtreecommitdiff
path: root/test/Transforms/LICM
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2010-09-17 15:48:55 +0000
committerDimitry Andric <dim@FreeBSD.org>2010-09-17 15:48:55 +0000
commitd39c594d39df7f283c2fb8a704a3f31c501180d9 (patch)
tree36453626c792cccd91f783a38a169d610a6b9db9 /test/Transforms/LICM
parent6144c1de6a7674dad94290650e4e14f24d42e421 (diff)
Notes
Diffstat (limited to 'test/Transforms/LICM')
-rw-r--r--test/Transforms/LICM/crash.ll61
-rw-r--r--test/Transforms/LICM/hoisting.ll16
-rw-r--r--test/Transforms/LICM/scalar_promote.ll59
-rw-r--r--test/Transforms/LICM/sinking.ll14
4 files changed, 144 insertions, 6 deletions
diff --git a/test/Transforms/LICM/crash.ll b/test/Transforms/LICM/crash.ll
new file mode 100644
index 000000000000..88be5c41ccc5
--- /dev/null
+++ b/test/Transforms/LICM/crash.ll
@@ -0,0 +1,61 @@
+; RUN: opt -licm %s -disable-output
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+
+; PR8068
+@g_12 = external global i8, align 1
+define void @test1() nounwind ssp {
+entry:
+ br label %for.body
+
+for.body: ; preds = %for.cond, %bb.nph
+ store i8 0, i8* @g_12, align 1
+ %tmp6 = load i8* @g_12, align 1
+ br label %for.cond
+
+for.cond: ; preds = %for.body
+ store i8 %tmp6, i8* @g_12, align 1
+ br i1 false, label %for.cond.for.end10_crit_edge, label %for.body
+
+for.cond.for.end10_crit_edge: ; preds = %for.cond
+ br label %for.end10
+
+for.end10: ; preds = %for.cond.for.end10_crit_edge, %entry
+ ret void
+}
+
+; PR8067
+@g_8 = external global i32, align 4
+
+define void @test2() noreturn nounwind ssp {
+entry:
+ br label %for.body
+
+for.body: ; preds = %for.body, %entry
+ %tmp7 = load i32* @g_8, align 4
+ store i32* @g_8, i32** undef, align 16
+ store i32 undef, i32* @g_8, align 4
+ br label %for.body
+}
+
+; PR8102
+define void @test3() {
+entry:
+ %__first = alloca { i32* }
+ br i1 undef, label %for.cond, label %for.end
+
+for.cond: ; preds = %for.cond, %entry
+ %tmp1 = getelementptr { i32*}* %__first, i32 0, i32 0
+ %tmp2 = load i32** %tmp1, align 4
+ %call = tail call i32* @test3helper(i32* %tmp2)
+ %tmp3 = getelementptr { i32*}* %__first, i32 0, i32 0
+ store i32* %call, i32** %tmp3, align 4
+ br i1 false, label %for.cond, label %for.end
+
+for.end: ; preds = %for.cond, %entry
+ ret void
+}
+
+declare i32* @test3helper(i32*)
diff --git a/test/Transforms/LICM/hoisting.ll b/test/Transforms/LICM/hoisting.ll
index e7d36afb91b1..6f28d53af66e 100644
--- a/test/Transforms/LICM/hoisting.ll
+++ b/test/Transforms/LICM/hoisting.ll
@@ -48,3 +48,19 @@ Out: ; preds = %Loop
%C = sub i32 %A, %B ; <i32> [#uses=1]
ret i32 %C
}
+
+
+; This loop invariant instruction should be constant folded, not hoisted.
+define i32 @test3(i1 %c) {
+; CHECK: define i32 @test3
+; CHECK: call void @foo2(i32 6)
+ %A = load i32* @X ; <i32> [#uses=2]
+ br label %Loop
+Loop:
+ %B = add i32 4, 2 ; <i32> [#uses=2]
+ call void @foo2( i32 %B )
+ br i1 %c, label %Loop, label %Out
+Out: ; preds = %Loop
+ %C = sub i32 %A, %B ; <i32> [#uses=1]
+ ret i32 %C
+}
diff --git a/test/Transforms/LICM/scalar_promote.ll b/test/Transforms/LICM/scalar_promote.ll
index ef28c38ca607..c1d2b24b0bba 100644
--- a/test/Transforms/LICM/scalar_promote.ll
+++ b/test/Transforms/LICM/scalar_promote.ll
@@ -1,4 +1,6 @@
; RUN: opt < %s -licm -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"
+
@X = global i32 7 ; <i32*> [#uses=4]
define void @test1(i32 %i) {
@@ -32,23 +34,21 @@ Entry:
br label %Loop
; CHECK: @test2
; CHECK: Entry:
-; CHECK-NEXT: %X1 = getelementptr i32* @X, i64 0
-; CHECK-NEXT: %X2 = getelementptr i32* @X, i64 0
-; CHECK-NEXT: %X1.promoted = load i32* %X1
+; CHECK-NEXT: %.promoted = load i32* getelementptr inbounds (i32* @X, i64 1)
; CHECK-NEXT: br label %Loop
Loop: ; preds = %Loop, %0
- %X1 = getelementptr i32* @X, i64 0 ; <i32*> [#uses=1]
+ %X1 = getelementptr i32* @X, i64 1 ; <i32*> [#uses=1]
%A = load i32* %X1 ; <i32> [#uses=1]
%V = add i32 %A, 1 ; <i32> [#uses=1]
- %X2 = getelementptr i32* @X, i64 0 ; <i32*> [#uses=1]
+ %X2 = getelementptr i32* @X, i64 1 ; <i32*> [#uses=1]
store i32 %V, i32* %X2
br i1 false, label %Loop, label %Exit
Exit: ; preds = %Loop
ret void
; CHECK: Exit:
-; CHECK-NEXT: store i32 %V, i32* %X1
+; CHECK-NEXT: store i32 %V, i32* getelementptr inbounds (i32* @X, i64 1)
; CHECK-NEXT: ret void
}
@@ -71,3 +71,50 @@ Out: ; preds = %Loop
ret void
}
+; PR8041
+define void @test4(i8* %x, i8 %n) {
+; CHECK: @test4
+ %handle1 = alloca i8*
+ %handle2 = alloca i8*
+ store i8* %x, i8** %handle1
+ br label %loop
+
+loop:
+ %tmp = getelementptr i8* %x, i64 8
+ store i8* %tmp, i8** %handle2
+ br label %subloop
+
+subloop:
+ %count = phi i8 [ 0, %loop ], [ %nextcount, %subloop ]
+ %offsetx2 = load i8** %handle2
+ store i8 %n, i8* %offsetx2
+ %newoffsetx2 = getelementptr i8* %offsetx2, i64 -1
+ store i8* %newoffsetx2, i8** %handle2
+ %nextcount = add i8 %count, 1
+ %innerexitcond = icmp sge i8 %nextcount, 8
+ br i1 %innerexitcond, label %innerexit, label %subloop
+
+; Should have promoted 'handle2' accesses.
+; CHECK: subloop:
+; CHECK-NEXT: phi i8* [
+; CHECK-NEXT: %count = phi i8 [
+; CHECK-NEXT: store i8 %n
+; CHECK-NOT: store
+; CHECK: br i1
+
+innerexit:
+ %offsetx1 = load i8** %handle1
+ %val = load i8* %offsetx1
+ %cond = icmp eq i8 %val, %n
+ br i1 %cond, label %exit, label %loop
+
+; Should not have promoted offsetx1 loads.
+; CHECK: innerexit:
+; CHECK: %val = load i8* %offsetx1
+; CHECK: %cond = icmp eq i8 %val, %n
+; CHECK: br i1 %cond, label %exit, label %loop
+
+exit:
+ ret void
+}
+
diff --git a/test/Transforms/LICM/sinking.ll b/test/Transforms/LICM/sinking.ll
index 11112eb74443..68e4b64bf9bf 100644
--- a/test/Transforms/LICM/sinking.ll
+++ b/test/Transforms/LICM/sinking.ll
@@ -233,3 +233,17 @@ Out: ; preds = %Loop
; CHECK-NEXT: ret i32 %tmp.6
}
+; Should delete, not sink, dead instructions.
+define void @test11() {
+ br label %Loop
+Loop:
+ %dead = getelementptr %Ty* @X2, i64 0, i32 0
+ br i1 false, label %Loop, label %Out
+Out:
+ ret void
+; CHECK: @test11
+; CHECK: Out:
+; CHECK-NEXT: ret void
+}
+
+