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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=instcombine -S -data-layout="E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128" | FileCheck %s -check-prefixes=ALL,CHECK
; RUN: opt < %s -passes=instcombine -S -data-layout="E-p:32:32:32-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128" | FileCheck %s -check-prefixes=ALL,P32
; RUN: opt < %s -passes=instcombine -S | FileCheck %s -check-prefixes=ALL,NODL
declare void @use(...)
@int = global i32 zeroinitializer
; Zero byte allocas should be merged if they can't be deleted.
define void @test() {
; CHECK-LABEL: @test(
; CHECK-NEXT: [[X:%.*]] = alloca [0 x i32], align 4
; CHECK-NEXT: call void (...) @use(ptr nonnull [[X]])
; CHECK-NEXT: call void (...) @use(ptr nonnull [[X]])
; CHECK-NEXT: call void (...) @use(ptr nonnull [[X]])
; CHECK-NEXT: call void (...) @use(ptr nonnull [[X]])
; CHECK-NEXT: ret void
;
; P32-LABEL: @test(
; P32-NEXT: [[X:%.*]] = alloca [0 x i32], align 4
; P32-NEXT: call void (...) @use(ptr nonnull [[X]])
; P32-NEXT: call void (...) @use(ptr nonnull [[X]])
; P32-NEXT: call void (...) @use(ptr nonnull [[X]])
; P32-NEXT: call void (...) @use(ptr nonnull [[X]])
; P32-NEXT: ret void
;
; NODL-LABEL: @test(
; NODL-NEXT: [[X:%.*]] = alloca [0 x i32], align 8
; NODL-NEXT: call void (...) @use(ptr nonnull [[X]])
; NODL-NEXT: call void (...) @use(ptr nonnull [[X]])
; NODL-NEXT: call void (...) @use(ptr nonnull [[X]])
; NODL-NEXT: call void (...) @use(ptr nonnull [[X]])
; NODL-NEXT: ret void
;
%X = alloca [0 x i32] ; <ptr> [#uses=1]
call void (...) @use( ptr %X )
%Y = alloca i32, i32 0 ; <ptr> [#uses=1]
call void (...) @use( ptr %Y )
%Z = alloca { } ; <ptr> [#uses=1]
call void (...) @use( ptr %Z )
%size = load i32, ptr @int
%A = alloca {{}}, i32 %size
call void (...) @use( {{}}* %A )
ret void
}
; Zero byte allocas should be deleted.
define void @test2() {
; ALL-LABEL: @test2(
; ALL-NEXT: ret void
;
%A = alloca i32 ; <ptr> [#uses=1]
store i32 123, ptr %A
ret void
}
; Zero byte allocas should be deleted.
define void @test3() {
; ALL-LABEL: @test3(
; ALL-NEXT: ret void
;
%A = alloca { i32 } ; <ptr> [#uses=1]
%B = getelementptr { i32 }, ptr %A, i32 0, i32 0 ; <ptr> [#uses=1]
store i32 123, ptr %B
ret void
}
define ptr @test4(i32 %n) {
; CHECK-LABEL: @test4(
; CHECK-NEXT: [[TMP1:%.*]] = zext i32 [[N:%.*]] to i64
; CHECK-NEXT: [[A:%.*]] = alloca i32, i64 [[TMP1]], align 4
; CHECK-NEXT: ret ptr [[A]]
;
; P32-LABEL: @test4(
; P32-NEXT: [[A:%.*]] = alloca i32, i32 [[N:%.*]], align 4
; P32-NEXT: ret ptr [[A]]
;
; NODL-LABEL: @test4(
; NODL-NEXT: [[TMP1:%.*]] = zext i32 [[N:%.*]] to i64
; NODL-NEXT: [[A:%.*]] = alloca i32, i64 [[TMP1]], align 4
; NODL-NEXT: ret ptr [[A]]
;
%A = alloca i32, i32 %n
ret ptr %A
}
; Allocas which are only used by GEPs, bitcasts, addrspacecasts, and stores
; (transitively) should be deleted.
define void @test5() {
; ALL-LABEL: @test5(
; ALL-NEXT: entry:
; ALL-NEXT: ret void
;
entry:
%a = alloca { i32 }
%b = alloca ptr
%c = alloca i32
store i32 123, ptr %a
store ptr %a, ptr %b
store i32 123, ptr %b
store atomic i32 2, ptr %a unordered, align 4
store atomic i32 3, ptr %a release, align 4
store atomic i32 4, ptr %a seq_cst, align 4
%c.1 = addrspacecast ptr %c to ptr addrspace(1)
store i32 123, ptr addrspace(1) %c.1
ret void
}
declare void @f(ptr %p)
; Check that we don't delete allocas in some erroneous cases.
define void @test6() {
; CHECK-LABEL: @test6(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[A:%.*]] = alloca { i32 }, align 4
; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4
; CHECK-NEXT: store volatile i32 123, ptr [[A]], align 4
; CHECK-NEXT: tail call void @f(ptr nonnull [[B]])
; CHECK-NEXT: ret void
;
; P32-LABEL: @test6(
; P32-NEXT: entry:
; P32-NEXT: [[A:%.*]] = alloca { i32 }, align 4
; P32-NEXT: [[B:%.*]] = alloca i32, align 4
; P32-NEXT: store volatile i32 123, ptr [[A]], align 4
; P32-NEXT: tail call void @f(ptr nonnull [[B]])
; P32-NEXT: ret void
;
; NODL-LABEL: @test6(
; NODL-NEXT: entry:
; NODL-NEXT: [[A:%.*]] = alloca { i32 }, align 8
; NODL-NEXT: [[B:%.*]] = alloca i32, align 4
; NODL-NEXT: store volatile i32 123, ptr [[A]], align 8
; NODL-NEXT: tail call void @f(ptr nonnull [[B]])
; NODL-NEXT: ret void
;
entry:
%a = alloca { i32 }
%b = alloca i32
store volatile i32 123, ptr %a
tail call void @f(ptr %b)
ret void
}
; PR14371
%opaque_type = type opaque
%real_type = type { { i32, ptr } }
@opaque_global = external constant %opaque_type, align 4
define void @test7() {
; ALL-LABEL: @test7(
; ALL-NEXT: entry:
; ALL-NEXT: ret void
;
entry:
%0 = alloca %real_type, align 4
call void @llvm.memcpy.p0.p0.i32(ptr %0, ptr @opaque_global, i32 8, i1 false)
ret void
}
declare void @llvm.memcpy.p0.p0.i32(ptr nocapture, ptr nocapture, i32, i1) nounwind
; Check that the GEP indices use the pointer size, or 64 if unknown
define void @test8() {
; ALL-LABEL: @test8(
; ALL-NEXT: [[X1:%.*]] = alloca [100 x i32], align 4
; ALL-NEXT: call void (...) @use(ptr nonnull [[X1]])
; ALL-NEXT: ret void
;
%x = alloca i32, i32 100
call void (...) @use(ptr %x)
ret void
}
; PR19569
%struct_type = type { i32, i32 }
declare void @test9_aux(ptr inalloca(<{ %struct_type }>))
declare ptr @llvm.stacksave()
declare void @llvm.stackrestore(ptr)
define void @test9(ptr %a) {
; ALL-LABEL: @test9(
; ALL-NEXT: entry:
; ALL-NEXT: [[ARGMEM:%.*]] = alloca inalloca <{ [[STRUCT_TYPE:%.*]] }>, align 8
; ALL-NEXT: [[TMP0:%.*]] = load i64, ptr [[A:%.*]], align 4
; ALL-NEXT: store i64 [[TMP0]], ptr [[ARGMEM]], align 8
; ALL-NEXT: call void @test9_aux(ptr nonnull inalloca(<{ [[STRUCT_TYPE]] }>) [[ARGMEM]])
; ALL-NEXT: ret void
;
entry:
%inalloca.save = call ptr @llvm.stacksave()
%argmem = alloca inalloca <{ %struct_type }>
call void @llvm.memcpy.p0.p0.i32(ptr align 4 %argmem, ptr align 4 %a, i32 8, i1 false)
call void @test9_aux(ptr inalloca(<{ %struct_type }>) %argmem)
call void @llvm.stackrestore(ptr %inalloca.save)
ret void
}
define void @test10() {
; ALL-LABEL: @test10(
; ALL-NEXT: entry:
; ALL-NEXT: [[V32:%.*]] = alloca i1, align 8
; ALL-NEXT: [[V64:%.*]] = alloca i1, align 8
; ALL-NEXT: [[V33:%.*]] = alloca i1, align 8
; ALL-NEXT: call void (...) @use(ptr nonnull [[V32]], ptr nonnull [[V64]], ptr nonnull [[V33]])
; ALL-NEXT: ret void
;
entry:
%v32 = alloca i1, align 8
%v64 = alloca i1, i64 1, align 8
%v33 = alloca i1, i33 1, align 8
call void (...) @use(ptr %v32, ptr %v64, ptr %v33)
ret void
}
define void @test11() {
; ALL-LABEL: @test11(
; ALL-NEXT: entry:
; ALL-NEXT: [[Y:%.*]] = alloca i32, align 4
; ALL-NEXT: call void (...) @use(ptr nonnull @int) [ "blah"(ptr [[Y]]) ]
; ALL-NEXT: ret void
;
entry:
%y = alloca i32
call void (...) @use(ptr nonnull @int) [ "blah"(ptr %y) ]
ret void
}
|