blob: 8b468a5b308a135f8b515767dec405f17c941a99 [file] [log] [blame]
Anna Thomasb2d12b82016-08-09 20:00:47 +00001; RUN: opt < %s -S -early-cse | FileCheck %s
2; RUN: opt < %s -S -passes=early-cse | FileCheck %s
3
4declare {}* @llvm.invariant.start.p0i8(i64, i8* nocapture) nounwind readonly
5declare void @llvm.invariant.end.p0i8({}*, i64, i8* nocapture) nounwind
6
7; Check that we do load-load forwarding over invariant.start, since it does not
8; clobber memory
9define i8 @test1(i8 *%P) {
10 ; CHECK-LABEL: @test1(
11 ; CHECK-NEXT: %V1 = load i8, i8* %P
12 ; CHECK-NEXT: %i = call {}* @llvm.invariant.start.p0i8(i64 1, i8* %P)
13 ; CHECK-NEXT: ret i8 0
14
15
16 %V1 = load i8, i8* %P
17 %i = call {}* @llvm.invariant.start.p0i8(i64 1, i8* %P)
18 %V2 = load i8, i8* %P
19 %Diff = sub i8 %V1, %V2
20 ret i8 %Diff
21}
22
23
24; Trivial Store->load forwarding over invariant.start
25define i8 @test2(i8 *%P) {
26 ; CHECK-LABEL: @test2(
27 ; CHECK-NEXT: store i8 42, i8* %P
28 ; CHECK-NEXT: %i = call {}* @llvm.invariant.start.p0i8(i64 1, i8* %P)
29 ; CHECK-NEXT: ret i8 42
30
31
32 store i8 42, i8* %P
33 %i = call {}* @llvm.invariant.start.p0i8(i64 1, i8* %P)
34 %V1 = load i8, i8* %P
35 ret i8 %V1
36}
37
38; We can DSE over invariant.start calls, since the first store to
39; %P is valid, and the second store is actually unreachable based on semantics
40; of invariant.start.
41define void @test3(i8* %P) {
42
43; CHECK-LABEL: @test3(
44; CHECK-NEXT: %i = call {}* @llvm.invariant.start.p0i8(i64 1, i8* %P)
45; CHECK-NEXT: store i8 60, i8* %P
46
47
48 store i8 50, i8* %P
49 %i = call {}* @llvm.invariant.start.p0i8(i64 1, i8* %P)
50 store i8 60, i8* %P
51 ret void
52}
53
54
55; FIXME: Now the first store can actually be eliminated, since there is no read within
56; the invariant region, between start and end.
57define void @test4(i8* %P) {
58
59; CHECK-LABEL: @test4(
60; CHECK-NEXT: store i8 50, i8* %P
61; CHECK-NEXT: %i = call {}* @llvm.invariant.start.p0i8(i64 1, i8* %P)
62; CHECK-NEXT: call void @llvm.invariant.end.p0i8({}* %i, i64 1, i8* %P)
63; CHECK-NEXT: store i8 60, i8* %P
64
65
66 store i8 50, i8* %P
67 %i = call {}* @llvm.invariant.start.p0i8(i64 1, i8* %P)
68 call void @llvm.invariant.end.p0i8({}* %i, i64 1, i8* %P)
69 store i8 60, i8* %P
70 ret void
71}