diff --git a/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp b/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp --- a/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp +++ b/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp @@ -285,8 +285,23 @@ } } +static Optional nameOrNone(const Value *V) { + if (V->hasName()) + return V->getName(); + return None; +} + void MemoryOpRemark::visitVariable(const Value *V, SmallVectorImpl &Result) { + if (auto *GV = dyn_cast(V)) { + auto *Ty = cast(GV->getType())->getElementType(); + int64_t Size = DL.getTypeSizeInBits(Ty).getFixedSize(); + VariableInfo Var{nameOrNone(GV), Size}; + if (!Var.isEmpty()) + Result.push_back(std::move(Var)); + return; + } + // If we find some information in the debug info, take that. bool FoundDI = false; // Try to get an llvm.dbg.declare, which has a DILocalVariable giving us the @@ -312,12 +327,10 @@ return; // If not, get it from the alloca. - Optional Name = AI->hasName() ? Optional(AI->getName()) - : Optional(None); Optional TySize = AI->getAllocationSizeInBits(DL); Optional Size = TySize ? getSizeInBytes(TySize->getFixedSize()) : None; - VariableInfo Var{Name, Size}; + VariableInfo Var{nameOrNone(AI), Size}; if (!Var.isEmpty()) Result.push_back(std::move(Var)); } diff --git a/llvm/test/CodeGen/AArch64/memsize-remarks.ll b/llvm/test/CodeGen/AArch64/memsize-remarks.ll --- a/llvm/test/CodeGen/AArch64/memsize-remarks.ll +++ b/llvm/test/CodeGen/AArch64/memsize-remarks.ll @@ -302,6 +302,19 @@ ret void } +@dropbear = external unnamed_addr constant [3 x i8], align 1 +@koala = external unnamed_addr constant [7 x i8], align 1 + +define void @slicePun() { +bb: +; GISEL: remark: :0:0: Call to memcpy. Memory operation size: 24 bytes.{{$}} +; GISEL-NEXT: Read Variables: koala (56 bytes). +; GISEL-NEXT: Written Variables: dropbear (24 bytes). + tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 getelementptr inbounds ([3 x i8], [3 x i8]* @dropbear, i64 0, i64 0), + i8* getelementptr inbounds ([7 x i8], [7 x i8]* @koala, i64 0, i64 0), i64 24, i1 false) + ret void +} + attributes #0 = { noinline nounwind ssp uwtable "frame-pointer"="non-leaf" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="apple-a7" "target-features"="+aes,+crypto,+fp-armv8,+neon,+sha2,+zcm,+zcz" } attributes #1 = { nounwind "frame-pointer"="non-leaf" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="apple-a7" "target-features"="+aes,+crypto,+fp-armv8,+neon,+sha2,+zcm,+zcz" } attributes #2 = { nofree nosync nounwind readnone speculatable willreturn }