Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 9faad58

Browse files
committed
Update loop unroller cost model to make sure debug info does not affect optimization decisions.
Summary: Debug info should *not* affect optimization decisions. This patch updates loop unroller cost model to make it not affected by debug info. Reviewers: davidxl, mzolotukhin Subscribers: haicheng, llvm-commits, mzolotukhin Differential Revision: https://reviews.llvm.org/D25098 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282894 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent b035d53 commit 9faad58

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

lib/Transforms/Scalar/LoopUnrollPass.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ analyzeLoopUnrollCost(const Loop *L, unsigned TripCount, DominatorTree &DT,
411411
// it. We don't change the actual IR, just count optimization
412412
// opportunities.
413413
for (Instruction &I : *BB) {
414+
if (isa<DbgInfoIntrinsic>(I))
415+
continue;
416+
414417
// Track this instruction's expected baseline cost when executing the
415418
// rolled loop form.
416419
RolledDynamicCost += TTI.getUserCost(&I);

test/Transforms/LoopUnroll/unroll-pragmas.ll

+40-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
; RUN: opt < %s -loop-unroll -pragma-unroll-threshold=1024 -S | FileCheck %s
2-
; RUN: opt < %s -loop-unroll -loop-unroll -pragma-unroll-threshold=1024 -S | FileCheck %s
1+
; RUN: opt < %s -loop-unroll -pragma-unroll-threshold=1024 -unroll-max-iteration-count-to-analyze=40 -S | FileCheck %s
2+
; RUN: opt < %s -loop-unroll -loop-unroll -pragma-unroll-threshold=1024 -unroll-max-iteration-count-to-analyze=40 -S | FileCheck %s
33
;
44
; Run loop unrolling twice to verify that loop unrolling metadata is properly
55
; removed and further unrolling is disabled after the pass is run once.
@@ -31,6 +31,31 @@ for.end: ; preds = %for.body
3131
ret void
3232
}
3333

34+
; loop4_with_dbg contains a small loop which should be completely unrolled by
35+
; the default unrolling heuristics. There is DbgInfoIntrinsic inside the loop
36+
; body, which should not block unrolling.
37+
;
38+
; CHECK-LABEL: @loop4_dbg(
39+
; CHECK-NOT: br i1
40+
define void @loop4_dbg(i32* nocapture %a) {
41+
entry:
42+
br label %for.body
43+
44+
for.body: ; preds = %for.body, %entry
45+
%indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
46+
%arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
47+
%0 = load i32, i32* %arrayidx, align 4
48+
call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !22, metadata !DIExpression()), !dbg !24
49+
%inc = add nsw i32 %0, 1
50+
store i32 %inc, i32* %arrayidx, align 4
51+
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
52+
%exitcond = icmp eq i64 %indvars.iv.next, 40
53+
br i1 %exitcond, label %for.end, label %for.body
54+
55+
for.end: ; preds = %for.body
56+
ret void
57+
}
58+
3459
; #pragma clang loop unroll(disable)
3560
;
3661
; CHECK-LABEL: @loop4_with_disable(
@@ -357,5 +382,18 @@ for.body: ; preds = %entry, %for.body
357382
for.end: ; preds = %for.body, %entry
358383
ret void
359384
}
385+
386+
declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
387+
388+
!llvm.module.flags = !{!18, !19}
389+
!llvm.dbg.cu = !{!20}
390+
360391
!16 = !{!16, !17}
361392
!17 = !{!"llvm.loop.unroll.count", i32 3}
393+
!18 = !{i32 2, !"Dwarf Version", i32 4}
394+
!19 = !{i32 2, !"Debug Info Version", i32 3}
395+
!20 = distinct !DICompileUnit(language: DW_LANG_C99, file: !23)
396+
!21 = distinct !DISubprogram(name: "foo", unit: !20)
397+
!22 = !DILocalVariable(name: "b", line: 1, arg: 2, scope: !21)
398+
!23 = !DIFile(filename: "a.c", directory: "a/b")
399+
!24 = !DILocation(line: 1, column: 14, scope: !21)

0 commit comments

Comments
 (0)