2010-10-18 20:04:47 +02:00
|
|
|
; RUN: opt < %s -basicaa -sink -S | FileCheck %s
|
2010-05-07 17:40:13 +02:00
|
|
|
|
|
|
|
@A = external global i32
|
|
|
|
@B = external global i32
|
|
|
|
|
|
|
|
; Sink should sink the load past the store (which doesn't overlap) into
|
|
|
|
; the block that uses it.
|
|
|
|
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @foo(
|
2010-05-07 17:40:13 +02:00
|
|
|
; CHECK: true:
|
|
|
|
; CHECK-NEXT: %l = load i32* @A
|
|
|
|
; CHECK-NEXT: ret i32 %l
|
|
|
|
|
|
|
|
define i32 @foo(i1 %z) {
|
|
|
|
%l = load i32* @A
|
|
|
|
store i32 0, i32* @B
|
|
|
|
br i1 %z, label %true, label %false
|
|
|
|
true:
|
|
|
|
ret i32 %l
|
|
|
|
false:
|
|
|
|
ret i32 0
|
|
|
|
}
|
2011-09-01 23:21:24 +02:00
|
|
|
|
2011-11-27 07:54:59 +01:00
|
|
|
; But don't sink load volatiles...
|
2011-09-01 23:21:24 +02:00
|
|
|
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @foo2(
|
2011-09-01 23:25:42 +02:00
|
|
|
; CHECK: load volatile
|
2011-09-01 23:21:24 +02:00
|
|
|
; CHECK-NEXT: store i32
|
|
|
|
|
|
|
|
define i32 @foo2(i1 %z) {
|
2011-09-01 23:25:42 +02:00
|
|
|
%l = load volatile i32* @A
|
2011-09-01 23:21:24 +02:00
|
|
|
store i32 0, i32* @B
|
|
|
|
br i1 %z, label %true, label %false
|
|
|
|
true:
|
|
|
|
ret i32 %l
|
|
|
|
false:
|
|
|
|
ret i32 0
|
|
|
|
}
|
2012-05-31 10:09:49 +02:00
|
|
|
|
|
|
|
; Sink to the nearest post-dominator
|
|
|
|
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @diamond(
|
2012-05-31 10:09:49 +02:00
|
|
|
; CHECK: X:
|
|
|
|
; CHECK-NEXT: phi
|
|
|
|
; CHECK-NEXT: mul nsw
|
|
|
|
; CHECK-NEXT: sub
|
|
|
|
|
|
|
|
define i32 @diamond(i32 %a, i32 %b, i32 %c) {
|
|
|
|
%1 = mul nsw i32 %c, %b
|
|
|
|
%2 = icmp sgt i32 %a, 0
|
|
|
|
br i1 %2, label %B0, label %B1
|
|
|
|
|
|
|
|
B0: ; preds = %0
|
|
|
|
br label %X
|
|
|
|
|
|
|
|
B1: ; preds = %0
|
|
|
|
br label %X
|
|
|
|
|
|
|
|
X: ; preds = %5, %3
|
|
|
|
%.01 = phi i32 [ %c, %B0 ], [ %a, %B1 ]
|
|
|
|
%R = sub i32 %1, %.01
|
|
|
|
ret i32 %R
|
|
|
|
}
|
|
|
|
|