1 ; RUN: opt < %s -licm -S | FileCheck %s
2 @X = global i32 7 ; <i32*> [#uses=4]
4 define void @test1(i32 %i) {
9 ; CHECK-NEXT: load i32* @X
10 ; CHECK-NEXT: br label %Loop
13 Loop: ; preds = %Loop, %0
14 %j = phi i32 [ 0, %Entry ], [ %Next, %Loop ] ; <i32> [#uses=1]
15 %x = load i32* @X ; <i32> [#uses=1]
16 %x2 = add i32 %x, 1 ; <i32> [#uses=1]
17 store i32 %x2, i32* @X
18 %Next = add i32 %j, 1 ; <i32> [#uses=2]
19 %cond = icmp eq i32 %Next, 0 ; <i1> [#uses=1]
20 br i1 %cond, label %Out, label %Loop
25 ; CHECK-NEXT: store i32 %x2, i32* @X
26 ; CHECK-NEXT: ret void
30 define void @test2(i32 %i) {
35 ; CHECK-NEXT: %X1 = getelementptr i32* @X, i64 0
36 ; CHECK-NEXT: %X2 = getelementptr i32* @X, i64 0
37 ; CHECK-NEXT: %X1.promoted = load i32* %X1
38 ; CHECK-NEXT: br label %Loop
40 Loop: ; preds = %Loop, %0
41 %X1 = getelementptr i32* @X, i64 0 ; <i32*> [#uses=1]
42 %A = load i32* %X1 ; <i32> [#uses=1]
43 %V = add i32 %A, 1 ; <i32> [#uses=1]
44 %X2 = getelementptr i32* @X, i64 0 ; <i32*> [#uses=1]
45 store i32 %V, i32* %X2
46 br i1 false, label %Loop, label %Exit
51 ; CHECK-NEXT: store i32 %V, i32* %X1
52 ; CHECK-NEXT: ret void
57 define void @test3(i32 %i) {
61 ; Should not promote this to a register
62 %x = volatile load i32* @X
64 store i32 %x2, i32* @X
65 br i1 true, label %Out, label %Loop
68 ; CHECK-NEXT: volatile load