1 ; RUN: opt < %s -licm -S | FileCheck %s
2 target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
4 @X = global i32 7 ; <i32*> [#uses=4]
6 define void @test1(i32 %i) {
11 ; CHECK-NEXT: load i32* @X
12 ; CHECK-NEXT: br label %Loop
15 Loop: ; preds = %Loop, %0
16 %j = phi i32 [ 0, %Entry ], [ %Next, %Loop ] ; <i32> [#uses=1]
17 %x = load i32* @X ; <i32> [#uses=1]
18 %x2 = add i32 %x, 1 ; <i32> [#uses=1]
19 store i32 %x2, i32* @X
20 %Next = add i32 %j, 1 ; <i32> [#uses=2]
21 %cond = icmp eq i32 %Next, 0 ; <i1> [#uses=1]
22 br i1 %cond, label %Out, label %Loop
27 ; CHECK-NEXT: store i32 %x2, i32* @X
28 ; CHECK-NEXT: ret void
32 define void @test2(i32 %i) {
37 ; CHECK-NEXT: %.promoted = load i32* getelementptr inbounds (i32* @X, i64 1)
38 ; CHECK-NEXT: br label %Loop
40 Loop: ; preds = %Loop, %0
41 %X1 = getelementptr i32* @X, i64 1 ; <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 1 ; <i32*> [#uses=1]
45 store i32 %V, i32* %X2
46 br i1 false, label %Loop, label %Exit
51 ; CHECK-NEXT: store i32 %V, i32* getelementptr inbounds (i32* @X, i64 1)
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
75 define void @test4(i8* %x, i8 %n) {
79 store i8* %x, i8** %handle1
83 %tmp = getelementptr i8* %x, i64 8
84 store i8* %tmp, i8** %handle2
88 %count = phi i8 [ 0, %loop ], [ %nextcount, %subloop ]
89 %offsetx2 = load i8** %handle2
90 store i8 %n, i8* %offsetx2
91 %newoffsetx2 = getelementptr i8* %offsetx2, i64 -1
92 store i8* %newoffsetx2, i8** %handle2
93 %nextcount = add i8 %count, 1
94 %innerexitcond = icmp sge i8 %nextcount, 8
95 br i1 %innerexitcond, label %innerexit, label %subloop
97 ; Should have promoted 'handle2' accesses.
99 ; CHECK-NEXT: phi i8* [
100 ; CHECK-NEXT: %count = phi i8 [
101 ; CHECK-NEXT: store i8 %n
106 %offsetx1 = load i8** %handle1
107 %val = load i8* %offsetx1
108 %cond = icmp eq i8 %val, %n
109 br i1 %cond, label %exit, label %loop
111 ; Should not have promoted offsetx1 loads.
113 ; CHECK: %val = load i8* %offsetx1
114 ; CHECK: %cond = icmp eq i8 %val, %n
115 ; CHECK: br i1 %cond, label %exit, label %loop