llvm.org GIT mirror llvm / 6fbc196
Move the re-sort of invalidated NonLocalPointerDeps cache earlier so that all code paths get it. PR4256 was about a case where the phi translation loop would find all preds in the Visited cache, so it could get by without re-sorting the NonLocalPointerDeps cache. Fix this by resorting it earlier, there is no reason not to do this. This patch inspired by Jakub Staszak's patch. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75476 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
2 changed file(s) with 82 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
730730 // If we do need to do phi translation, then there are a bunch of different
731731 // cases, because we have to find a Value* live in the predecessor block. We
732732 // know that PtrInst is defined in this block at least.
733
734 // We may have added values to the cache list before this PHI translation.
735 // If so, we haven't done anything to ensure that the cache remains sorted.
736 // Sort it now (if needed) so that recursive invocations of
737 // getNonLocalPointerDepFromBB and other routines that could reuse the cache
738 // value will only see properly sorted cache arrays.
739 if (Cache && NumSortedEntries != Cache->size()) {
740 std::sort(Cache->begin(), Cache->end());
741 NumSortedEntries = Cache->size();
742 }
733743
734744 // If this is directly a PHI node, just use the incoming values for each
735745 // pred as the phi translated version.
736746 if (PHINode *PtrPHI = dyn_cast(PtrInst)) {
747 Cache = 0;
748
737749 for (BasicBlock **PI = PredCache->GetPreds(BB); *PI; ++PI) {
738750 BasicBlock *Pred = *PI;
739751 Value *PredPtr = PtrPHI->getIncomingValueForBlock(Pred);
758770 goto PredTranslationFailure;
759771 }
760772
761 // We may have added values to the cache list before this PHI
762 // translation. If so, we haven't done anything to ensure that the
763 // cache remains sorted. Sort it now (if needed) so that recursive
764 // invocations of getNonLocalPointerDepFromBB that could reuse the cache
765 // value will only see properly sorted cache arrays.
766 if (Cache && NumSortedEntries != Cache->size())
767 std::sort(Cache->begin(), Cache->end());
768 Cache = 0;
769
770773 // FIXME: it is entirely possible that PHI translating will end up with
771774 // the same value. Consider PHI translating something like:
772775 // X = phi [x, bb1], [y, bb2]. PHI translating for bb1 doesn't *need*
778781 Result, Visited))
779782 goto PredTranslationFailure;
780783 }
781
784
782785 // Refresh the CacheInfo/Cache pointer so that it isn't invalidated.
783786 CacheInfo = &NonLocalPointerDeps[CacheKey];
784787 Cache = &CacheInfo->second;
805808 CacheInfo = &NonLocalPointerDeps[CacheKey];
806809 Cache = &CacheInfo->second;
807810 NumSortedEntries = Cache->size();
808 } else if (NumSortedEntries != Cache->size()) {
809 std::sort(Cache->begin(), Cache->end());
810 NumSortedEntries = Cache->size();
811 }
812
811 }
812
813813 // Since we did phi translation, the "Cache" set won't contain all of the
814814 // results for the query. This is ok (we can still use it to accelerate
815815 // specific block queries) but we can't do the fastpath "return all
0 ; RUN: llvm-as < %s | opt -gvn | llvm-dis
1 ; PR4256
2 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
3 target triple = "i386-linux-gnu"
4 %llvm.dbg.anchor.type = type { i32, i32 }
5 %struct.cset = type { i8*, i8, i8, i32, i8* }
6 %struct.lmat = type { %struct.re_guts*, i32, %llvm.dbg.anchor.type*, i8*, i8*, i8*, i8*, i8**, i32, i8*, i8*, i8*, i8*, i8* }
7 %struct.re_guts = type { i32*, %struct.cset*, i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8*, i8*, i32, i32, i32, i32, [1 x i8] }
8
9 define i8* @lbackref(%struct.lmat* %m, i8* %start, i8* %stop, i32 %startst, i32 %stopst, i32 %lev, i32 %rec) nounwind {
10 entry:
11 br label %bb63
12
13 bb: ; preds = %bb63
14 switch i32 0, label %bb62 [
15 i32 268435456, label %bb2
16 i32 805306368, label %bb9
17 i32 -1610612736, label %bb51
18 ]
19
20 bb2: ; preds = %bb
21 br label %bb62
22
23 bb9: ; preds = %bb
24 %0 = load i8* %sp.1, align 1 ; [#uses=0]
25 br label %bb62
26
27 bb51: ; preds = %bb
28 %1 = load i8* %sp.1, align 1 ; [#uses=0]
29 ret i8* null
30
31 bb62: ; preds = %bb9, %bb2, %bb
32 br label %bb63
33
34 bb63: ; preds = %bb84, %bb69, %bb62, %entry
35 %sp.1 = phi i8* [ null, %bb62 ], [ %sp.1.lcssa, %bb84 ], [ %start, %entry ], [ %sp.1.lcssa, %bb69 ] ; [#uses=3]
36 br i1 false, label %bb, label %bb65
37
38 bb65: ; preds = %bb63
39 %sp.1.lcssa = phi i8* [ %sp.1, %bb63 ] ; [#uses=4]
40 br i1 false, label %bb66, label %bb69
41
42 bb66: ; preds = %bb65
43 ret i8* null
44
45 bb69: ; preds = %bb65
46 switch i32 0, label %bb108.loopexit2.loopexit.loopexit [
47 i32 1342177280, label %bb63
48 i32 1476395008, label %bb84
49 i32 1879048192, label %bb104
50 i32 2013265920, label %bb93
51 ]
52
53 bb84: ; preds = %bb69
54 %2 = tail call i8* @lbackref(%struct.lmat* %m, i8* %sp.1.lcssa, i8* %stop, i32 0, i32 %stopst, i32 0, i32 0) nounwind ; [#uses=0]
55 br label %bb63
56
57 bb93: ; preds = %bb69
58 ret i8* null
59
60 bb104: ; preds = %bb69
61 %sp.1.lcssa.lcssa33 = phi i8* [ %sp.1.lcssa, %bb69 ] ; [#uses=0]
62 unreachable
63
64 bb108.loopexit2.loopexit.loopexit: ; preds = %bb69
65 ret i8* null
66 }