llvm.org GIT mirror llvm / a555cf0
IndVarSimplify: preserve debug information attached to widened PHI nodes. This fixes PR35015. https://bugs.llvm.org/show_bug.cgi?id=35015 Differential Revision: https://reviews.llvm.org/D39345 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317282 91177308-0d34-0410-b5e6-96231b3b80d8 Adrian Prantl 1 year, 11 months ago
2 changed file(s) with 81 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
4747 #include "llvm/IR/ConstantRange.h"
4848 #include "llvm/IR/Constants.h"
4949 #include "llvm/IR/DataLayout.h"
50 #include "llvm/IR/DebugInfoMetadata.h"
5051 #include "llvm/IR/DerivedTypes.h"
5152 #include "llvm/IR/Dominators.h"
5253 #include "llvm/IR/Function.h"
16231624 if (DU.NarrowDef->use_empty())
16241625 DeadInsts.emplace_back(DU.NarrowDef);
16251626 }
1627
1628 // Attach any debug information to the new PHI. Since OrigPhi and WidePHI
1629 // evaluate the same recurrence, we can just copy the debug info over.
1630 SmallVector DbgValues;
1631 llvm::findDbgValues(DbgValues, OrigPhi);
1632 auto *MDPhi = MetadataAsValue::get(WidePhi->getContext(),
1633 ValueAsMetadata::get(WidePhi));
1634 for (auto &DbgValue : DbgValues)
1635 DbgValue->setOperand(0, MDPhi);
16261636 return WidePhi;
16271637 }
16281638
0 ; RUN: opt %s -indvars -S -o - | FileCheck %s
1 source_filename = "/Data/llvm/test/Transforms/IndVarSimplify/scev-phi-debug-info.ll"
2 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
3 target triple = "x86_64-unknown-linux-gnu"
4
5 %struct.status = type { i32, i8* }
6
7 @status = internal unnamed_addr global [32 x %struct.status] zeroinitializer, align 16, !dbg !0
8
9 define void @f0() local_unnamed_addr !dbg !20 {
10 entry:
11 tail call void @llvm.dbg.value(metadata i32 0, metadata !23, metadata !DIExpression()), !dbg !24
12 br label %for.cond, !dbg !24
13
14 for.cond: ; preds = %for.body, %entry
15 ; CHECK: %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
16 ; CHECK: call void @llvm.dbg.value(metadata i64 %indvars.iv, metadata !23, metadata !DIExpression()), !dbg !24
17 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
18 tail call void @llvm.dbg.value(metadata i32 %i.0, metadata !23, metadata !DIExpression()), !dbg !24
19 %cmp = icmp slt i32 %i.0, 32, !dbg !24
20 br i1 %cmp, label %for.body, label %for.end, !dbg !24
21
22 for.body: ; preds = %for.cond
23 %idxprom = sext i32 %i.0 to i64, !dbg !24
24 %value = getelementptr inbounds [32 x %struct.status], [32 x %struct.status]* @status, i64 0, i64 %idxprom, i32 0, !dbg !24
25 store i32 42, i32* %value, align 16, !dbg !24
26 tail call void @use(i32 %i.0), !dbg !24
27 %inc = add nsw i32 %i.0, 1, !dbg !24
28 tail call void @llvm.dbg.value(metadata i32 %inc, metadata !23, metadata !DIExpression()), !dbg !24
29 br label %for.cond, !dbg !24
30
31 for.end: ; preds = %for.cond
32 ret void, !dbg !24
33 }
34
35 declare void @use(i32)
36
37 ; Function Attrs: nounwind readnone speculatable
38 declare void @llvm.dbg.value(metadata, metadata, metadata) #0
39
40 attributes #0 = { nounwind readnone speculatable }
41
42 !llvm.dbg.cu = !{!2}
43 !llvm.module.flags = !{!16, !17, !18}
44 !llvm.ident = !{!19}
45
46 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
47 !1 = distinct !DIGlobalVariable(name: "status", scope: !2, file: !3, line: 5, type: !6, isLocal: true, isDefinition: true)
48 !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 6.0.0 (trunk 316001) (llvm/trunk 316171)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
49 !3 = !DIFile(filename: "x.c", directory: "/home/davide/work/llvm/build-release/bin")
50 !4 = !{}
51 !5 = !{!0}
52 !6 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, size: 4096, elements: !14)
53 !7 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "status", file: !3, line: 2, size: 128, elements: !8)
54 !8 = !{!9, !11}
55 !9 = !DIDerivedType(tag: DW_TAG_member, name: "value", scope: !7, file: !3, line: 3, baseType: !10, size: 32)
56 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
57 !11 = !DIDerivedType(tag: DW_TAG_member, name: "p", scope: !7, file: !3, line: 4, baseType: !12, size: 64, offset: 64)
58 !12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
59 !13 = !DIBasicType(name: "unsigned char", size: 8, encoding: DW_ATE_unsigned_char)
60 !14 = !{!15}
61 !15 = !DISubrange(count: 32)
62 !16 = !{i32 2, !"Dwarf Version", i32 4}
63 !17 = !{i32 2, !"Debug Info Version", i32 3}
64 !18 = !{i32 1, !"wchar_size", i32 4}
65 !19 = !{!"clang version 6.0.0 (trunk 316001) (llvm/trunk 316171)"}
66 !20 = distinct !DISubprogram(name: "f0", scope: !3, file: !3, line: 6, type: !21, isLocal: false, isDefinition: true, scopeLine: 7, flags: DIFlagPrototyped, isOptimized: true, unit: !2, variables: !22)
67 !21 = !DISubroutineType(types: !4)
68 !22 = !{!23}
69 !23 = !DILocalVariable(name: "i", scope: !20, file: !3, line: 8, type: !10)
70 !24 = !DILocation(line: 9, scope: !20)