Skip to content

Commit a91131f

Browse files
authored
Merge pull request #39315 from JuliaLang/tb/legal_alloc_opt
Only create legal int types during alloc opt
2 parents e8f23d7 + 543ac5f commit a91131f

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

src/llvm-alloc-opt.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,12 @@ void Optimizer::moveToStack(CallInst *orig_inst, size_t sz, bool has_ref)
936936
ptr = cast<Instruction>(prolog_builder.CreateBitCast(buff, pass.T_pint8));
937937
}
938938
else {
939-
buff = prolog_builder.CreateAlloca(Type::getIntNTy(pass.getLLVMContext(), sz * 8));
939+
Type *buffty;
940+
if (pass.DL->isLegalInteger(sz * 8))
941+
buffty = Type::getIntNTy(pass.getLLVMContext(), sz * 8);
942+
else
943+
buffty = ArrayType::get(Type::getInt8Ty(pass.getLLVMContext()), sz);
944+
buff = prolog_builder.CreateAlloca(buffty);
940945
buff->setAlignment(Align(align));
941946
ptr = cast<Instruction>(prolog_builder.CreateBitCast(buff, pass.T_pint8));
942947
}
@@ -1193,8 +1198,10 @@ void Optimizer::splitOnStack(CallInst *orig_inst)
11931198
else if (field.elty && !field.multiloc) {
11941199
allocty = field.elty;
11951200
}
1196-
else {
1201+
else if (pass.DL->isLegalInteger(field.size * 8)) {
11971202
allocty = Type::getIntNTy(pass.getLLVMContext(), field.size * 8);
1203+
} else {
1204+
allocty = ArrayType::get(Type::getInt8Ty(pass.getLLVMContext()), field.size);
11981205
}
11991206
slot.slot = prolog_builder.CreateAlloca(allocty);
12001207
insertLifetime(prolog_builder.CreateBitCast(slot.slot, pass.T_pint8),

test/llvmpasses/alloc-opt.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
isz = sizeof(UInt) == 8 ? "i64" : "i32"
66

77
println("""
8+
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
9+
810
@tag = external addrspace(10) global {}
911
""")
1012

@@ -167,7 +169,7 @@ define void @object_field({} addrspace(10)* %field) {
167169
# CHECK-LABEL: }{{$}}
168170

169171
# CHECK-LABEL: @memcpy_opt
170-
# CHECK: alloca i128, align 16
172+
# CHECK: alloca [16 x i8], align 16
171173
# CHECK: call {}*** @julia.ptls_states()
172174
# CHECK-NOT: @julia.gc_alloc_obj
173175
# CHECK-NOT: @jl_gc_pool_alloc

test/llvmpasses/alloc-opt2.jl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,30 @@ L3:
7979
""")
8080
# CHECK-LABEL: }{{$}}
8181

82+
# CHECK-LABEL: @legal_int_types
83+
# CHECK: alloca [12 x i8]
84+
# CHECK-NOT: alloca i96
85+
# CHECK: ret void
86+
println("""
87+
define void @legal_int_types() {
88+
%ptls = call {}*** @julia.ptls_states()
89+
%ptls_i8 = bitcast {}*** %ptls to i8*
90+
%var1 = call {} addrspace(10)* @julia.gc_alloc_obj(i8* %ptls_i8, $isz 12, {} addrspace(10)* @tag)
91+
%var2 = addrspacecast {} addrspace(10)* %var1 to {} addrspace(11)*
92+
%var3 = call {}* @julia.pointer_from_objref({} addrspace(11)* %var2)
93+
ret void
94+
}
95+
""")
96+
# CHECK-LABEL: }{{$}}
97+
98+
99+
82100
println("""
83101
declare void @external_function()
84102
declare {} addrspace(10)* @external_function2()
85103
declare {}*** @julia.ptls_states()
86104
declare noalias {} addrspace(10)* @julia.gc_alloc_obj(i8*, $isz, {} addrspace(10)*)
87-
declare i64 @julia.pointer_from_objref({} addrspace(11)*)
105+
declare {}* @julia.pointer_from_objref({} addrspace(11)*)
88106
declare void @llvm.memcpy.p11i8.p0i8.i64(i8 addrspace(11)* nocapture writeonly, i8* nocapture readonly, i64, i32, i1)
89107
declare token @llvm.julia.gc_preserve_begin(...)
90108
declare void @llvm.julia.gc_preserve_end(token)

0 commit comments

Comments
 (0)