1) Check that trapping instructionns that are not guaranteed to execute are not hoisted.
2) Check that trapping instructions that are guaranteed to execute are hoisted.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7613
91177308-0d34-0410-b5e6-
96231b3b80d8
--- /dev/null
+; This testcase tests for a problem where LICM hoists
+; potentially trapping instructions when they are not guaranteed to execute.
+;
+; RUN: as < %s | opt -licm | dis | grep -C 2 "IfUnEqual" | grep div
+
+%X = global int 0
+declare void %foo()
+
+int %test(bool %c) {
+ %A = load int *%X
+ br label %Loop
+Loop:
+ call void %foo()
+ br bool %c, label %LoopTail, label %IfUnEqual
+
+IfUnEqual:
+ %B1 = div int 4, %A ;; Should not hoist this div!
+ br label %LoopTail
+
+LoopTail:
+ %B = phi int [ 0, %Loop ], [ %B1, %IfUnEqual]
+ br bool %c, label %Loop, label %Out
+
+Out:
+ %C = sub int %A, %B
+ ret int %C
+}
--- /dev/null
+; This testcase tests to make sure a trapping instruction is hoisted when
+; it is guaranteed to execute.
+;
+; RUN: as < %s | opt -licm | dis | grep -C 2 "test" | grep div
+
+%X = global int 0
+declare void %foo()
+
+int %test(bool %c) {
+ %A = load int *%X
+ br label %Loop
+Loop:
+ call void %foo()
+ %B = div int 4, %A ;; Should have hoisted this div!
+ br bool %c, label %Loop, label %Out
+
+Out:
+ %C = sub int %A, %B
+ ret int %C
+}