summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/SROA.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/Scalar/SROA.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/SROA.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index 8d818c673f6..6faf905f9b3 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -4174,14 +4174,23 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
for (auto Piece : Pieces) {
// Create a piece expression describing the new partition or reuse AI's
// expression if there is only one partition.
- if (IsSplit)
- Expr = DIB.createPieceExpression(Piece.Offset, Piece.Size);
+ DIExpression PieceExpr = Expr;
+ if (IsSplit || Expr.isVariablePiece()) {
+ // If this alloca is already a scalar replacement of a larger aggregate,
+ // Piece.Offset describes the offset inside the scalar.
+ unsigned Offset = Expr.isVariablePiece() ? Expr.getPieceOffset() : 0;
+ assert((Offset == 0 ||
+ Offset+Piece.Offset+Piece.Size <=
+ Expr.getPieceOffset()+Expr.getPieceSize()) &&
+ "inner piece is not inside original alloca");
+ PieceExpr = DIB.createPieceExpression(Offset+Piece.Offset, Piece.Size);
+ }
// Remove any existing dbg.declare intrinsic describing the same alloca.
if (DbgDeclareInst *OldDDI = FindAllocaDbgDeclare(Piece.Alloca))
OldDDI->eraseFromParent();
- Instruction *NewDDI = DIB.insertDeclare(Piece.Alloca, Var, Expr, &AI);
+ auto *NewDDI = DIB.insertDeclare(Piece.Alloca, Var, PieceExpr, &AI);
NewDDI->setDebugLoc(DbgDecl->getDebugLoc());
}
}
OpenPOWER on IntegriCloud