2014-09-16 01:56:56 +08:00
|
|
|
; Test that GCSE uses basicaa to do alias analysis, which is capable of
|
|
|
|
; disambiguating some obvious cases. All loads should be removable in
|
2002-08-23 01:31:36 +08:00
|
|
|
; this testcase.
|
|
|
|
|
2020-06-27 05:58:01 +08:00
|
|
|
; RUN: opt < %s -basic-aa -gvn -instcombine -dce -S | FileCheck %s
|
2002-08-23 01:31:36 +08:00
|
|
|
|
2008-02-14 14:56:27 +08:00
|
|
|
@A = global i32 7
|
|
|
|
@B = global i32 8
|
2002-08-23 01:31:36 +08:00
|
|
|
|
2012-04-24 17:15:38 +08:00
|
|
|
; CHECK: define i32 @test()
|
|
|
|
; CHECK-NEXT: store i32 123, i32* @B
|
|
|
|
; CHECK-NEXT: ret i32 0
|
|
|
|
|
2008-02-14 14:56:27 +08:00
|
|
|
define i32 @test() {
|
2015-02-28 05:17:42 +08:00
|
|
|
%A1 = load i32, i32* @A
|
2002-08-23 01:31:36 +08:00
|
|
|
|
2008-02-14 14:56:27 +08:00
|
|
|
store i32 123, i32* @B ; Store cannot alias @A
|
2002-08-23 01:31:36 +08:00
|
|
|
|
2015-02-28 05:17:42 +08:00
|
|
|
%A2 = load i32, i32* @A
|
2008-02-14 14:56:27 +08:00
|
|
|
%X = sub i32 %A1, %A2
|
|
|
|
ret i32 %X
|
2002-08-23 01:31:36 +08:00
|
|
|
}
|
|
|
|
|
2012-04-24 17:15:38 +08:00
|
|
|
; CHECK: define i32 @test2()
|
|
|
|
; CHECK-NEXT: br label %Loop
|
|
|
|
; CHECK: Loop:
|
|
|
|
; CHECK-NEXT: store i32 0, i32* @B
|
|
|
|
; CHECK-NEXT: br i1 true, label %out, label %Loop
|
|
|
|
; CHECK: out:
|
|
|
|
; CHECK-NEXT: ret i32 0
|
|
|
|
|
2008-02-14 14:56:27 +08:00
|
|
|
define i32 @test2() {
|
2015-02-28 05:17:42 +08:00
|
|
|
%A1 = load i32, i32* @A
|
2002-08-23 04:22:55 +08:00
|
|
|
br label %Loop
|
|
|
|
Loop:
|
2008-02-14 14:56:27 +08:00
|
|
|
%AP = phi i32 [0, %0], [%X, %Loop]
|
|
|
|
store i32 %AP, i32* @B ; Store cannot alias @A
|
2002-08-23 04:22:55 +08:00
|
|
|
|
2015-02-28 05:17:42 +08:00
|
|
|
%A2 = load i32, i32* @A
|
2008-02-14 14:56:27 +08:00
|
|
|
%X = sub i32 %A1, %A2
|
|
|
|
%c = icmp eq i32 %X, 0
|
|
|
|
br i1 %c, label %out, label %Loop
|
2002-08-23 04:22:55 +08:00
|
|
|
|
|
|
|
out:
|
2008-02-14 14:56:27 +08:00
|
|
|
ret i32 %X
|
2002-08-23 04:22:55 +08:00
|
|
|
}
|
|
|
|
|
2008-02-14 14:56:27 +08:00
|
|
|
declare void @external()
|
2004-03-13 06:38:31 +08:00
|
|
|
|
2012-04-24 17:15:38 +08:00
|
|
|
; CHECK: define i32 @test3()
|
|
|
|
; CHECK-NEXT: call void @external()
|
|
|
|
; CHECK-NEXT: ret i32 7
|
|
|
|
|
2008-02-14 14:56:27 +08:00
|
|
|
define i32 @test3() {
|
|
|
|
%X = alloca i32
|
|
|
|
store i32 7, i32* %X
|
|
|
|
call void @external()
|
2015-02-28 05:17:42 +08:00
|
|
|
%V = load i32, i32* %X
|
2008-02-14 14:56:27 +08:00
|
|
|
ret i32 %V
|
2004-03-13 06:38:31 +08:00
|
|
|
}
|
|
|
|
|