From 2adae8e1b7dfda5eb7b9a44793dd84a036a9cd15 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 19 Sep 2022 18:09:39 -0400 Subject: [PATCH] VectorCombine: Pass through AssumptionCache --- llvm/include/llvm/Analysis/Loads.h | 2 ++ llvm/lib/Analysis/Loads.cpp | 9 ++++++--- llvm/lib/Transforms/Vectorize/VectorCombine.cpp | 6 ++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/llvm/include/llvm/Analysis/Loads.h b/llvm/include/llvm/Analysis/Loads.h index 5ea51c2487c8..2880ed33a34c 100644 --- a/llvm/include/llvm/Analysis/Loads.h +++ b/llvm/include/llvm/Analysis/Loads.h @@ -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); diff --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp index 5a693c27bc42..f2fa9e06ea84 100644 --- a/llvm/lib/Analysis/Loads.cpp +++ b/llvm/lib/Analysis/Loads.cpp @@ -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 diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp index 1f5f83816b72..8a2eaafacf49 100644 --- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -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