New testcase distilled from:
[oota-llvm.git] / test / Transforms / LICM / 2003-08-04-TrappingInstHoist.ll
1 ; This testcase tests for a problem where LICM hoists 
2 ; potentially trapping instructions when they are not guaranteed to execute.
3 ;
4 ; RUN: llvm-as < %s | opt -licm | llvm-dis | grep -C 2 "IfUnEqual" | grep div 
5
6 %X = global int 0
7 declare void %foo()
8
9 int %test(bool %c) {
10         %A = load int *%X
11         br label %Loop
12 Loop:
13         call void %foo()
14         br bool %c, label %LoopTail, label %IfUnEqual
15
16 IfUnEqual:
17         %B1 = div int 4, %A  ;; Should not hoist this div!
18         br label %LoopTail
19
20 LoopTail:
21         %B = phi int [ 0, %Loop ], [ %B1, %IfUnEqual] 
22         br bool %c, label %Loop, label %Out
23
24 Out:
25         %C = sub int %A, %B
26         ret int %C
27 }