2009-09-08 22:34:10 +00:00
|
|
|
; RUN: opt %s -licm -S | FileCheck %s
|
2008-01-01 01:34:36 +00:00
|
|
|
@X = global i32 7 ; <i32*> [#uses=4]
|
2003-02-22 22:20:19 +00:00
|
|
|
|
2009-08-30 22:08:19 +00:00
|
|
|
define void @test1(i32 %i) {
|
|
|
|
Entry:
|
2003-02-22 22:20:19 +00:00
|
|
|
br label %Loop
|
2009-08-30 22:08:19 +00:00
|
|
|
; CHECK: @test1
|
|
|
|
; CHECK: Entry:
|
|
|
|
; CHECK-NEXT: load i32* @X
|
|
|
|
; CHECK-NEXT: br label %Loop
|
|
|
|
|
2003-02-22 22:20:19 +00:00
|
|
|
|
2008-01-01 01:34:36 +00:00
|
|
|
Loop: ; preds = %Loop, %0
|
2009-08-30 22:08:19 +00:00
|
|
|
%j = phi i32 [ 0, %Entry ], [ %Next, %Loop ] ; <i32> [#uses=1]
|
2008-01-01 01:34:36 +00:00
|
|
|
%x = load i32* @X ; <i32> [#uses=1]
|
|
|
|
%x2 = add i32 %x, 1 ; <i32> [#uses=1]
|
|
|
|
store i32 %x2, i32* @X
|
|
|
|
%Next = add i32 %j, 1 ; <i32> [#uses=2]
|
|
|
|
%cond = icmp eq i32 %Next, 0 ; <i1> [#uses=1]
|
|
|
|
br i1 %cond, label %Out, label %Loop
|
2003-02-22 22:20:19 +00:00
|
|
|
|
2009-08-30 22:08:19 +00:00
|
|
|
Out:
|
2003-02-22 22:20:19 +00:00
|
|
|
ret void
|
2009-08-30 22:08:19 +00:00
|
|
|
; CHECK: Out:
|
|
|
|
; CHECK-NEXT: store i32 %x2, i32* @X
|
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
|
2003-02-22 22:20:19 +00:00
|
|
|
}
|
2003-02-24 03:52:04 +00:00
|
|
|
|
2009-08-30 22:08:19 +00:00
|
|
|
define void @test2(i32 %i) {
|
|
|
|
Entry:
|
2003-02-24 03:52:04 +00:00
|
|
|
br label %Loop
|
2009-08-30 22:08:19 +00:00
|
|
|
; CHECK: @test2
|
|
|
|
; CHECK: Entry:
|
|
|
|
; CHECK-NEXT: %X1 = getelementptr i32* @X, i64 0
|
|
|
|
; CHECK-NEXT: %X2 = getelementptr i32* @X, i64 0
|
|
|
|
; CHECK-NEXT: %X1.promoted = load i32* %X1
|
|
|
|
; CHECK-NEXT: br label %Loop
|
2003-02-24 03:52:04 +00:00
|
|
|
|
2008-01-01 01:34:36 +00:00
|
|
|
Loop: ; preds = %Loop, %0
|
|
|
|
%X1 = getelementptr i32* @X, i64 0 ; <i32*> [#uses=1]
|
|
|
|
%A = load i32* %X1 ; <i32> [#uses=1]
|
|
|
|
%V = add i32 %A, 1 ; <i32> [#uses=1]
|
|
|
|
%X2 = getelementptr i32* @X, i64 0 ; <i32*> [#uses=1]
|
|
|
|
store i32 %V, i32* %X2
|
|
|
|
br i1 false, label %Loop, label %Exit
|
2003-02-24 03:52:04 +00:00
|
|
|
|
2008-01-01 01:34:36 +00:00
|
|
|
Exit: ; preds = %Loop
|
|
|
|
ret void
|
2009-08-30 22:08:19 +00:00
|
|
|
; CHECK: Exit:
|
|
|
|
; CHECK-NEXT: store i32 %V, i32* %X1
|
|
|
|
; CHECK-NEXT: ret void
|
2003-02-24 03:52:04 +00:00
|
|
|
}
|
2009-08-30 22:08:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
define void @test3(i32 %i) {
|
|
|
|
; CHECK: @test3
|
|
|
|
br label %Loop
|
|
|
|
Loop:
|
|
|
|
; Should not promote this to a register
|
|
|
|
%x = volatile load i32* @X
|
|
|
|
%x2 = add i32 %x, 1
|
|
|
|
store i32 %x2, i32* @X
|
|
|
|
br i1 true, label %Out, label %Loop
|
|
|
|
|
|
|
|
; CHECK: Loop:
|
|
|
|
; CHECK-NEXT: volatile load
|
|
|
|
|
|
|
|
Out: ; preds = %Loop
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|