Skip to content

Commit 5947c17

Browse files
committedJun 25, 2018
[SCEVExp] Advance found insertion point until we find a non-dbg instruction.
This avoids creating unnecessary casts if the IP used to be a dbg info intrinsic. Fixes PR37727. Reviewers: vsk, aprantl, sanjoy, efriedma Reviewed By: vsk, efriedma Differential Revision: https://reviews.llvm.org/D47874 llvm-svn: 335513
1 parent 1e911fa commit 5947c17

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed
 

Diff for: ‎llvm/lib/Analysis/ScalarEvolutionExpander.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ Value *SCEVExpander::InsertNoopCastOfTo(Value *V, Type *Ty) {
162162

163163
// Cast the instruction immediately after the instruction.
164164
Instruction *I = cast<Instruction>(V);
165-
BasicBlock::iterator IP = findInsertPointAfter(I, Builder.GetInsertBlock());
165+
BasicBlock::iterator IP = skipDebugInfo(
166+
findInsertPointAfter(I, Builder.GetInsertBlock()));
166167
return ReuseOrCreateCast(I, Ty, Op, IP);
167168
}
168169

@@ -1480,8 +1481,8 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) {
14801481
NewOps[i] = SE.getAnyExtendExpr(S->op_begin()[i], CanonicalIV->getType());
14811482
Value *V = expand(SE.getAddRecExpr(NewOps, S->getLoop(),
14821483
S->getNoWrapFlags(SCEV::FlagNW)));
1483-
BasicBlock::iterator NewInsertPt =
1484-
findInsertPointAfter(cast<Instruction>(V), Builder.GetInsertBlock());
1484+
BasicBlock::iterator NewInsertPt = skipDebugInfo(
1485+
findInsertPointAfter(cast<Instruction>(V), Builder.GetInsertBlock()));
14851486
V = expandCodeFor(SE.getTruncateExpr(SE.getUnknown(V), Ty), nullptr,
14861487
&*NewInsertPt);
14871488
return V;
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
; RUN: opt -loop-vectorize %s -S | FileCheck %s
2+
; Tests that the debug intrinsic does not cause additional instructions to be
3+
; created by SCEVExpander.
4+
5+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
6+
target triple = "x86_64-unknown-linux-gnu"
7+
8+
%struct.s = type { double* }
9+
10+
; CHECK-LABEL: entry:
11+
; CHECK: %[[LV:.+]] = load double*, double** %a
12+
; CHECK-NEXT: call void @llvm.dbg.value(metadata double* %[[LV]]
13+
; CHECK-NEXT: %[[PTI:.+]] = ptrtoint double* %[[LV]] to i64
14+
; CHECK-NEXT: %[[MPTR:.+]] = and i64 %[[PTI]], 31
15+
; CHECK-NEXT: %[[MCOND:.+]] = icmp eq i64 %[[MPTR]], 0
16+
; CHECK-NEXT: br i1 false, label %scalar.ph, label %vector.scevcheck
17+
18+
19+
define void @test(%struct.s* %x) !dbg !6 {
20+
entry:
21+
%a = getelementptr inbounds %struct.s, %struct.s* %x, i64 0, i32 0
22+
%0 = load double*, double** %a, align 8
23+
call void @llvm.dbg.value(metadata double* %0, metadata !9, metadata !DIExpression()), !dbg !11
24+
%ptrint = ptrtoint double* %0 to i64
25+
%maskedptr = and i64 %ptrint, 31
26+
%maskcond = icmp eq i64 %maskedptr, 0
27+
br label %for.body
28+
29+
for.body: ; preds = %for.body, %entry
30+
%indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next.1, %for.body ]
31+
%arrayidx = getelementptr inbounds double, double* %0, i64 %indvars.iv
32+
%1 = load double, double* %arrayidx, align 16
33+
%add = fadd double %1, 1.000000e+00
34+
store double %add, double* %arrayidx, align 16
35+
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
36+
%arrayidx.1 = getelementptr inbounds double, double* %0, i64 %indvars.iv.next
37+
%2 = load double, double* %arrayidx.1, align 8
38+
%add.1 = fadd double %2, 1.000000e+00
39+
store double %add.1, double* %arrayidx.1, align 8
40+
%indvars.iv.next.1 = add nuw nsw i64 %indvars.iv.next, 1
41+
%exitcond.1 = icmp eq i64 %indvars.iv.next, 1599
42+
br i1 %exitcond.1, label %for.end, label %for.body
43+
44+
for.end: ; preds = %for.body
45+
ret void
46+
}
47+
48+
declare void @llvm.dbg.value(metadata, metadata, metadata)
49+
50+
!llvm.dbg.cu = !{!0}
51+
!llvm.module.flags = !{!5}
52+
53+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
54+
!1 = !DIFile(filename: "file.ll", directory: "/")
55+
!2 = !{}
56+
!5 = !{i32 2, !"Debug Info Version", i32 3}
57+
!6 = distinct !DISubprogram(name: "test", linkageName: "test", scope: null, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !0)
58+
!7 = !DISubroutineType(types: !2)
59+
!9 = !DILocalVariable(name: "1", scope: !6, file: !1, line: 1, type: !10)
60+
!10 = !DIBasicType(name: "ty64", size: 64, encoding: DW_ATE_unsigned)
61+
!11 = !DILocation(line: 1, column: 1, scope: !6)

0 commit comments

Comments
 (0)
Please sign in to comment.