llvm.org GIT mirror llvm / 368924a
loop-unroll: teach remapInstruction to update dbg.value intrinsics. Fixes PR35112. https://bugs.llvm.org/show_bug.cgi?id=35112 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317138 91177308-0d34-0410-b5e6-96231b3b80d8 Adrian Prantl 1 year, 11 months ago
2 changed file(s) with 90 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
6767 ValueToValueMapTy &VMap) {
6868 for (unsigned op = 0, E = I->getNumOperands(); op != E; ++op) {
6969 Value *Op = I->getOperand(op);
70
71 // Unwrap arguments of dbg.value intrinsics.
72 bool Wrapped = false;
73 if (auto *V = dyn_cast(Op))
74 if (auto *Unwrapped = dyn_cast(V->getMetadata())) {
75 Op = Unwrapped->getValue();
76 Wrapped = true;
77 }
78
79 auto wrap = [&](Value *V) {
80 auto &C = I->getContext();
81 return Wrapped ? MetadataAsValue::get(C, ValueAsMetadata::get(V)) : V;
82 };
83
7084 ValueToValueMapTy::iterator It = VMap.find(Op);
7185 if (It != VMap.end())
72 I->setOperand(op, It->second);
86 I->setOperand(op, wrap(It->second));
7387 }
7488
7589 if (PHINode *PN = dyn_cast(I)) {
0 ; RUN: opt %s -S -o - -loop-unroll | FileCheck %s
1 ; generated at -O3 from:
2 ; void f() {
3 ; for (int i = 1; i <=32; i <<=2 )
4 ; bar(i>>1);
5 ; }
6 source_filename = "/tmp/loop.c"
7 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
8 target triple = "x86_64-apple-macosx10.13.0"
9
10 ; Function Attrs: nounwind ssp uwtable
11 define void @f() local_unnamed_addr #0 !dbg !8 {
12 entry:
13 tail call void @llvm.dbg.value(metadata i32 1, metadata !12, metadata !DIExpression()), !dbg !15
14 br label %for.body, !dbg !16
15
16 for.cond.cleanup: ; preds = %for.body
17 ret void, !dbg !17
18
19 for.body: ; preds = %entry, %for.body
20 %i.04 = phi i32 [ 1, %entry ], [ %shl, %for.body ]
21 tail call void @llvm.dbg.value(metadata i32 %i.04, metadata !12, metadata !DIExpression()), !dbg !15
22 %shr = ashr i32 %i.04, 1, !dbg !18
23
24 ; The loop gets unrolled entirely.
25 ; CHECK: call void @llvm.dbg.value(metadata i32 1, metadata !12, metadata !DIExpression()), !dbg !15
26 ; CHECK: call void @llvm.dbg.value(metadata i32 4, metadata !12, metadata !DIExpression()), !dbg !15
27 ; CHECK: call void @llvm.dbg.value(metadata i32 16, metadata !12, metadata !DIExpression()), !dbg !15
28 ; CHECK: call void @llvm.dbg.value(metadata i32 64, metadata !12, metadata !DIExpression()), !dbg !15
29
30 %call = tail call i32 (i32, ...) bitcast (i32 (...)* @bar to i32 (i32, ...)*)(i32 %shr) #3, !dbg !20
31 %shl = shl i32 %i.04, 2, !dbg !21
32 tail call void @llvm.dbg.value(metadata i32 %shl, metadata !12, metadata !DIExpression()), !dbg !15
33 %cmp = icmp slt i32 %shl, 33, !dbg !22
34 br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !16, !llvm.loop !23
35 }
36
37 declare i32 @bar(...) local_unnamed_addr
38
39 ; Function Attrs: nounwind readnone speculatable
40 declare void @llvm.dbg.value(metadata, metadata, metadata) #2
41
42 attributes #0 = { nounwind ssp uwtable }
43 attributes #2 = { nounwind readnone speculatable }
44 attributes #3 = { nounwind }
45
46 !llvm.dbg.cu = !{!0}
47 !llvm.module.flags = !{!3, !4, !5, !6}
48 !llvm.ident = !{!7}
49
50 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0 (trunk 317113) (llvm/trunk 317122)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
51 !1 = !DIFile(filename: "/tmp/loop.c", directory: "/Data/llvm")
52 !2 = !{}
53 !3 = !{i32 2, !"Dwarf Version", i32 4}
54 !4 = !{i32 2, !"Debug Info Version", i32 3}
55 !5 = !{i32 1, !"wchar_size", i32 4}
56 !6 = !{i32 7, !"PIC Level", i32 2}
57 !7 = !{!"clang version 6.0.0 (trunk 317113) (llvm/trunk 317122)"}
58 !8 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !9, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !0, variables: !11)
59 !9 = !DISubroutineType(types: !10)
60 !10 = !{null}
61 !11 = !{!12}
62 !12 = !DILocalVariable(name: "i", scope: !13, file: !1, line: 2, type: !14)
63 !13 = distinct !DILexicalBlock(scope: !8, file: !1, line: 2, column: 3)
64 !14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
65 !15 = !DILocation(line: 2, column: 12, scope: !13)
66 !16 = !DILocation(line: 2, column: 3, scope: !13)
67 !17 = !DILocation(line: 4, column: 1, scope: !8)
68 !18 = !DILocation(line: 3, column: 10, scope: !19)
69 !19 = distinct !DILexicalBlock(scope: !13, file: !1, line: 2, column: 3)
70 !20 = !DILocation(line: 3, column: 5, scope: !19)
71 !21 = !DILocation(line: 2, column: 29, scope: !19)
72 !22 = !DILocation(line: 2, column: 21, scope: !19)
73 !23 = distinct !{!23, !16, !24}
74 !24 = !DILocation(line: 3, column: 13, scope: !13)