Skip to content

Commit b8ec630

Browse files
committedAug 26, 2016
Handle empty functions with debug info in load/store opt pass
Summary: In fuctions that contained debug info but were empty otherwise, the ARM load/store optimizer could abort. This was because function MergeReturnIntoLDM handled the special case where a Machine Basic BLock is empty by calling MBB.empty(). However, this returns false in presence of debug info, although the function should be considered empty in the eyes of the load/store optimizer. This has been fixed by handling the case where searching through the block finds only debug instructions. Reviewers: rengolin, dexonsmith, llvm-commits, jmolloy Subscribers: t.p.northover, aemerson, rengolin, samparker Differential Revision: https://reviews.llvm.org/D23847 llvm-svn: 279820
1 parent fdb0f39 commit b8ec630

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed
 

‎llvm/lib/Target/ARM/ARMLoadStoreOptimizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1851,7 +1851,7 @@ bool ARMLoadStoreOpt::MergeReturnIntoLDM(MachineBasicBlock &MBB) {
18511851
if (MBB.empty()) return false;
18521852

18531853
MachineBasicBlock::iterator MBBI = MBB.getLastNonDebugInstr();
1854-
if (MBBI != MBB.begin() &&
1854+
if (MBBI != MBB.begin() && MBBI != MBB.end() &&
18551855
(MBBI->getOpcode() == ARM::BX_RET ||
18561856
MBBI->getOpcode() == ARM::tBX_RET ||
18571857
MBBI->getOpcode() == ARM::MOVPCLR)) {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
; RUN: llc < %s -mtriple=thumbv7em-arm-none-eabi -O3
2+
3+
; When using -Oz and -g, this code generated an abort in the ARM load/store optimizer.
4+
5+
%struct.s = type { %struct.s* }
6+
7+
; Function Attrs: minsize nounwind optsize readonly
8+
define %struct.s* @s_idx(%struct.s* readonly %xl) local_unnamed_addr #0 !dbg !8 {
9+
entry:
10+
tail call void @llvm.dbg.value(metadata %struct.s* %xl, i64 0, metadata !17, metadata !18), !dbg !19
11+
br label %while.cond, !dbg !20
12+
13+
while.cond: ; preds = %while.body, %entry
14+
%xl.addr.0 = phi %struct.s* [ %xl, %entry ], [ %0, %while.body ]
15+
%tobool = icmp eq %struct.s* %xl.addr.0, null
16+
br i1 %tobool, label %while.end, label %while.body
17+
18+
while.body: ; preds = %while.cond
19+
%next = getelementptr inbounds %struct.s, %struct.s* %xl.addr.0, i32 0, i32 0
20+
%0 = load %struct.s*, %struct.s** %next, align 4
21+
tail call void @llvm.dbg.value(metadata %struct.s* %0, i64 0, metadata !17, metadata !18), !dbg !19
22+
br label %while.cond
23+
24+
while.end: ; preds = %while.cond
25+
ret %struct.s* null
26+
}
27+
28+
; Function Attrs: nounwind readnone
29+
declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1
30+
31+
!llvm.dbg.cu = !{!0}
32+
!llvm.module.flags = !{!3, !4, !5, !6}
33+
34+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 4.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
35+
!1 = !DIFile(filename: "test.c", directory: "/a/b/c")
36+
!2 = !{}
37+
!3 = !{i32 2, !"Dwarf Version", i32 4}
38+
!4 = !{i32 2, !"Debug Info Version", i32 3}
39+
!5 = !{i32 1, !"wchar_size", i32 4}
40+
!6 = !{i32 1, !"min_enum_size", i32 4}
41+
!7 = !{!"clang version 4.0.0 "}
42+
!8 = distinct !DISubprogram(name: "s_idx", scope: !1, file: !1, line: 6, type: !9, isLocal: false, isDefinition: true, scopeLine: 7, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !16)
43+
!9 = !DISubroutineType(types: !10)
44+
!10 = !{!11, !11}
45+
!11 = !DIDerivedType(tag: DW_TAG_typedef, name: "ezxml_t", file: !1, line: 1, baseType: !12)
46+
!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 32, align: 32)
47+
!13 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s", file: !1, line: 2, size: 32, align: 32, elements: !14)
48+
!14 = !{!15}
49+
!15 = !DIDerivedType(tag: DW_TAG_member, name: "next", scope: !13, file: !1, line: 3, baseType: !11, size: 32, align: 32)
50+
!16 = !{!17}
51+
!17 = !DILocalVariable(name: "xl", arg: 1, scope: !8, file: !1, line: 6, type: !11)
52+
!18 = !DIExpression()
53+
!19 = !DILocation(line: 6, column: 27, scope: !8)
54+
!20 = !DILocation(line: 8, column: 5, scope: !8)

0 commit comments

Comments
 (0)
Please sign in to comment.