summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/EarlyCSE/invariant.start.ll
blob: 8b468a5b308a135f8b515767dec405f17c941a99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
; RUN: opt < %s -S -early-cse | FileCheck %s
; RUN: opt < %s -S -passes=early-cse | FileCheck %s

declare {}* @llvm.invariant.start.p0i8(i64, i8* nocapture) nounwind readonly
declare void @llvm.invariant.end.p0i8({}*, i64, i8* nocapture) nounwind

; Check that we do load-load forwarding over invariant.start, since it does not
; clobber memory
define i8 @test1(i8 *%P) {
  ; CHECK-LABEL: @test1(
  ; CHECK-NEXT: %V1 = load i8, i8* %P
  ; CHECK-NEXT: %i = call {}* @llvm.invariant.start.p0i8(i64 1, i8* %P)
  ; CHECK-NEXT: ret i8 0


  %V1 = load i8, i8* %P
  %i = call {}* @llvm.invariant.start.p0i8(i64 1, i8* %P)
  %V2 = load i8, i8* %P
  %Diff = sub i8 %V1, %V2
  ret i8 %Diff
}


; Trivial Store->load forwarding over invariant.start
define i8 @test2(i8 *%P) {
  ; CHECK-LABEL: @test2(
  ; CHECK-NEXT: store i8 42, i8* %P
  ; CHECK-NEXT: %i = call {}* @llvm.invariant.start.p0i8(i64 1, i8* %P)
  ; CHECK-NEXT: ret i8 42


  store i8 42, i8* %P
  %i = call {}* @llvm.invariant.start.p0i8(i64 1, i8* %P)
  %V1 = load i8, i8* %P
  ret i8 %V1
}

; We can DSE over invariant.start calls, since the first store to
; %P is valid, and the second store is actually unreachable based on semantics
; of invariant.start.
define void @test3(i8* %P) {

; CHECK-LABEL: @test3(
; CHECK-NEXT:  %i = call {}* @llvm.invariant.start.p0i8(i64 1, i8* %P)
; CHECK-NEXT:  store i8 60, i8* %P


  store i8 50, i8* %P
  %i = call {}* @llvm.invariant.start.p0i8(i64 1, i8* %P)
  store i8 60, i8* %P
  ret void
}


; FIXME: Now the first store can actually be eliminated, since there is no read within
; the invariant region, between start and end.
define void @test4(i8* %P) {

; CHECK-LABEL: @test4(
; CHECK-NEXT: store i8 50, i8* %P
; CHECK-NEXT:  %i = call {}* @llvm.invariant.start.p0i8(i64 1, i8* %P)
; CHECK-NEXT: call void @llvm.invariant.end.p0i8({}* %i, i64 1, i8* %P)
; CHECK-NEXT:  store i8 60, i8* %P


  store i8 50, i8* %P
  %i = call {}* @llvm.invariant.start.p0i8(i64 1, i8* %P)
  call void @llvm.invariant.end.p0i8({}* %i, i64 1, i8* %P)
  store i8 60, i8* %P
  ret void
}
OpenPOWER on IntegriCloud