2011-01-02 23:04:14 +00:00
|
|
|
; RUN: opt < %s -S -early-cse | FileCheck %s
|
2015-02-01 10:51:23 +00:00
|
|
|
; RUN: opt < %s -S -passes=early-cse | FileCheck %s
|
2011-01-02 23:04:14 +00:00
|
|
|
|
2014-11-03 20:21:32 +00:00
|
|
|
declare void @llvm.assume(i1) nounwind
|
2011-01-02 23:04:14 +00:00
|
|
|
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test1(
|
2011-01-02 23:04:14 +00:00
|
|
|
define void @test1(i8 %V, i32 *%P) {
|
|
|
|
%A = bitcast i64 42 to double ;; dead
|
|
|
|
%B = add i32 4, 19 ;; constant folds
|
|
|
|
store i32 %B, i32* %P
|
|
|
|
; CHECK-NEXT: store i32 23, i32* %P
|
|
|
|
|
|
|
|
%C = zext i8 %V to i32
|
|
|
|
%D = zext i8 %V to i32 ;; CSE
|
2011-11-27 06:54:59 +00:00
|
|
|
store volatile i32 %C, i32* %P
|
|
|
|
store volatile i32 %D, i32* %P
|
2011-01-02 23:04:14 +00:00
|
|
|
; CHECK-NEXT: %C = zext i8 %V to i32
|
2011-08-12 22:50:01 +00:00
|
|
|
; CHECK-NEXT: store volatile i32 %C
|
|
|
|
; CHECK-NEXT: store volatile i32 %C
|
2011-01-02 23:19:45 +00:00
|
|
|
|
|
|
|
%E = add i32 %C, %C
|
|
|
|
%F = add i32 %C, %C
|
2011-11-27 06:54:59 +00:00
|
|
|
store volatile i32 %E, i32* %P
|
|
|
|
store volatile i32 %F, i32* %P
|
2011-01-02 23:19:45 +00:00
|
|
|
; CHECK-NEXT: %E = add i32 %C, %C
|
2011-08-12 22:50:01 +00:00
|
|
|
; CHECK-NEXT: store volatile i32 %E
|
|
|
|
; CHECK-NEXT: store volatile i32 %E
|
2011-01-02 23:19:45 +00:00
|
|
|
|
|
|
|
%G = add nuw i32 %C, %C ;; not a CSE with E
|
2011-11-27 06:54:59 +00:00
|
|
|
store volatile i32 %G, i32* %P
|
2011-01-02 23:19:45 +00:00
|
|
|
; CHECK-NEXT: %G = add nuw i32 %C, %C
|
2011-08-12 22:50:01 +00:00
|
|
|
; CHECK-NEXT: store volatile i32 %G
|
2011-01-02 23:04:14 +00:00
|
|
|
ret void
|
|
|
|
}
|
2011-01-03 03:18:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
;; Simple load value numbering.
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test2(
|
2011-01-03 03:18:43 +00:00
|
|
|
define i32 @test2(i32 *%P) {
|
2015-02-27 21:17:42 +00:00
|
|
|
%V1 = load i32, i32* %P
|
|
|
|
%V2 = load i32, i32* %P
|
2011-01-03 03:18:43 +00:00
|
|
|
%Diff = sub i32 %V1, %V2
|
|
|
|
ret i32 %Diff
|
|
|
|
; CHECK: ret i32 0
|
|
|
|
}
|
|
|
|
|
2014-11-03 20:21:32 +00:00
|
|
|
; CHECK-LABEL: @test2a(
|
|
|
|
define i32 @test2a(i32 *%P, i1 %b) {
|
2015-02-27 21:17:42 +00:00
|
|
|
%V1 = load i32, i32* %P
|
2014-11-03 20:21:32 +00:00
|
|
|
tail call void @llvm.assume(i1 %b)
|
2015-02-27 21:17:42 +00:00
|
|
|
%V2 = load i32, i32* %P
|
2014-11-03 20:21:32 +00:00
|
|
|
%Diff = sub i32 %V1, %V2
|
|
|
|
ret i32 %Diff
|
|
|
|
; CHECK: ret i32 0
|
|
|
|
}
|
|
|
|
|
2011-01-03 03:18:43 +00:00
|
|
|
;; Cross block load value numbering.
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test3(
|
2011-01-03 03:18:43 +00:00
|
|
|
define i32 @test3(i32 *%P, i1 %Cond) {
|
2015-02-27 21:17:42 +00:00
|
|
|
%V1 = load i32, i32* %P
|
2011-01-03 03:18:43 +00:00
|
|
|
br i1 %Cond, label %T, label %F
|
|
|
|
T:
|
|
|
|
store i32 4, i32* %P
|
|
|
|
ret i32 42
|
|
|
|
F:
|
2015-02-27 21:17:42 +00:00
|
|
|
%V2 = load i32, i32* %P
|
2011-01-03 03:18:43 +00:00
|
|
|
%Diff = sub i32 %V1, %V2
|
|
|
|
ret i32 %Diff
|
|
|
|
; CHECK: F:
|
|
|
|
; CHECK: ret i32 0
|
|
|
|
}
|
|
|
|
|
2014-11-03 20:21:32 +00:00
|
|
|
; CHECK-LABEL: @test3a(
|
|
|
|
define i32 @test3a(i32 *%P, i1 %Cond, i1 %b) {
|
2015-02-27 21:17:42 +00:00
|
|
|
%V1 = load i32, i32* %P
|
2014-11-03 20:21:32 +00:00
|
|
|
br i1 %Cond, label %T, label %F
|
|
|
|
T:
|
|
|
|
store i32 4, i32* %P
|
|
|
|
ret i32 42
|
|
|
|
F:
|
|
|
|
tail call void @llvm.assume(i1 %b)
|
2015-02-27 21:17:42 +00:00
|
|
|
%V2 = load i32, i32* %P
|
2014-11-03 20:21:32 +00:00
|
|
|
%Diff = sub i32 %V1, %V2
|
|
|
|
ret i32 %Diff
|
|
|
|
; CHECK: F:
|
|
|
|
; CHECK: ret i32 0
|
|
|
|
}
|
|
|
|
|
2011-01-03 03:18:43 +00:00
|
|
|
;; Cross block load value numbering stops when stores happen.
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test4(
|
2011-01-03 03:18:43 +00:00
|
|
|
define i32 @test4(i32 *%P, i1 %Cond) {
|
2015-02-27 21:17:42 +00:00
|
|
|
%V1 = load i32, i32* %P
|
2011-01-03 03:18:43 +00:00
|
|
|
br i1 %Cond, label %T, label %F
|
|
|
|
T:
|
|
|
|
ret i32 42
|
|
|
|
F:
|
|
|
|
; Clobbers V1
|
|
|
|
store i32 42, i32* %P
|
|
|
|
|
2015-02-27 21:17:42 +00:00
|
|
|
%V2 = load i32, i32* %P
|
2011-01-03 03:18:43 +00:00
|
|
|
%Diff = sub i32 %V1, %V2
|
|
|
|
ret i32 %Diff
|
|
|
|
; CHECK: F:
|
|
|
|
; CHECK: ret i32 %Diff
|
|
|
|
}
|
2011-01-03 03:33:47 +00:00
|
|
|
|
|
|
|
declare i32 @func(i32 *%P) readonly
|
|
|
|
|
|
|
|
;; Simple call CSE'ing.
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test5(
|
2011-01-03 03:33:47 +00:00
|
|
|
define i32 @test5(i32 *%P) {
|
|
|
|
%V1 = call i32 @func(i32* %P)
|
|
|
|
%V2 = call i32 @func(i32* %P)
|
|
|
|
%Diff = sub i32 %V1, %V2
|
|
|
|
ret i32 %Diff
|
|
|
|
; CHECK: ret i32 0
|
|
|
|
}
|
2011-01-03 03:46:34 +00:00
|
|
|
|
|
|
|
;; Trivial Store->load forwarding
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test6(
|
2011-01-03 03:46:34 +00:00
|
|
|
define i32 @test6(i32 *%P) {
|
|
|
|
store i32 42, i32* %P
|
2015-02-27 21:17:42 +00:00
|
|
|
%V1 = load i32, i32* %P
|
2011-01-03 03:46:34 +00:00
|
|
|
ret i32 %V1
|
|
|
|
; CHECK: ret i32 42
|
|
|
|
}
|
2011-01-03 04:17:24 +00:00
|
|
|
|
2014-11-03 20:21:32 +00:00
|
|
|
; CHECK-LABEL: @test6a(
|
|
|
|
define i32 @test6a(i32 *%P, i1 %b) {
|
|
|
|
store i32 42, i32* %P
|
|
|
|
tail call void @llvm.assume(i1 %b)
|
2015-02-27 21:17:42 +00:00
|
|
|
%V1 = load i32, i32* %P
|
2014-11-03 20:21:32 +00:00
|
|
|
ret i32 %V1
|
|
|
|
; CHECK: ret i32 42
|
|
|
|
}
|
|
|
|
|
2011-01-03 04:17:24 +00:00
|
|
|
;; Trivial dead store elimination.
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test7(
|
2011-01-03 04:17:24 +00:00
|
|
|
define void @test7(i32 *%P) {
|
|
|
|
store i32 42, i32* %P
|
|
|
|
store i32 45, i32* %P
|
|
|
|
ret void
|
|
|
|
; CHECK-NEXT: store i32 45
|
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
}
|
2011-01-03 23:38:13 +00:00
|
|
|
|
|
|
|
;; Readnone functions aren't invalidated by stores.
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test8(
|
2011-01-03 23:38:13 +00:00
|
|
|
define i32 @test8(i32 *%P) {
|
|
|
|
%V1 = call i32 @func(i32* %P) readnone
|
|
|
|
store i32 4, i32* %P
|
|
|
|
%V2 = call i32 @func(i32* %P) readnone
|
|
|
|
%Diff = sub i32 %V1, %V2
|
|
|
|
ret i32 %Diff
|
|
|
|
; CHECK: ret i32 0
|
|
|
|
}
|
|
|
|
|
2014-11-18 17:46:32 +00:00
|
|
|
;; Trivial DSE can't be performed across a readonly call. The call
|
|
|
|
;; can observe the earlier write.
|
|
|
|
; CHECK-LABEL: @test9(
|
|
|
|
define i32 @test9(i32 *%P) {
|
|
|
|
store i32 4, i32* %P
|
|
|
|
%V1 = call i32 @func(i32* %P) readonly
|
|
|
|
store i32 5, i32* %P
|
|
|
|
ret i32 %V1
|
|
|
|
; CHECK: store i32 4, i32* %P
|
|
|
|
; CHECK-NEXT: %V1 = call i32 @func(i32* %P)
|
|
|
|
; CHECK-NEXT: store i32 5, i32* %P
|
|
|
|
; CHECK-NEXT: ret i32 %V1
|
|
|
|
}
|
|
|
|
|
|
|
|
;; Trivial DSE can be performed across a readnone call.
|
|
|
|
; CHECK-LABEL: @test10
|
|
|
|
define i32 @test10(i32 *%P) {
|
|
|
|
store i32 4, i32* %P
|
|
|
|
%V1 = call i32 @func(i32* %P) readnone
|
|
|
|
store i32 5, i32* %P
|
|
|
|
ret i32 %V1
|
|
|
|
; CHECK-NEXT: %V1 = call i32 @func(i32* %P)
|
|
|
|
; CHECK-NEXT: store i32 5, i32* %P
|
|
|
|
; CHECK-NEXT: ret i32 %V1
|
|
|
|
}
|
|
|
|
|
|
|
|
;; Trivial dead store elimination - should work for an entire series of dead stores too.
|
|
|
|
; CHECK-LABEL: @test11(
|
|
|
|
define void @test11(i32 *%P) {
|
|
|
|
store i32 42, i32* %P
|
|
|
|
store i32 43, i32* %P
|
|
|
|
store i32 44, i32* %P
|
|
|
|
store i32 45, i32* %P
|
|
|
|
ret void
|
|
|
|
; CHECK-NEXT: store i32 45
|
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
}
|
|
|
|
|
2015-02-10 23:11:02 +00:00
|
|
|
; CHECK-LABEL: @test12(
|
2015-02-10 23:09:43 +00:00
|
|
|
define i32 @test12(i1 %B, i32* %P1, i32* %P2) {
|
2015-02-27 21:17:42 +00:00
|
|
|
%load0 = load i32, i32* %P1
|
|
|
|
%1 = load atomic i32, i32* %P2 seq_cst, align 4
|
|
|
|
%load1 = load i32, i32* %P1
|
2015-02-10 23:09:43 +00:00
|
|
|
%sel = select i1 %B, i32 %load0, i32 %load1
|
|
|
|
ret i32 %sel
|
2015-02-27 21:17:42 +00:00
|
|
|
; CHECK: load i32, i32* %P1
|
|
|
|
; CHECK: load i32, i32* %P1
|
2015-02-10 23:09:43 +00:00
|
|
|
}
|