From: Christopher Tetreault Date: Tue, 16 Jun 2020 20:19:15 +0000 (-0700) Subject: [NFC] Bail out for scalable vectors before calling getNumElements X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b265cad93e70815cfad5eaaacfb095276a9a4213;p=platform%2Fupstream%2Fllvm.git [NFC] Bail out for scalable vectors before calling getNumElements Summary: Move the bail out logic to before constructing the Result and Lane vectors. This is both potentially faster, and avoids calling getNumElements on a potentially scalable vector Reviewers: efriedma, sunfish, chandlerc, c-rhodes, fpetrogalli Reviewed By: fpetrogalli Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D81619 --- diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 67591de..76e7b29 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -2689,24 +2689,26 @@ static Constant *ConstantFoldVectorCall(StringRef Name, const DataLayout &DL, const TargetLibraryInfo *TLI, const CallBase *Call) { - SmallVector Result(VTy->getNumElements()); - SmallVector Lane(Operands.size()); - Type *Ty = VTy->getElementType(); - // Do not iterate on scalable vector. The number of elements is unknown at // compile-time. if (isa(VTy)) return nullptr; + auto *FVTy = cast(VTy); + + SmallVector Result(FVTy->getNumElements()); + SmallVector Lane(Operands.size()); + Type *Ty = FVTy->getElementType(); + if (IntrinsicID == Intrinsic::masked_load) { auto *SrcPtr = Operands[0]; auto *Mask = Operands[2]; auto *Passthru = Operands[3]; - Constant *VecData = ConstantFoldLoadFromConstPtr(SrcPtr, VTy, DL); + Constant *VecData = ConstantFoldLoadFromConstPtr(SrcPtr, FVTy, DL); SmallVector NewElements; - for (unsigned I = 0, E = VTy->getNumElements(); I != E; ++I) { + for (unsigned I = 0, E = FVTy->getNumElements(); I != E; ++I) { auto *MaskElt = Mask->getAggregateElement(I); if (!MaskElt) break; @@ -2732,12 +2734,12 @@ static Constant *ConstantFoldVectorCall(StringRef Name, return nullptr; } } - if (NewElements.size() != VTy->getNumElements()) + if (NewElements.size() != FVTy->getNumElements()) return nullptr; return ConstantVector::get(NewElements); } - for (unsigned I = 0, E = VTy->getNumElements(); I != E; ++I) { + for (unsigned I = 0, E = FVTy->getNumElements(); I != E; ++I) { // Gather a column of constants. for (unsigned J = 0, JE = Operands.size(); J != JE; ++J) { // Some intrinsics use a scalar type for certain arguments.