Skip to content

Commit 182b535

Browse files
committed
julia fix
1 parent c81564c commit 182b535

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,19 +1482,23 @@ LLVM_DUMP_METHOD void AllocaSlices::dump() const { print(dbgs()); }
14821482

14831483
/// Walk the range of a partitioning looking for a common type to cover this
14841484
/// sequence of slices.
1485-
static std::pair<Type *, IntegerType *>
1485+
/// Returns: {CommonType, LargestIntegerType, OnlyIntrinsicUsers}
1486+
static std::tuple<Type *, IntegerType *, bool>
14861487
findCommonType(AllocaSlices::const_iterator B, AllocaSlices::const_iterator E,
14871488
uint64_t EndOffset) {
14881489
Type *Ty = nullptr;
14891490
bool TyIsCommon = true;
14901491
IntegerType *ITy = nullptr;
1492+
bool OnlyIntrinsicUsers = true;
14911493

14921494
// Note that we need to look at *every* alloca slice's Use to ensure we
14931495
// always get consistent results regardless of the order of slices.
14941496
for (AllocaSlices::const_iterator I = B; I != E; ++I) {
14951497
Use *U = I->getUse();
14961498
if (isa<IntrinsicInst>(*U->getUser()))
14971499
continue;
1500+
// We found a non-intrinsic user
1501+
OnlyIntrinsicUsers = false;
14981502
if (I->beginOffset() != B->beginOffset() || I->endOffset() != EndOffset)
14991503
continue;
15001504

@@ -1528,7 +1532,7 @@ findCommonType(AllocaSlices::const_iterator B, AllocaSlices::const_iterator E,
15281532
Ty = UserTy;
15291533
}
15301534

1531-
return {TyIsCommon ? Ty : nullptr, ITy};
1535+
return {TyIsCommon ? Ty : nullptr, ITy, OnlyIntrinsicUsers};
15321536
}
15331537

15341538
/// PHI instructions that use an alloca and are subsequently loaded can be
@@ -5206,20 +5210,24 @@ AllocaInst *SROA::rewritePartition(AllocaInst &AI, AllocaSlices &AS,
52065210

52075211
// Otherwise, check if there is a common type that all slices of the
52085212
// partition use. Collect the largest integer type used as a backup.
5209-
auto CommonUseTy = findCommonType(P.begin(), P.end(), P.endOffset());
5213+
auto [CommonUseTy, LargestIntTy, OnlyIntrinsicUsers] =
5214+
findCommonType(P.begin(), P.end(), P.endOffset());
52105215
// If there is a common type that spans the partition, use it.
5211-
if (CommonUseTy.first) {
5212-
TypeSize CommonUseSize = DL.getTypeAllocSize(CommonUseTy.first);
5216+
if (CommonUseTy) {
5217+
TypeSize CommonUseSize = DL.getTypeAllocSize(CommonUseTy);
52135218
if (CommonUseSize.isFixed() &&
52145219
CommonUseSize.getFixedValue() >= P.size()) {
52155220

52165221
if (VecTy)
52175222
return {VecTy, false, VecTy};
5218-
return {CommonUseTy.first,
5219-
isIntegerWideningViable(P, CommonUseTy.first, DL), nullptr};
5223+
return {CommonUseTy, isIntegerWideningViable(P, CommonUseTy, DL),
5224+
nullptr};
52205225
}
52215226
}
52225227

5228+
if (OnlyIntrinsicUsers && DL.isLegalInteger(P.size() * 8))
5229+
return {Type::getIntNTy(*C, P.size() * 8), false, nullptr};
5230+
52235231
// If not, can we find an appropriate subtype in the original allocated
52245232
// type?
52255233
if (Type *TypePartitionTy = getTypePartition(DL, AI.getAllocatedType(),
@@ -5233,17 +5241,17 @@ AllocaInst *SROA::rewritePartition(AllocaInst &AI, AllocaSlices &AS,
52335241
return {TypePartitionTy, true, nullptr};
52345242
if (VecTy)
52355243
return {VecTy, false, VecTy};
5236-
if (CommonUseTy.second &&
5237-
DL.getTypeAllocSize(CommonUseTy.second).getFixedValue() >= P.size() &&
5238-
isIntegerWideningViable(P, CommonUseTy.second, DL))
5239-
return {CommonUseTy.second, true, nullptr};
5244+
if (LargestIntTy &&
5245+
DL.getTypeAllocSize(LargestIntTy).getFixedValue() >= P.size() &&
5246+
isIntegerWideningViable(P, LargestIntTy, DL))
5247+
return {LargestIntTy, true, nullptr};
52405248
return {TypePartitionTy, false, nullptr};
52415249
}
52425250

52435251
// If still not, can we use the largest bitwidth integer type used?
5244-
if (CommonUseTy.second &&
5245-
DL.getTypeAllocSize(CommonUseTy.second).getFixedValue() >= P.size())
5246-
return {CommonUseTy.second, false, nullptr};
5252+
if (LargestIntTy &&
5253+
DL.getTypeAllocSize(LargestIntTy).getFixedValue() >= P.size())
5254+
return {LargestIntTy, false, nullptr};
52475255

52485256
if (DL.isLegalInteger(P.size() * 8))
52495257
return {Type::getIntNTy(*C, P.size() * 8), false, nullptr};

llvm/test/Transforms/SROA/basictest.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ define i64 @test19(ptr %x) {
785785
; CHECK-NEXT: entry:
786786
; CHECK-NEXT: [[A_SROA_0_0_COPYLOAD:%.*]] = load i64, ptr [[X:%.*]], align 1
787787
; CHECK-NEXT: [[A_SROA_2_0_X_SROA_IDX:%.*]] = getelementptr inbounds i8, ptr [[X]], i64 8
788-
; CHECK-NEXT: [[A_SROA_2_0_COPYLOAD:%.*]] = load ptr, ptr [[A_SROA_2_0_X_SROA_IDX]], align 1
788+
; CHECK-NEXT: [[A_SROA_2_0_COPYLOAD:%.*]] = load i64, ptr [[A_SROA_2_0_X_SROA_IDX]], align 1
789789
; CHECK-NEXT: ret i64 [[A_SROA_0_0_COPYLOAD]]
790790
;
791791
entry:
@@ -809,7 +809,7 @@ define i64 @test19_addrspacecast(ptr %x) {
809809
; CHECK-NEXT: [[CAST1:%.*]] = addrspacecast ptr [[X:%.*]] to ptr addrspace(1)
810810
; CHECK-NEXT: [[A_SROA_0_0_COPYLOAD:%.*]] = load i64, ptr addrspace(1) [[CAST1]], align 1
811811
; CHECK-NEXT: [[A_SROA_2_0_CAST1_SROA_IDX:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[CAST1]], i16 8
812-
; CHECK-NEXT: [[A_SROA_2_0_COPYLOAD:%.*]] = load ptr, ptr addrspace(1) [[A_SROA_2_0_CAST1_SROA_IDX]], align 1
812+
; CHECK-NEXT: [[A_SROA_2_0_COPYLOAD:%.*]] = load i64, ptr addrspace(1) [[A_SROA_2_0_CAST1_SROA_IDX]], align 1
813813
; CHECK-NEXT: ret i64 [[A_SROA_0_0_COPYLOAD]]
814814
;
815815
entry:
@@ -1332,10 +1332,10 @@ define void @PR15674(ptr %data, ptr %src, i32 %size) {
13321332
; CHECK-NEXT: entry:
13331333
; CHECK-NEXT: [[TMP_SROA_0:%.*]] = alloca i32, align 4
13341334
; CHECK-NEXT: switch i32 [[SIZE:%.*]], label [[END:%.*]] [
1335-
; CHECK-NEXT: i32 4, label [[BB4:%.*]]
1336-
; CHECK-NEXT: i32 3, label [[BB3:%.*]]
1337-
; CHECK-NEXT: i32 2, label [[BB2:%.*]]
1338-
; CHECK-NEXT: i32 1, label [[BB1:%.*]]
1335+
; CHECK-NEXT: i32 4, label [[BB4:%.*]]
1336+
; CHECK-NEXT: i32 3, label [[BB3:%.*]]
1337+
; CHECK-NEXT: i32 2, label [[BB2:%.*]]
1338+
; CHECK-NEXT: i32 1, label [[BB1:%.*]]
13391339
; CHECK-NEXT: ]
13401340
; CHECK: bb4:
13411341
; CHECK-NEXT: [[SRC_GEP3:%.*]] = getelementptr inbounds i8, ptr [[SRC:%.*]], i32 3

0 commit comments

Comments
 (0)