Index: llvm/include/llvm/IR/DebugInfoMetadata.h =================================================================== --- llvm/include/llvm/IR/DebugInfoMetadata.h +++ llvm/include/llvm/IR/DebugInfoMetadata.h @@ -2551,6 +2551,11 @@ return 0; } + /// Append a zero- or sign-extension to \p Expr. Converts the expression to a + /// stack value if it isn't one already. + static DIExpression *appendExt(const DIExpression *Expr, unsigned FromSize, + unsigned ToSize, bool Signed); + /// Check if fragments overlap between a pair of FragmentInfos. static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B) { return fragmentCmp(A, B) == 0; Index: llvm/lib/IR/DebugInfoMetadata.cpp =================================================================== --- llvm/lib/IR/DebugInfoMetadata.cpp +++ llvm/lib/IR/DebugInfoMetadata.cpp @@ -1189,6 +1189,15 @@ return true; } +DIExpression *DIExpression::appendExt(const DIExpression *Expr, + unsigned FromSize, unsigned ToSize, + bool Signed) { + dwarf::TypeKind TK = Signed ? dwarf::DW_ATE_signed : dwarf::DW_ATE_unsigned; + uint64_t Ops[] = {dwarf::DW_OP_LLVM_convert, FromSize, TK, + dwarf::DW_OP_LLVM_convert, ToSize, TK}; + return appendToStack(Expr, Ops); +} + DIGlobalVariableExpression * DIGlobalVariableExpression::getImpl(LLVMContext &Context, Metadata *Variable, Metadata *Expression, StorageType Storage, Index: llvm/lib/Transforms/Utils/Local.cpp =================================================================== --- llvm/lib/Transforms/Utils/Local.cpp +++ llvm/lib/Transforms/Utils/Local.cpp @@ -1867,10 +1867,8 @@ return None; bool Signed = *Signedness == DIBasicType::Signedness::Signed; - dwarf::TypeKind TK = Signed ? dwarf::DW_ATE_signed : dwarf::DW_ATE_unsigned; - SmallVector Ops({dwarf::DW_OP_LLVM_convert, ToBits, TK, - dwarf::DW_OP_LLVM_convert, FromBits, TK}); - return DIExpression::appendToStack(DII.getExpression(), Ops); + return DIExpression::appendExt(DII.getExpression(), ToBits, FromBits, + Signed); }; return rewriteDebugUsers(From, To, DomPoint, DT, SignOrZeroExt); }