llvm.org GIT mirror llvm / 90d2c9d
[LoopReroll] Ignore debug intrinsics Originally, debug intrinsics and annotation intrinsics may prevent the loop to be rerolled, now they are ignored. Differential Revision: http://reviews.llvm.org/D13150 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@248718 91177308-0d34-0410-b5e6-96231b3b80d8 Weiming Zhao 4 years ago
2 changed file(s) with 159 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
992992 return false;
993993 }
994994
995 static bool isIgnorableInst(const Instruction *I) {
996 if (isa(I))
997 return true;
998 const IntrinsicInst* II = dyn_cast(I);
999 if (!II)
1000 return false;
1001 switch (II->getIntrinsicID()) {
1002 default:
1003 return false;
1004 case llvm::Intrinsic::annotation:
1005 case Intrinsic::ptr_annotation:
1006 case Intrinsic::var_annotation:
1007 // TODO: the following intrinsics may also be whitelisted:
1008 // lifetime_start, lifetime_end, invariant_start, invariant_end
1009 return true;
1010 }
1011 return false;
1012 }
1013
9951014 bool LoopReroll::DAGRootTracker::validate(ReductionTracker &Reductions) {
9961015 // We now need to check for equivalence of the use graph of each root with
9971016 // that of the primary induction variable (excluding the roots). Our goal
10251044 // Make sure all instructions in the loop are in one and only one
10261045 // set.
10271046 for (auto &KV : Uses) {
1028 if (KV.second.count() != 1) {
1047 if (KV.second.count() != 1 && !isIgnorableInst(KV.first)) {
10291048 DEBUG(dbgs() << "LRR: Aborting - instruction is not used in 1 iteration: "
10301049 << *KV.first << " (#uses=" << KV.second.count() << ")\n");
10311050 return false;
0 ;RUN: opt < %s -loop-reroll -S | FileCheck %s
1 ;void foo(float * restrict a, float * restrict b, int n) {
2 ; for(int i = 0; i < n; i+=4) {
3 ; a[i] = b[i];
4 ; a[i+1] = b[i+1];
5 ; a[i+2] = b[i+2];
6 ; a[i+3] = b[i+3];
7 ; }
8 ;}
9 target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
10 target triple = "armv4t--linux-gnueabi"
11
12 ; Function Attrs: nounwind
13 define void @foo(float* noalias nocapture %a, float* noalias nocapture readonly %b, i32 %n) #0 {
14 entry:
15 ;CHECK-LABEL: @foo
16
17 tail call void @llvm.dbg.value(metadata float* %a, i64 0, metadata !12, metadata !22), !dbg !23
18 tail call void @llvm.dbg.value(metadata float* %b, i64 0, metadata !13, metadata !22), !dbg !24
19 tail call void @llvm.dbg.value(metadata i32 %n, i64 0, metadata !14, metadata !22), !dbg !25
20 tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !15, metadata !22), !dbg !26
21 %cmp.30 = icmp sgt i32 %n, 0, !dbg !27
22 br i1 %cmp.30, label %for.body.preheader, label %for.cond.cleanup, !dbg !29
23
24 for.body.preheader: ; preds = %entry
25 br label %for.body, !dbg !30
26
27 for.cond.cleanup.loopexit: ; preds = %for.body
28 br label %for.cond.cleanup, !dbg !32
29
30 for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit, %entry
31 ret void, !dbg !32
32
33 for.body: ; preds = %for.body.preheader, %for.body
34 ;CHECK: for.body:
35 ;CHECK: %indvar = phi i32 [ %indvar.next, %for.body ], [ 0, {{.*}} ]
36 ;CHECK: load
37 ;CHECK: store
38 ;CHECK-NOT: load
39 ;CHECK-NOT: store
40 ;CHECK: call void @llvm.dbg.value
41 ;CHECK: %indvar.next = add i32 %indvar, 1
42 ;CHECK: icmp eq i32 %indvar
43 %i.031 = phi i32 [ %add13, %for.body ], [ 0, %for.body.preheader ]
44 %arrayidx = getelementptr inbounds float, float* %b, i32 %i.031, !dbg !30
45 %0 = bitcast float* %arrayidx to i32*, !dbg !30
46 %1 = load i32, i32* %0, align 4, !dbg !30, !tbaa !33
47 %arrayidx1 = getelementptr inbounds float, float* %a, i32 %i.031, !dbg !37
48 %2 = bitcast float* %arrayidx1 to i32*, !dbg !38
49 store i32 %1, i32* %2, align 4, !dbg !38, !tbaa !33
50 %add = or i32 %i.031, 1, !dbg !39
51 %arrayidx2 = getelementptr inbounds float, float* %b, i32 %add, !dbg !40
52 %3 = bitcast float* %arrayidx2 to i32*, !dbg !40
53 %4 = load i32, i32* %3, align 4, !dbg !40, !tbaa !33
54 %arrayidx4 = getelementptr inbounds float, float* %a, i32 %add, !dbg !41
55 %5 = bitcast float* %arrayidx4 to i32*, !dbg !42
56 store i32 %4, i32* %5, align 4, !dbg !42, !tbaa !33
57 %add5 = or i32 %i.031, 2, !dbg !43
58 %arrayidx6 = getelementptr inbounds float, float* %b, i32 %add5, !dbg !44
59 %6 = bitcast float* %arrayidx6 to i32*, !dbg !44
60 %7 = load i32, i32* %6, align 4, !dbg !44, !tbaa !33
61 %arrayidx8 = getelementptr inbounds float, float* %a, i32 %add5, !dbg !45
62 %8 = bitcast float* %arrayidx8 to i32*, !dbg !46
63 store i32 %7, i32* %8, align 4, !dbg !46, !tbaa !33
64 %add9 = or i32 %i.031, 3, !dbg !47
65 %arrayidx10 = getelementptr inbounds float, float* %b, i32 %add9, !dbg !48
66 %9 = bitcast float* %arrayidx10 to i32*, !dbg !48
67 %10 = load i32, i32* %9, align 4, !dbg !48, !tbaa !33
68 %arrayidx12 = getelementptr inbounds float, float* %a, i32 %add9, !dbg !49
69 %11 = bitcast float* %arrayidx12 to i32*, !dbg !50
70 store i32 %10, i32* %11, align 4, !dbg !50, !tbaa !33
71 %add13 = add nuw nsw i32 %i.031, 4, !dbg !51
72 tail call void @llvm.dbg.value(metadata i32 %add13, i64 0, metadata !15, metadata !22), !dbg !26
73 %cmp = icmp slt i32 %add13, %n, !dbg !27
74 br i1 %cmp, label %for.body, label %for.cond.cleanup.loopexit, !dbg !29
75 }
76
77 ; Function Attrs: nounwind readnone
78 declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1
79
80 attributes #0 = { nounwind "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="arm7tdmi" "target-features"="+strict-align" "unsafe-fp-math"="false" "use-soft-float"="false" }
81 attributes #1 = { nounwind readnone }
82
83 !llvm.dbg.cu = !{!0}
84 !llvm.module.flags = !{!17, !18, !19, !20}
85 !llvm.ident = !{!21}
86
87 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.8.0 (http://llvm.org/git/clang.git b1fbc23058e7fa1cdd954ab97ba84f1c549c9879) (http://llvm.org/git/llvm.git 054da58c5398a721d4dab7af63d7de8d7a1e1a1c)", isOptimized: true, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3)
88 !1 = !DIFile(filename: "test.c", directory: "/home/weimingz/llvm-build/release/community-tip")
89 !2 = !{}
90 !3 = !{!4}
91 !4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, function: void (float*, float*, i32)* @foo, variables: !11)
92 !5 = !DISubroutineType(types: !6)
93 !6 = !{null, !7, !7, !10}
94 !7 = !DIDerivedType(tag: DW_TAG_restrict_type, baseType: !8)
95 !8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 32, align: 32)
96 !9 = !DIBasicType(name: "float", size: 32, align: 32, encoding: DW_ATE_float)
97 !10 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
98 !11 = !{!12, !13, !14, !15}
99 !12 = !DILocalVariable(name: "a", arg: 1, scope: !4, file: !1, line: 1, type: !7)
100 !13 = !DILocalVariable(name: "b", arg: 2, scope: !4, file: !1, line: 1, type: !7)
101 !14 = !DILocalVariable(name: "n", arg: 3, scope: !4, file: !1, line: 1, type: !10)
102 !15 = !DILocalVariable(name: "i", scope: !16, file: !1, line: 2, type: !10)
103 !16 = distinct !DILexicalBlock(scope: !4, file: !1, line: 2, column: 3)
104 !17 = !{i32 2, !"Dwarf Version", i32 4}
105 !18 = !{i32 2, !"Debug Info Version", i32 3}
106 !19 = !{i32 1, !"wchar_size", i32 4}
107 !20 = !{i32 1, !"min_enum_size", i32 4}
108 !21 = !{!"clang version 3.8.0 (http://llvm.org/git/clang.git b1fbc23058e7fa1cdd954ab97ba84f1c549c9879) (http://llvm.org/git/llvm.git 054da58c5398a721d4dab7af63d7de8d7a1e1a1c)"}
109 !22 = !DIExpression()
110 !23 = !DILocation(line: 1, column: 27, scope: !4)
111 !24 = !DILocation(line: 1, column: 47, scope: !4)
112 !25 = !DILocation(line: 1, column: 54, scope: !4)
113 !26 = !DILocation(line: 2, column: 11, scope: !16)
114 !27 = !DILocation(line: 2, column: 20, scope: !28)
115 !28 = distinct !DILexicalBlock(scope: !16, file: !1, line: 2, column: 3)
116 !29 = !DILocation(line: 2, column: 3, scope: !16)
117 !30 = !DILocation(line: 3, column: 12, scope: !31)
118 !31 = distinct !DILexicalBlock(scope: !28, file: !1, line: 2, column: 31)
119 !32 = !DILocation(line: 8, column: 1, scope: !4)
120 !33 = !{!34, !34, i64 0}
121 !34 = !{!"float", !35, i64 0}
122 !35 = !{!"omnipotent char", !36, i64 0}
123 !36 = !{!"Simple C/C++ TBAA"}
124 !37 = !DILocation(line: 3, column: 5, scope: !31)
125 !38 = !DILocation(line: 3, column: 10, scope: !31)
126 !39 = !DILocation(line: 4, column: 17, scope: !31)
127 !40 = !DILocation(line: 4, column: 14, scope: !31)
128 !41 = !DILocation(line: 4, column: 5, scope: !31)
129 !42 = !DILocation(line: 4, column: 12, scope: !31)
130 !43 = !DILocation(line: 5, column: 17, scope: !31)
131 !44 = !DILocation(line: 5, column: 14, scope: !31)
132 !45 = !DILocation(line: 5, column: 5, scope: !31)
133 !46 = !DILocation(line: 5, column: 12, scope: !31)
134 !47 = !DILocation(line: 6, column: 17, scope: !31)
135 !48 = !DILocation(line: 6, column: 14, scope: !31)
136 !49 = !DILocation(line: 6, column: 5, scope: !31)
137 !50 = !DILocation(line: 6, column: 12, scope: !31)
138 !51 = !DILocation(line: 2, column: 26, scope: !28)