Skip to content

Commit 31d5126

Browse files
committed
[SROA]: Only defer trying partial sized ptr or ptr vector types
Change-Id: Ic77f87290905addadd5819dff2d0c62f031022ab
1 parent 5ea3531 commit 31d5126

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,6 +2271,7 @@ static VectorType *isVectorPromotionViable(Partition &P, const DataLayout &DL) {
22712271
// we have different element types.
22722272
SmallVector<VectorType *, 4> CandidateTys;
22732273
SetVector<Type *> LoadStoreTys;
2274+
SetVector<Type *> DeferredTys;
22742275
Type *CommonEltTy = nullptr;
22752276
VectorType *CommonVecPtrTy = nullptr;
22762277
bool HaveVecPtrTy = false;
@@ -2342,20 +2343,28 @@ static VectorType *isVectorPromotionViable(Partition &P, const DataLayout &DL) {
23422343
Ty = SI->getValueOperand()->getType();
23432344
else
23442345
continue;
2346+
2347+
auto CandTy =
2348+
isa<VectorType>(Ty) ? cast<VectorType>(Ty)->getElementType() : Ty;
2349+
if (CandTy->isPointerTy() && (S.beginOffset() != P.beginOffset() ||
2350+
S.endOffset() != P.endOffset())) {
2351+
DeferredTys.insert(Ty);
2352+
continue;
2353+
}
2354+
23452355
LoadStoreTys.insert(Ty);
23462356
// Consider any loads or stores that are the exact size of the slice.
23472357
if (S.beginOffset() == P.beginOffset() && S.endOffset() == P.endOffset())
23482358
CheckCandidateType(Ty);
23492359
}
23502360

2351-
if (auto *VTy = checkVectorTypesForPromotion(
2352-
P, DL, CandidateTys, HaveCommonEltTy, CommonEltTy, HaveVecPtrTy,
2353-
HaveCommonVecPtrTy, CommonVecPtrTy))
2361+
SmallVector<VectorType *, 4> CandidateTysCopy = CandidateTys;
2362+
if (auto *VTy =
2363+
createAndCheckVectorTypesForPromotion(LoadStoreTys, CandidateTysCopy))
23542364
return VTy;
23552365

2356-
SmallVector<VectorType *, 4> CandidateTysCopy = CandidateTys;
23572366
CandidateTys.clear();
2358-
return createAndCheckVectorTypesForPromotion(LoadStoreTys, CandidateTysCopy);
2367+
return createAndCheckVectorTypesForPromotion(DeferredTys, CandidateTysCopy);
23592368
}
23602369

23612370
/// Test whether a slice of an alloca is valid for integer widening.

llvm/test/Transforms/SROA/vector-promotion.ll

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,38 @@ define <4 x ptr> @ptrLoadStoreTysPtr(ptr %init, i64 %val2) {
13921392
ret <4 x ptr> %sroaval
13931393
}
13941394

1395+
define <4 x i32> @validLoadStoreTy([2 x i64] %cond.coerce) {
1396+
; CHECK-LABEL: @validLoadStoreTy(
1397+
; CHECK-NEXT: entry:
1398+
; CHECK-NEXT: [[COND_COERCE_FCA_0_EXTRACT:%.*]] = extractvalue [2 x i64] [[COND_COERCE:%.*]], 0
1399+
; CHECK-NEXT: [[COND_SROA_0_0_VEC_INSERT:%.*]] = insertelement <2 x i64> undef, i64 [[COND_COERCE_FCA_0_EXTRACT]], i32 0
1400+
; CHECK-NEXT: [[COND_COERCE_FCA_1_EXTRACT:%.*]] = extractvalue [2 x i64] [[COND_COERCE]], 1
1401+
; CHECK-NEXT: [[COND_SROA_0_8_VEC_INSERT:%.*]] = insertelement <2 x i64> [[COND_SROA_0_0_VEC_INSERT]], i64 [[COND_COERCE_FCA_1_EXTRACT]], i32 1
1402+
; CHECK-NEXT: [[TMP0:%.*]] = bitcast <2 x i64> [[COND_SROA_0_8_VEC_INSERT]] to <4 x i32>
1403+
; CHECK-NEXT: ret <4 x i32> [[TMP0]]
1404+
;
1405+
; DEBUG-LABEL: @validLoadStoreTy(
1406+
; DEBUG-NEXT: entry:
1407+
; DEBUG-NEXT: call void @llvm.dbg.value(metadata ptr undef, metadata [[META553:![0-9]+]], metadata !DIExpression()), !dbg [[DBG557:![0-9]+]]
1408+
; DEBUG-NEXT: call void @llvm.dbg.value(metadata ptr undef, metadata [[META554:![0-9]+]], metadata !DIExpression()), !dbg [[DBG558:![0-9]+]]
1409+
; DEBUG-NEXT: [[COND_COERCE_FCA_0_EXTRACT:%.*]] = extractvalue [2 x i64] [[COND_COERCE:%.*]], 0, !dbg [[DBG559:![0-9]+]]
1410+
; DEBUG-NEXT: [[COND_SROA_0_0_VEC_INSERT:%.*]] = insertelement <2 x i64> undef, i64 [[COND_COERCE_FCA_0_EXTRACT]], i32 0, !dbg [[DBG559]]
1411+
; DEBUG-NEXT: [[COND_COERCE_FCA_1_EXTRACT:%.*]] = extractvalue [2 x i64] [[COND_COERCE]], 1, !dbg [[DBG559]]
1412+
; DEBUG-NEXT: [[COND_SROA_0_8_VEC_INSERT:%.*]] = insertelement <2 x i64> [[COND_SROA_0_0_VEC_INSERT]], i64 [[COND_COERCE_FCA_1_EXTRACT]], i32 1, !dbg [[DBG559]]
1413+
; DEBUG-NEXT: call void @llvm.dbg.value(metadata ptr undef, metadata [[META555:![0-9]+]], metadata !DIExpression()), !dbg [[DBG560:![0-9]+]]
1414+
; DEBUG-NEXT: [[TMP0:%.*]] = bitcast <2 x i64> [[COND_SROA_0_8_VEC_INSERT]] to <4 x i32>, !dbg [[DBG561:![0-9]+]]
1415+
; DEBUG-NEXT: call void @llvm.dbg.value(metadata <4 x i32> [[TMP0]], metadata [[META556:![0-9]+]], metadata !DIExpression()), !dbg [[DBG561]]
1416+
; DEBUG-NEXT: ret <4 x i32> [[TMP0]], !dbg [[DBG562:![0-9]+]]
1417+
;
1418+
entry:
1419+
%cond = alloca <4 x i32>, align 8
1420+
%coerce.dive2 = getelementptr inbounds <4 x i32>, ptr %cond, i32 0, i32 0
1421+
store [2 x i64] %cond.coerce, ptr %coerce.dive2, align 8
1422+
%m5 = getelementptr inbounds <4 x i32>, ptr %cond, i32 0, i32 0
1423+
%0 = load <4 x i32>, ptr %m5, align 8
1424+
ret <4 x i32> %0
1425+
}
1426+
13951427
declare void @llvm.memcpy.p0.p0.i64(ptr, ptr, i64, i1)
13961428
declare void @llvm.lifetime.end.p0(i64, ptr)
13971429
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:

0 commit comments

Comments
 (0)