VectorCombine: Pass through AssumptionCache

This commit is contained in:
Matt Arsenault 2022-09-19 18:09:39 -04:00
parent c867401407
commit 2adae8e1b7
3 changed files with 12 additions and 5 deletions

View File

@ -71,6 +71,7 @@ bool isDereferenceableAndAlignedPointer(const Value *V, Align Alignment,
bool isSafeToLoadUnconditionally(Value *V, Align Alignment, APInt &Size,
const DataLayout &DL,
Instruction *ScanFrom = nullptr,
AssumptionCache *AC = nullptr,
const DominatorTree *DT = nullptr,
const TargetLibraryInfo *TLI = nullptr);
@ -96,6 +97,7 @@ bool isDereferenceableAndAlignedInLoop(LoadInst *LI, Loop *L,
bool isSafeToLoadUnconditionally(Value *V, Type *Ty, Align Alignment,
const DataLayout &DL,
Instruction *ScanFrom = nullptr,
AssumptionCache *AC = nullptr,
const DominatorTree *DT = nullptr,
const TargetLibraryInfo *TLI = nullptr);

View File

@ -327,12 +327,13 @@ bool llvm::isDereferenceableAndAlignedInLoop(LoadInst *LI, Loop *L,
bool llvm::isSafeToLoadUnconditionally(Value *V, Align Alignment, APInt &Size,
const DataLayout &DL,
Instruction *ScanFrom,
AssumptionCache *AC,
const DominatorTree *DT,
const TargetLibraryInfo *TLI) {
// If DT is not specified we can't make context-sensitive query
const Instruction* CtxI = DT ? ScanFrom : nullptr;
if (isDereferenceableAndAlignedPointer(V, Alignment, Size, DL, CtxI, nullptr,
DT, TLI))
if (isDereferenceableAndAlignedPointer(V, Alignment, Size, DL, CtxI, AC, DT,
TLI))
return true;
if (!ScanFrom)
@ -403,13 +404,15 @@ bool llvm::isSafeToLoadUnconditionally(Value *V, Align Alignment, APInt &Size,
bool llvm::isSafeToLoadUnconditionally(Value *V, Type *Ty, Align Alignment,
const DataLayout &DL,
Instruction *ScanFrom,
AssumptionCache *AC,
const DominatorTree *DT,
const TargetLibraryInfo *TLI) {
TypeSize TySize = DL.getTypeStoreSize(Ty);
if (TySize.isScalable())
return false;
APInt Size(DL.getIndexTypeSizeInBits(V->getType()), TySize.getFixedValue());
return isSafeToLoadUnconditionally(V, Alignment, Size, DL, ScanFrom, DT, TLI);
return isSafeToLoadUnconditionally(V, Alignment, Size, DL, ScanFrom, AC, DT,
TLI);
}
/// DefMaxInstsToScan - the default number of maximum instructions

View File

@ -173,7 +173,8 @@ bool VectorCombine::vectorizeLoadInsert(Instruction &I) {
auto *MinVecTy = VectorType::get(ScalarTy, MinVecNumElts, false);
unsigned OffsetEltIndex = 0;
Align Alignment = Load->getAlign();
if (!isSafeToLoadUnconditionally(SrcPtr, MinVecTy, Align(1), DL, Load, &DT)) {
if (!isSafeToLoadUnconditionally(SrcPtr, MinVecTy, Align(1), DL, Load, &AC,
&DT)) {
// It is not safe to load directly from the pointer, but we can still peek
// through gep offsets and check if it safe to load from a base address with
// updated alignment. If it is, we can shuffle the element(s) into place
@ -198,7 +199,8 @@ bool VectorCombine::vectorizeLoadInsert(Instruction &I) {
if (OffsetEltIndex >= MinVecNumElts)
return false;
if (!isSafeToLoadUnconditionally(SrcPtr, MinVecTy, Align(1), DL, Load, &DT))
if (!isSafeToLoadUnconditionally(SrcPtr, MinVecTy, Align(1), DL, Load, &AC,
&DT))
return false;
// Update alignment with offset value. Note that the offset could be negated