Skip to content

Commit 7f1dcc8

Browse files
committed
[InstCombine] Skip scalable vectors in combineLoadToOperationType
Don't try to canonicalize loads to scalable vector types to loads of integers. This removes one assertion when trying to use a TypeSize as a parameter to DataLayout::isLegalInteger. It does not handle the second part of the function (which looks at bitcasts). This patch also contains a NFC fix for Load Analysis, where a variable initialization that would cause the same assertion is moved closer to its use. This allows us to run the new test for InstCombine without having to teach LocationSize to play nicely with scalable vectors. Differential Revision: https://reviews.llvm.org/D70075
1 parent 8794f67 commit 7f1dcc8

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

llvm/lib/Analysis/Loads.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,6 @@ Value *llvm::FindAvailablePtrLoadStore(Value *Ptr, Type *AccessTy,
383383
MaxInstsToScan = ~0U;
384384

385385
const DataLayout &DL = ScanBB->getModule()->getDataLayout();
386-
387-
// Try to get the store size for the type.
388-
auto AccessSize = LocationSize::precise(DL.getTypeStoreSize(AccessTy));
389-
390386
Value *StrippedPtr = Ptr->stripPointerCasts();
391387

392388
while (ScanFrom != ScanBB->begin()) {
@@ -425,6 +421,9 @@ Value *llvm::FindAvailablePtrLoadStore(Value *Ptr, Type *AccessTy,
425421
return LI;
426422
}
427423

424+
// Try to get the store size for the type.
425+
auto AccessSize = LocationSize::precise(DL.getTypeStoreSize(AccessTy));
426+
428427
if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
429428
Value *StorePtr = SI->getPointerOperand()->stripPointerCasts();
430429
// If this is a store through Ptr, the value is available!

llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ static Instruction *combineLoadToOperationType(InstCombiner &IC, LoadInst &LI) {
586586
// Do not perform canonicalization if minmax pattern is found (to avoid
587587
// infinite loop).
588588
if (!Ty->isIntegerTy() && Ty->isSized() &&
589+
!(Ty->isVectorTy() && Ty->getVectorIsScalable()) &&
589590
DL.isLegalInteger(DL.getTypeStoreSizeInBits(Ty)) &&
590591
DL.typeSizeEqualsStoreSize(Ty) &&
591592
!DL.isNonIntegralPointerType(Ty) &&

llvm/test/Transforms/InstCombine/load.ll

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,42 @@ entry:
237237
ret void
238238
}
239239

240+
define void @test16-vect(i8* %x, i8* %a, i8* %b, i8* %c) {
241+
; CHECK-LABEL: @test16-vect(
242+
; CHECK-NEXT: entry:
243+
; CHECK-NEXT: [[C_CAST:%.*]] = bitcast i8* [[C:%.*]] to i32*
244+
; CHECK-NEXT: [[TMP0:%.*]] = bitcast i8* [[X:%.*]] to i32*
245+
; CHECK-NEXT: [[X11:%.*]] = load i32, i32* [[TMP0]], align 4
246+
; CHECK-NEXT: [[TMP1:%.*]] = bitcast i8* [[A:%.*]] to i32*
247+
; CHECK-NEXT: store i32 [[X11]], i32* [[TMP1]], align 4
248+
; CHECK-NEXT: [[TMP2:%.*]] = bitcast i8* [[B:%.*]] to i32*
249+
; CHECK-NEXT: store i32 [[X11]], i32* [[TMP2]], align 4
250+
; CHECK-NEXT: [[TMP3:%.*]] = bitcast i8* [[X]] to i32*
251+
; CHECK-NEXT: [[X22:%.*]] = load i32, i32* [[TMP3]], align 4
252+
; CHECK-NEXT: [[TMP4:%.*]] = bitcast i8* [[B]] to i32*
253+
; CHECK-NEXT: store i32 [[X22]], i32* [[TMP4]], align 4
254+
; CHECK-NEXT: store i32 [[X22]], i32* [[C_CAST]], align 4
255+
; CHECK-NEXT: ret void
256+
;
257+
entry:
258+
%x.cast = bitcast i8* %x to <4 x i8>*
259+
%a.cast = bitcast i8* %a to <4 x i8>*
260+
%b.cast = bitcast i8* %b to <4 x i8>*
261+
%c.cast = bitcast i8* %c to i32*
262+
263+
%x1 = load <4 x i8>, <4 x i8>* %x.cast
264+
store <4 x i8> %x1, <4 x i8>* %a.cast
265+
store <4 x i8> %x1, <4 x i8>* %b.cast
266+
267+
%x2 = load <4 x i8>, <4 x i8>* %x.cast
268+
store <4 x i8> %x2, <4 x i8>* %b.cast
269+
%x2.cast = bitcast <4 x i8> %x2 to i32
270+
store i32 %x2.cast, i32* %c.cast
271+
272+
ret void
273+
}
274+
275+
240276
; Check that in cases similar to @test16 we don't try to rewrite a load when
241277
; its only use is a store but it is used as the pointer to that store rather
242278
; than the value.
@@ -300,3 +336,15 @@ entry:
300336
store %swift.error* %err.res, %swift.error** %err, align 8
301337
ret void
302338
}
339+
340+
; Make sure we don't canonicalize accesses to scalable vectors.
341+
define void @test20(<vscale x 4 x i8>* %x, <vscale x 4 x i8>* %y) {
342+
; CHECK-LABEL: @test20(
343+
; CHECK-NEXT: [[X_LOAD:%.*]] = load <vscale x 4 x i8>, <vscale x 4 x i8>* [[X:%.*]], align 1
344+
; CHECK-NEXT: store <vscale x 4 x i8> [[X_LOAD]], <vscale x 4 x i8>* [[Y:%.*]], align 1
345+
; CHECK-NEXT: ret void
346+
;
347+
%x.load = load <vscale x 4 x i8>, <vscale x 4 x i8>* %x, align 1
348+
store <vscale x 4 x i8> %x.load, <vscale x 4 x i8>* %y, align 1
349+
ret void
350+
}

0 commit comments

Comments
 (0)