File: memcpy-undef.ll

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (139 lines) | stat: -rw-r--r-- 6,343 bytes parent folder | download | duplicates (4)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -basic-aa -memcpyopt -S -verify-memoryssa | FileCheck %s

target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.8.0"

%struct.foo = type { i8, [7 x i8], i32 }

; Check that the memcpy is removed.
define i32 @test1(%struct.foo* nocapture %foobie) nounwind noinline ssp uwtable {
; CHECK-LABEL: @test1(
; CHECK-NEXT:    [[BLETCH_SROA_1:%.*]] = alloca [7 x i8], align 1
; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds [[STRUCT_FOO:%.*]], %struct.foo* [[FOOBIE:%.*]], i64 0, i32 0
; CHECK-NEXT:    store i8 98, i8* [[TMP1]], align 4
; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds [[STRUCT_FOO]], %struct.foo* [[FOOBIE]], i64 0, i32 1, i64 0
; CHECK-NEXT:    [[TMP3:%.*]] = getelementptr inbounds [7 x i8], [7 x i8]* [[BLETCH_SROA_1]], i64 0, i64 0
; CHECK-NEXT:    [[TMP4:%.*]] = getelementptr inbounds [[STRUCT_FOO]], %struct.foo* [[FOOBIE]], i64 0, i32 2
; CHECK-NEXT:    store i32 20, i32* [[TMP4]], align 4
; CHECK-NEXT:    ret i32 undef
;
  %bletch.sroa.1 = alloca [7 x i8], align 1
  %1 = getelementptr inbounds %struct.foo, %struct.foo* %foobie, i64 0, i32 0
  store i8 98, i8* %1, align 4
  %2 = getelementptr inbounds %struct.foo, %struct.foo* %foobie, i64 0, i32 1, i64 0
  %3 = getelementptr inbounds [7 x i8], [7 x i8]* %bletch.sroa.1, i64 0, i64 0
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %2, i8* %3, i64 7, i1 false)
  %4 = getelementptr inbounds %struct.foo, %struct.foo* %foobie, i64 0, i32 2
  store i32 20, i32* %4, align 4
  ret i32 undef
}

; Check that the memcpy is removed.
define void @test2(i8* sret(i8) noalias nocapture %out, i8* %in) nounwind noinline ssp uwtable {
; CHECK-LABEL: @test2(
; CHECK-NEXT:    call void @llvm.lifetime.start.p0i8(i64 8, i8* [[IN:%.*]])
; CHECK-NEXT:    ret void
;
  call void @llvm.lifetime.start.p0i8(i64 8, i8* %in)
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %out, i8* %in, i64 8, i1 false)
  ret void
}

; Check that the memcpy is not removed.
define void @test3(i8* sret(i8) noalias nocapture %out, i8* %in) nounwind noinline ssp uwtable {
; CHECK-LABEL: @test3(
; CHECK-NEXT:    call void @llvm.lifetime.start.p0i8(i64 4, i8* [[IN:%.*]])
; CHECK-NEXT:    call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[OUT:%.*]], i8* [[IN]], i64 8, i1 false)
; CHECK-NEXT:    ret void
;
  call void @llvm.lifetime.start.p0i8(i64 4, i8* %in)
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %out, i8* %in, i64 8, i1 false)
  ret void
}

; Check that the memcpy is not removed.
define void @test_lifetime_may_alias(i8* %lifetime, i8* %src, i8* %dst) {
; CHECK-LABEL: @test_lifetime_may_alias(
; CHECK-NEXT:    call void @llvm.lifetime.start.p0i8(i64 8, i8* [[LIFETIME:%.*]])
; CHECK-NEXT:    call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[DST:%.*]], i8* [[SRC:%.*]], i64 8, i1 false)
; CHECK-NEXT:    ret void
;
  call void @llvm.lifetime.start.p0i8(i64 8, i8* %lifetime)
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 8, i1 false)
  ret void
}

