forked from OSchip/llvm-project
75acec8a14
Summary: DebugLoc shouldn't be propagated across basic blocks to prevent incorrect stepping and imprecise sample profile result. rL288903 addressed the wrong DebugLoc propagation issue by limiting the copy of DebugLoc when GVN removes a fully redundant load that is dominated by some other load. However, DebugLoc is still incorrectly propagated in the following example: ``` 1: extern int g; 2: 3: void foo(int x, int y, int z) { 4: if (x) 5: g = 0; 6: else 7: g = 1; 8: 9: int i = 0; 10: for ( ; i < y ; i++) 11: if (i > z) 12: g++; 13: } ``` Below is LLVM IR representation of the program before GVN: ``` @g = external local_unnamed_addr global i32, align 4 ; Function Attrs: nounwind uwtable define void @foo(i32 %x, i32 %y, i32 %z) local_unnamed_addr #0 !dbg !4 { entry: %not.tobool = icmp eq i32 %x, 0, !dbg !8 %.sink = zext i1 %not.tobool to i32, !dbg !8 store i32 %.sink, i32* @g, align 4, !tbaa !9 %cmp8 = icmp sgt i32 %y, 0, !dbg !13 br i1 %cmp8, label %for.body.preheader, label %for.end, !dbg !17 for.body.preheader: ; preds = %entry br label %for.body, !dbg !19 for.body: ; preds = %for.body.preheader, %for.inc %i.09 = phi i32 [ %inc4, %for.inc ], [ 0, %for.body.preheader ] %cmp1 = icmp sgt i32 %i.09, %z, !dbg !19 br i1 %cmp1, label %if.then2, label %for.inc, !dbg !21 if.then2: ; preds = %for.body %0 = load i32, i32* @g, align 4, !dbg !22, !tbaa !9 %inc = add nsw i32 %0, 1, !dbg !22 store i32 %inc, i32* @g, align 4, !dbg !22, !tbaa !9 br label %for.inc, !dbg !23 for.inc: ; preds = %for.body, %if.then2 %inc4 = add nuw nsw i32 %i.09, 1, !dbg !24 %exitcond = icmp ne i32 %inc4, %y, !dbg !13 br i1 %exitcond, label %for.body, label %for.end.loopexit, !dbg !17 for.end.loopexit: ; preds = %for.inc br label %for.end, !dbg !26 for.end: ; preds = %for.end.loopexit, %entry ret void, !dbg !26 } ``` where ``` !21 = !DILocation(line: 11, column: 9, scope: !15) !22 = !DILocation(line: 12, column: 8, scope: !20) !23 = !DILocation(line: 12, column: 7, scope: !20) !24 = !DILocation(line: 10, column: 20, scope: !25) ``` And below is after GVN: ``` @g = external local_unnamed_addr global i32, align 4 define void @foo(i32 %x, i32 %y, i32 %z) local_unnamed_addr !dbg !4 { entry: %not.tobool = icmp eq i32 %x, 0, !dbg !8 %.sink = zext i1 %not.tobool to i32, !dbg !8 store i32 %.sink, i32* @g, align 4, !tbaa !9 %cmp8 = icmp sgt i32 %y, 0, !dbg !13 br i1 %cmp8, label %for.body.preheader, label %for.end, !dbg !17 for.body.preheader: ; preds = %entry br label %for.body, !dbg !19 for.body: ; preds = %for.inc, %for.body.preheader %0 = phi i32 [ %1, %for.inc ], [ %.sink, %for.body.preheader ], !dbg !21 %i.09 = phi i32 [ %inc4, %for.inc ], [ 0, %for.body.preheader ] %cmp1 = icmp sgt i32 %i.09, %z, !dbg !19 br i1 %cmp1, label %if.then2, label %for.inc, !dbg !22 if.then2: ; preds = %for.body %inc = add nsw i32 %0, 1, !dbg !21 store i32 %inc, i32* @g, align 4, !dbg !21, !tbaa !9 br label %for.inc, !dbg !23 for.inc: ; preds = %if.then2, %for.body %1 = phi i32 [ %inc, %if.then2 ], [ %0, %for.body ] %inc4 = add nuw nsw i32 %i.09, 1, !dbg !24 %exitcond = icmp ne i32 %inc4, %y, !dbg !13 br i1 %exitcond, label %for.body, label %for.end.loopexit, !dbg !17 for.end.loopexit: ; preds = %for.inc br label %for.end, !dbg !26 for.end: ; preds = %for.end.loopexit, %entry ret void, !dbg !26 } ``` As you see, GVN removes the load in if.then2 block and creates a phi instruction in for.body for it. The problem is that DebugLoc of remove load instruction is propagated to the newly created phi instruction, which is wrong. rL288903 cannot handle this case because ValuesPerBlock.size() is not 1 in this example when the load is removed. Reviewers: aprantl, andreadb, wolfgangp Reviewed By: andreadb Subscribers: davide, llvm-commits Differential Revision: https://reviews.llvm.org/D29254 llvm-svn: 293688 |
||
---|---|---|
.. | ||
2007-07-25-DominatedLoop.ll | ||
2007-07-25-InfiniteLoop.ll | ||
2007-07-25-Loop.ll | ||
2007-07-25-NestedLoop.ll | ||
2007-07-25-SinglePredecessor.ll | ||
2007-07-26-InterlockingLoops.ll | ||
2007-07-26-NonRedundant.ll | ||
2007-07-26-PhiErasure.ll | ||
2007-07-30-PredIDom.ll | ||
2007-07-31-NoDomInherit.ll | ||
2007-07-31-RedundantPhi.ll | ||
2008-02-12-UndefLoad.ll | ||
2008-02-13-NewPHI.ll | ||
2008-07-02-Unreachable.ll | ||
2008-12-09-SelfRemove.ll | ||
2008-12-12-RLE-Crash.ll | ||
2008-12-14-rle-reanalyze.ll | ||
2008-12-15-CacheVisited.ll | ||
2009-01-21-SortInvalidation.ll | ||
2009-01-22-SortInvalidation.ll | ||
2009-03-10-PREOnVoid.ll | ||
2009-07-13-MemDepSortFail.ll | ||
2009-11-12-MemDepMallocBitCast.ll | ||
2010-03-31-RedundantPHIs.ll | ||
2010-05-08-OneBit.ll | ||
2010-11-13-Simplify.ll | ||
2011-04-27-phioperands.ll | ||
2011-07-07-MatchIntrinsicExtract.ll | ||
2011-09-07-TypeIdFor.ll | ||
2012-05-22-PreCrash.ll | ||
2016-08-30-MaskedScatterGather.ll | ||
MemdepMiscompile.ll | ||
assume-equal.ll | ||
basic-cyclic-opt.ll | ||
basic-undef-test.ll | ||
basic.ll | ||
big-endian.ll | ||
bitcast-of-call.ll | ||
br-identical.ll | ||
calloc-load-removal.ll | ||
calls-nonlocal.ll | ||
calls-readonly.ll | ||
commute.ll | ||
cond_br.ll | ||
cond_br2.ll | ||
condprop.ll | ||
crash-no-aa.ll | ||
crash.ll | ||
cyclic-phi-handling.ll | ||
dbg-redundant-load.ll | ||
deadstore.ll | ||
debugloc.ll | ||
edge.ll | ||
equivalent-phi.ll | ||
fence.ll | ||
flags.ll | ||
fold-const-expr.ll | ||
fpmath.ll | ||
funclet.ll | ||
invariant.group.ll | ||
invariant.start.ll | ||
lifetime-simple.ll | ||
load-constant-mem.ll | ||
load-from-unreachable-predecessor.ll | ||
loadforward.ll | ||
malloc-load-removal.ll | ||
memory-handling.ll | ||
no_speculative_loads_with_asan.ll | ||
noalias.ll | ||
non-local-offset.ll | ||
nonescaping-malloc.ll | ||
null-aliases-nothing.ll | ||
opt-remarks.ll | ||
phi-translate-partial-alias.ll | ||
pr10820.ll | ||
pr12979.ll | ||
pr14166.ll | ||
pr17732.ll | ||
pr17852.ll | ||
pr24397.ll | ||
pr24426.ll | ||
pr25440.ll | ||
pr28562.ll | ||
pr31472.ll | ||
pr31483.ll | ||
pr31491.ll | ||
pr31501.ll | ||
pr31573.ll | ||
pr31594.ll | ||
pr31613.ll | ||
pr31682.ll | ||
pr31758.ll | ||
pre-compare.ll | ||
pre-new-inst.ll | ||
propagate-ir-flags.ll | ||
range.ll | ||
readattrs.ll | ||
rle-must-alias.ll | ||
rle-no-phi-translate.ll | ||
rle-nonlocal.ll | ||
stale-loop-info.ll | ||
storeoverstore.ll | ||
tbaa.ll | ||
unreachable_block_infinite_loop.ll | ||
volatile-nonvolatile.ll |