diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -501,6 +501,10 @@ Constant *FoldReinterpretLoadFromConstPtr(Constant *C, Type *LoadTy, const DataLayout &DL) { + // Bail out early. Not expect to load from scalable global variable. + if (LoadTy->isVectorTy() && LoadTy->getVectorIsScalable()) + return nullptr; + auto *PTy = cast(C->getType()); auto *IntType = dyn_cast(LoadTy); @@ -520,8 +524,8 @@ else if (LoadTy->isDoubleTy()) MapTy = Type::getInt64Ty(C->getContext()); else if (LoadTy->isVectorTy()) { - MapTy = PointerType::getIntNTy(C->getContext(), - DL.getTypeSizeInBits(LoadTy)); + MapTy = PointerType::getIntNTy( + C->getContext(), DL.getTypeSizeInBits(LoadTy).getFixedSize()); } else return nullptr; @@ -561,7 +565,8 @@ return nullptr; int64_t Offset = OffsetAI.getSExtValue(); - int64_t InitializerSize = DL.getTypeAllocSize(GV->getInitializer()->getType()); + int64_t InitializerSize = + DL.getTypeAllocSize(GV->getInitializer()->getType()).getFixedSize(); // If we're not accessing anything in this constant, the result is undefined. if (Offset <= -1 * static_cast(BytesLoaded)) diff --git a/llvm/test/Analysis/ConstantFolding/vscale.ll b/llvm/test/Analysis/ConstantFolding/vscale.ll --- a/llvm/test/Analysis/ConstantFolding/vscale.ll +++ b/llvm/test/Analysis/ConstantFolding/vscale.ll @@ -185,6 +185,20 @@ %i2 = shufflevector %i, undef, zeroinitializer ret %i2 } + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Memory Access and Addressing Operations +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +define @load() { +; CHECK-LABEL: @load( +; CHECK-NEXT: [[R:%.*]] = load , * getelementptr (, * null, i64 1) +; CHECK-NEXT: ret [[R]] +; + %r = load , * getelementptr (, * null, i64 1) + ret %r +} + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Conversion Operations ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;