; lifetime.start on full alloca size, copy in range.
define void @test_lifetime_partial_alias_1(i8* noalias %dst) {
; CHECK-LABEL: @test_lifetime_partial_alias_1(
; CHECK-NEXT:    [[A:%.*]] = alloca [16 x i8], align 1
; CHECK-NEXT:    [[A_I8:%.*]] = bitcast [16 x i8]* [[A]] to i8*
; CHECK-NEXT:    call void @llvm.lifetime.start.p0i8(i64 16, i8* [[A_I8]])
; CHECK-NEXT:    [[GEP:%.*]] = getelementptr i8, i8* [[A_I8]], i64 8
; CHECK-NEXT:    ret void
;
  %a = alloca [16 x i8]
  %a.i8 = bitcast [16 x i8]* %a to i8*
  call void @llvm.lifetime.start.p0i8(i64 16, i8* %a.i8)
  %gep = getelementptr i8, i8* %a.i8, i64 8
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %gep, i64 8, i1 false)
  ret void
}

; lifetime.start on full alloca size, copy out of range.
define void @test_lifetime_partial_alias_2(i8* noalias %dst) {
; CHECK-LABEL: @test_lifetime_partial_alias_2(
; CHECK-NEXT:    [[A:%.*]] = alloca [16 x i8], align 1
; CHECK-NEXT:    [[A_I8:%.*]] = bitcast [16 x i8]* [[A]] to i8*
; CHECK-NEXT:    call void @llvm.lifetime.start.p0i8(i64 16, i8* [[A_I8]])
; CHECK-NEXT:    [[GEP:%.*]] = getelementptr i8, i8* [[A_I8]], i64 8
; CHECK-NEXT:    ret void
;
  %a = alloca [16 x i8]
  %a.i8 = bitcast [16 x i8]* %a to i8*
  call void @llvm.lifetime.start.p0i8(i64 16, i8* %a.i8)
  %gep = getelementptr i8, i8* %a.i8, i64 8
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %gep, i64 16, i1 false)
  ret void
}

; lifetime.start on part of alloca, copy in range.
define void @test_lifetime_partial_alias_3(i8* noalias %dst) {
; CHECK-LABEL: @test_lifetime_partial_alias_3(
; CHECK-NEXT:    [[A:%.*]] = alloca [16 x i8], align 1
; CHECK-NEXT:    [[A_I8:%.*]] = bitcast [16 x i8]* [[A]] to i8*
; CHECK-NEXT:    call void @llvm.lifetime.start.p0i8(i64 12, i8* [[A_I8]])
; CHECK-NEXT:    [[GEP:%.*]] = getelementptr i8, i8* [[A_I8]], i64 8
; CHECK-NEXT:    call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[DST:%.*]], i8* [[GEP]], i64 4, i1 false)
; CHECK-NEXT:    ret void
;
  %a = alloca [16 x i8]
  %a.i8 = bitcast [16 x i8]* %a to i8*
  call void @llvm.lifetime.start.p0i8(i64 12, i8* %a.i8)
  %gep = getelementptr i8, i8* %a.i8, i64 8
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %gep, i64 4, i1 false)
  ret void
}

; lifetime.start on part of alloca, copy out of range.
define void @test_lifetime_partial_alias_4(i8* noalias %dst) {
; CHECK-LABEL: @test_lifetime_partial_alias_4(
; CHECK-NEXT:    [[A:%.*]] = alloca [16 x i8], align 1
; CHECK-NEXT:    [[A_I8:%.*]] = bitcast [16 x i8]* [[A]] to i8*
; CHECK-NEXT:    call void @llvm.lifetime.start.p0i8(i64 12, i8* [[A_I8]])
; CHECK-NEXT:    [[GEP:%.*]] = getelementptr i8, i8* [[A_I8]], i64 8
; CHECK-NEXT:    call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[DST:%.*]], i8* [[GEP]], i64 8, i1 false)
; CHECK-NEXT:    ret void
;
  %a = alloca [16 x i8]
  %a.i8 = bitcast [16 x i8]* %a to i8*
  call void @llvm.lifetime.start.p0i8(i64 12, i8* %a.i8)
  %gep = getelementptr i8, i8* %a.i8, i64 8
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %gep, i64 8, i1 false)
  ret void
}

declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind

declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) nounwind