summaryrefslogtreecommitdiff
path: root/test/Transforms/LICM
diff options
context:
space:
mode:
authorNadav Rotem <nrotem@apple.com>2012-09-04 10:25:04 +0000
committerNadav Rotem <nrotem@apple.com>2012-09-04 10:25:04 +0000
commit7765492a7a7e6eab36bc43558ea7c1f91e57cfec (patch)
tree9c5cb82bd89c30a288cc00c830e1e1b74969f93d /test/Transforms/LICM
parent68d92bdcc99e647546f40cfce5cfbeb904be2985 (diff)
downloadllvm-7765492a7a7e6eab36bc43558ea7c1f91e57cfec.tar.gz
llvm-7765492a7a7e6eab36bc43558ea7c1f91e57cfec.tar.bz2
llvm-7765492a7a7e6eab36bc43558ea7c1f91e57cfec.tar.xz
LICM may hoist an instruction with undefined behavior above a trap.
Scan the body of the loop and find instructions that may trap. Use this information when deciding if it is safe to hoist or sink instructions. Notice that we can optimize the search of instructions that may throw in the case of nested loops. rdar://11518836 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@163132 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Transforms/LICM')
-rw-r--r--test/Transforms/LICM/hoisting.ll28
1 files changed, 27 insertions, 1 deletions
diff --git a/test/Transforms/LICM/hoisting.ll b/test/Transforms/LICM/hoisting.ll
index 6f28d53af6..98f93345e3 100644
--- a/test/Transforms/LICM/hoisting.ll
+++ b/test/Transforms/LICM/hoisting.ll
@@ -29,7 +29,7 @@ Out: ; preds = %LoopTail
}
-declare void @foo2(i32)
+declare void @foo2(i32) nounwind
;; It is ok and desirable to hoist this potentially trapping instruction.
@@ -64,3 +64,29 @@ Out: ; preds = %Loop
%C = sub i32 %A, %B ; <i32> [#uses=1]
ret i32 %C
}
+
+; CHECK: @test4
+; CHECK: call
+; CHECK: sdiv
+; CHECK: ret
+define i32 @test4(i32 %x, i32 %y) nounwind uwtable ssp {
+entry:
+ br label %for.body
+
+for.body: ; preds = %entry, %for.body
+ %i.02 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+ %n.01 = phi i32 [ 0, %entry ], [ %add, %for.body ]
+ call void @foo_may_call_exit(i32 0)
+ %div = sdiv i32 %x, %y
+ %add = add nsw i32 %n.01, %div
+ %inc = add nsw i32 %i.02, 1
+ %cmp = icmp slt i32 %inc, 10000
+ br i1 %cmp, label %for.body, label %for.end
+
+for.end: ; preds = %for.body
+ %n.0.lcssa = phi i32 [ %add, %for.body ]
+ ret i32 %n.0.lcssa
+}
+
+declare void @foo_may_call_exit(i32)
+