Skip to content

Commit d5354fd

Browse files
committedJan 14, 2016
[SROA] Also insert a bit piece expression if only one piece is needed
Summary: If SROA creates only one piece (e.g. because the other is not needed), it still needs to create a bit_piece expression if that bit piece is smaller than the original size of the alloca. Reviewers: aprantl Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D16187 llvm-svn: 257795
1 parent 60b201b commit d5354fd

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed
 

‎llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4024,12 +4024,12 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
40244024
auto *Var = DbgDecl->getVariable();
40254025
auto *Expr = DbgDecl->getExpression();
40264026
DIBuilder DIB(*AI.getModule(), /*AllowUnresolved*/ false);
4027-
bool IsSplit = Pieces.size() > 1;
4027+
uint64_t AllocaSize = DL.getTypeSizeInBits(AI.getAllocatedType());
40284028
for (auto Piece : Pieces) {
40294029
// Create a piece expression describing the new partition or reuse AI's
40304030
// expression if there is only one partition.
40314031
auto *PieceExpr = Expr;
4032-
if (IsSplit || Expr->isBitPiece()) {
4032+
if (Piece.Size < AllocaSize || Expr->isBitPiece()) {
40334033
// If this alloca is already a scalar replacement of a larger aggregate,
40344034
// Piece.Offset describes the offset inside the scalar.
40354035
uint64_t Offset = Expr->isBitPiece() ? Expr->getBitPieceOffset() : 0;
@@ -4043,6 +4043,9 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
40434043
Size = std::min(Size, AbsEnd - Start);
40444044
}
40454045
PieceExpr = DIB.createBitPieceExpression(Start, Size);
4046+
} else {
4047+
assert(Pieces.size() == 1 &&
4048+
"partition is as large as original alloca");
40464049
}
40474050

40484051
// Remove any existing dbg.declare intrinsic describing the same alloca.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
; RUN: opt -sroa %s -S | FileCheck %s
2+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
3+
4+
%foo = type { [8 x i8], [8 x i8] }
5+
6+
declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
7+
define void @_ZL18findInsertLocationPN4llvm17MachineBasicBlockENS_9SlotIndexERNS_13LiveIntervalsE() {
8+
entry:
9+
%retval = alloca %foo, align 8
10+
call void @llvm.dbg.declare(metadata %foo* %retval, metadata !1, metadata !7), !dbg !8
11+
; Checks that SROA still inserts a bit_piece expression, even if it produces only one piece
12+
; (as long as that piece is smaller than the whole thing)
13+
; CHECK-NOT: call void @llvm.dbg.value
14+
; CHECK: call void @llvm.dbg.value(metadata %foo* undef, i64 0, metadata !1, metadata ![[BIT_PIECE:[0-9]+]]), !dbg
15+
; CHECK-NOT: call void @llvm.dbg.value
16+
; CHECK: ![[BIT_PIECE]] = !DIExpression(DW_OP_bit_piece, 64, 64)
17+
%0 = bitcast %foo* %retval to i8*
18+
%1 = getelementptr inbounds i8, i8* %0, i64 8
19+
%2 = bitcast i8* %1 to %foo**
20+
store %foo* undef, %foo** %2, align 8
21+
ret void
22+
}
23+
24+
attributes #0 = { nounwind readnone }
25+
26+
!llvm.dbg.cu = !{}
27+
!llvm.module.flags = !{!0}
28+
29+
!0 = !{i32 2, !"Debug Info Version", i32 3}
30+
!1 = !DILocalVariable(name: "I", scope: !2, file: !3, line: 947, type: !4)
31+
!2 = distinct !DISubprogram(name: "findInsertLocation", linkageName: "_ZL18findInsertLocationPN4llvm17MachineBasicBlockENS_9SlotIndexERNS_13LiveIntervalsE", scope: !3, file: !3, line: 937, isLocal: true, isDefinition: true, scopeLine: 938, flags: DIFlagPrototyped, isOptimized: true)
32+
!3 = !DIFile(filename: "none", directory: ".")
33+
!4 = !DICompositeType(tag: DW_TAG_class_type, name: "bundle_iterator<llvm::MachineInstr, llvm::ilist_iterator<llvm::MachineInstr> >", scope: !5, file: !3, line: 163, size: 128, align: 64, elements: !6, templateParams: !6, identifier: "_ZTSN4llvm17MachineBasicBlock15bundle_iteratorINS_12MachineInstrENS_14ilist_iteratorIS2_EEEE")
34+
!5 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "MachineBasicBlock", file: !3, line: 68, size: 1408, align: 64, identifier: "_ZTSN4llvm17MachineBasicBlockE")
35+
!6 = !{}
36+
!7 = !DIExpression()
37+
!8 = !DILocation(line: 947, column: 35, scope: !2)

0 commit comments

Comments
 (0)
Please sign in to comment.