File: memcpy-byval-forwarding-clobbers.ll

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.6-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,304 kB
  • sloc: cpp: 7,438,677; ansic: 1,393,822; asm: 1,012,926; python: 241,650; f90: 86,635; objc: 75,479; lisp: 42,144; pascal: 17,286; sh: 10,027; ml: 5,082; perl: 4,730; awk: 3,523; makefile: 3,349; javascript: 2,251; xml: 892; fortran: 672
file content (113 lines) | stat: -rw-r--r-- 4,594 bytes parent folder | download | duplicates (6)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -passes=memcpyopt -S %s | FileCheck %s

declare void @init(ptr nocapture sret(i64) align 8)

declare i1 @check(ptr readonly byval(i64) align 8) readonly argmemonly

declare void @clobber(ptr) argmemonly

declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg)

; %a.2's lifetime ends before the call to @check. We must remove the call to
; @llvm.lifetime.end in order to replace %a.1 with %a.2 in the call to @check.
define i1 @alloca_forwarding_lifetime_end_clobber() {
; CHECK-LABEL: @alloca_forwarding_lifetime_end_clobber(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[A_2:%.*]] = alloca i64, align 8
; CHECK-NEXT:    call void @init(ptr sret(i64) align 8 [[A_2]])
; CHECK-NEXT:    store i8 0, ptr [[A_2]], align 1
; CHECK-NEXT:    [[CALL:%.*]] = call i1 @check(ptr byval(i64) align 8 [[A_2]])
; CHECK-NEXT:    ret i1 [[CALL]]
;
entry:
  %a.1 = alloca i64, align 8
  %a.2 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %a.2)
  call void @init(ptr sret(i64) align 8 %a.2)
  store i8 0, ptr %a.2
  call void @llvm.memcpy.p0.p0.i64(ptr %a.1, ptr %a.2, i64 8, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %a.2)
  ;call void @clobber(ptr %a.2)
  %call = call i1 @check(ptr byval(i64) align 8 %a.1)
  ret i1 %call
}

; There is a call clobbering %a.2 before the call to @check. Cannot replace
; %a.1 with %a.2 in the call to @check.
define i1 @alloca_forwarding_call_clobber() {
; CHECK-LABEL: @alloca_forwarding_call_clobber(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[A_1:%.*]] = alloca i64, align 8
; CHECK-NEXT:    [[A_2:%.*]] = alloca i64, align 8
; CHECK-NEXT:    call void @llvm.lifetime.start.p0(i64 8, ptr [[A_2]])
; CHECK-NEXT:    call void @init(ptr sret(i64) align 8 [[A_2]])
; CHECK-NEXT:    store i8 0, ptr [[A_2]], align 1
; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i64(ptr [[A_1]], ptr [[A_2]], i64 8, i1 false)
; CHECK-NEXT:    call void @clobber(ptr [[A_2]])
; CHECK-NEXT:    [[CALL:%.*]] = call i1 @check(ptr byval(i64) align 8 [[A_1]])
; CHECK-NEXT:    ret i1 [[CALL]]
;
entry:
  %a.1 = alloca i64, align 8
  %a.2 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %a.2)
  call void @init(ptr sret(i64) align 8 %a.2)
  store i8 0, ptr %a.2
  call void @llvm.memcpy.p0.p0.i64(ptr %a.1, ptr %a.2, i64 8, i1 false)
  call void @clobber(ptr %a.2)
  %call = call i1 @check(ptr byval(i64) align 8 %a.1)
  ret i1 %call
}

define i1 @alloca_forwarding_call_clobber_after() {
; CHECK-LABEL: @alloca_forwarding_call_clobber_after(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[A_1:%.*]] = alloca i64, align 8
; CHECK-NEXT:    [[A_2:%.*]] = alloca i64, align 8
; CHECK-NEXT:    call void @llvm.lifetime.start.p0(i64 8, ptr [[A_2]])
; CHECK-NEXT:    call void @init(ptr sret(i64) align 8 [[A_2]])
; CHECK-NEXT:    store i8 0, ptr [[A_2]], align 1
; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i64(ptr [[A_1]], ptr [[A_2]], i64 8, i1 false)
; CHECK-NEXT:    [[CALL:%.*]] = call i1 @check(ptr byval(i64) align 8 [[A_2]])
; CHECK-NEXT:    call void @clobber(ptr [[A_2]])
; CHECK-NEXT:    ret i1 [[CALL]]
;
entry:
  %a.1 = alloca i64, align 8
  %a.2 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %a.2)
  call void @init(ptr sret(i64) align 8 %a.2)
  store i8 0, ptr %a.2
  call void @llvm.memcpy.p0.p0.i64(ptr %a.1, ptr %a.2, i64 8, i1 false)
  %call = call i1 @check(ptr byval(i64) align 8 %a.1)
  call void @clobber(ptr %a.2)
  ret i1 %call
}

define i1 @alloca_forwarding_unrelated_call_noclobber() {
; CHECK-LABEL: @alloca_forwarding_unrelated_call_noclobber(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[A_2:%.*]] = alloca i64, align 8
; CHECK-NEXT:    [[A_3:%.*]] = alloca i64, align 8
; CHECK-NEXT:    call void @init(ptr sret(i64) align 8 [[A_2]])
; CHECK-NEXT:    store i8 0, ptr [[A_2]], align 1
; CHECK-NEXT:    call void @clobber(ptr [[A_3]])
; CHECK-NEXT:    [[CALL:%.*]] = call i1 @check(ptr byval(i64) align 8 [[A_2]])
; CHECK-NEXT:    ret i1 [[CALL]]
;
entry:
  %a.1 = alloca i64, align 8
  %a.2 = alloca i64, align 8
  %a.3 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %a.2)
  call void @init(ptr sret(i64) align 8 %a.2)
  store i8 0, ptr %a.2
  call void @llvm.memcpy.p0.p0.i64(ptr %a.1, ptr %a.2, i64 8, i1 false)
  call void @clobber(ptr %a.3)
  %call = call i1 @check(ptr byval(i64) align 8 %a.1)
  ret i1 %call
}