1 ; RUN: opt %s -licm -S | FileCheck %s
3 @X = global i32 0 ; <i32*> [#uses=1]
7 ; This testcase tests for a problem where LICM hoists
8 ; potentially trapping instructions when they are not guaranteed to execute.
9 define i32 @test1(i1 %c) {
11 %A = load i32* @X ; <i32> [#uses=2]
13 Loop: ; preds = %LoopTail, %0
15 br i1 %c, label %LoopTail, label %IfUnEqual
17 IfUnEqual: ; preds = %Loop
19 ; CHECK-NEXT: sdiv i32 4, %A
20 %B1 = sdiv i32 4, %A ; <i32> [#uses=1]
23 LoopTail: ; preds = %IfUnEqual, %Loop
24 %B = phi i32 [ 0, %Loop ], [ %B1, %IfUnEqual ] ; <i32> [#uses=1]
25 br i1 %c, label %Loop, label %Out
26 Out: ; preds = %LoopTail
27 %C = sub i32 %A, %B ; <i32> [#uses=1]
32 declare void @foo2(i32)
35 ;; It is ok and desirable to hoist this potentially trapping instruction.
36 define i32 @test2(i1 %c) {
38 ; CHECK-NEXT: load i32* @X
39 ; CHECK-NEXT: %B = sdiv i32 4, %A
40 %A = load i32* @X ; <i32> [#uses=2]
43 ;; Should have hoisted this div!
44 %B = sdiv i32 4, %A ; <i32> [#uses=2]
45 call void @foo2( i32 %B )
46 br i1 %c, label %Loop, label %Out
48 %C = sub i32 %A, %B ; <i32> [#uses=1]