llvm.org GIT mirror llvm / 01ad70a
[GVN] When merging blocks update LoopInfo if it's available If LoopInfo is available during GVN, BasicAA will use it. However MergeBlockIntoPredecessor does not update LI as it merges blocks. This didn't use to cause problems because LI was freed before GVN/BasicAA. Now with OptimizationRemarkEmitter, the lifetime of LI is extended so LI needs to be kept up-to-date during GVN. Differential Revision: https://reviews.llvm.org/D27288 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288307 91177308-0d34-0410-b5e6-96231b3b80d8 Adam Nemet 4 years ago
3 changed file(s) with 62 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
2121 #include "llvm/ADT/SmallPtrSet.h"
2222 #include "llvm/Analysis/AliasAnalysis.h"
2323 #include "llvm/Analysis/AssumptionCache.h"
24 #include "llvm/Analysis/LoopInfo.h"
2425 #include "llvm/Analysis/MemoryDependenceAnalysis.h"
2526 #include "llvm/IR/Dominators.h"
2627 #include "llvm/IR/IntrinsicInst.h"
133134
134135 bool runImpl(Function &F, AssumptionCache &RunAC, DominatorTree &RunDT,
135136 const TargetLibraryInfo &RunTLI, AAResults &RunAA,
136 MemoryDependenceResults *RunMD);
137 MemoryDependenceResults *RunMD, LoopInfo *LI);
137138
138139 /// Push a new Value to the LeaderTable onto the list for its value number.
139140 void addToLeaderTable(uint32_t N, Value *V, const BasicBlock *BB) {
585585 auto &TLI = AM.getResult(F);
586586 auto &AA = AM.getResult(F);
587587 auto &MemDep = AM.getResult(F);
588 bool Changed = runImpl(F, AC, DT, TLI, AA, &MemDep);
588 auto *LI = AM.getCachedResult(F);
589 bool Changed = runImpl(F, AC, DT, TLI, AA, &MemDep, LI);
589590 if (!Changed)
590591 return PreservedAnalyses::all();
591592 PreservedAnalyses PA;
21782179 /// runOnFunction - This is the main transformation entry point for a function.
21792180 bool GVN::runImpl(Function &F, AssumptionCache &RunAC, DominatorTree &RunDT,
21802181 const TargetLibraryInfo &RunTLI, AAResults &RunAA,
2181 MemoryDependenceResults *RunMD) {
2182 MemoryDependenceResults *RunMD, LoopInfo *LI) {
21822183 AC = &RunAC;
21832184 DT = &RunDT;
21842185 VN.setDomTree(DT);
21952196 for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ) {
21962197 BasicBlock *BB = &*FI++;
21972198
2198 bool removedBlock =
2199 MergeBlockIntoPredecessor(BB, DT, /* LoopInfo */ nullptr, MD);
2200 if (removedBlock) ++NumGVNBlocks;
2199 bool removedBlock = MergeBlockIntoPredecessor(BB, DT, LI, MD);
2200 if (removedBlock)
2201 ++NumGVNBlocks;
22012202
22022203 Changed |= removedBlock;
22032204 }
26922693 if (skipFunction(F))
26932694 return false;
26942695
2696 auto *LIWP = getAnalysisIfAvailable();
2697
26952698 return Impl.runImpl(
26962699 F, getAnalysis().getAssumptionCache(F),
26972700 getAnalysis().getDomTree(),
26982701 getAnalysis().getTLI(),
26992702 getAnalysis().getAAResults(),
27002703 NoLoads ? nullptr
2701 : &getAnalysis().getMemDep());
2704 : &getAnalysis().getMemDep(),
2705 LIWP ? &LIWP->getLoopInfo() : nullptr);
27022706 }
27032707
27042708 void getAnalysisUsage(AnalysisUsage &AU) const override {
0 ; RUN: opt -loops -gvn -S < %s | FileCheck %s
1
2 ; This used to fail with ASAN enabled and if for some reason LoopInfo remained
3 ; available during GVN. In this case BasicAA will use LI but
4 ; MergeBlockIntoPredecessor in GVN failed to update LI.
5
6 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
7
8 %struct.wibble.1028 = type { i32, i32, %struct.barney.881 }
9 %struct.barney.881 = type { %struct.zot.882 }
10 %struct.zot.882 = type { [64 x i8] }
11
12 ; Function Attrs: argmemonly
13 declare void @snork.1(i8*) local_unnamed_addr #0
14
15 define hidden zeroext i1 @eggs(%struct.wibble.1028* %arg, i1 %arg2) unnamed_addr align 2 {
16 bb:
17 br i1 %arg2, label %bb14, label %bb3
18
19 bb3: ; preds = %bb
20 %tmp = getelementptr inbounds %struct.wibble.1028, %struct.wibble.1028* %arg, i64 0, i32 2, i32 0, i32 0, i64 0
21 %tmp5 = bitcast i8* %tmp to %struct.wibble.1028**
22 br label %bb6
23
24 bb6: ; preds = %bb12, %bb3
25 br label %bb7
26
27 bb7: ; preds = %bb6
28 br i1 undef, label %bb11, label %bb8
29
30 bb8: ; preds = %bb7
31 %tmp9 = load %struct.wibble.1028*, %struct.wibble.1028** %tmp5, align 8
32 ; CHECK: %tmp9 = load %struct.wibble.1028*, %struct.wibble.1028** %tmp5, align 8
33 %tmp10 = bitcast %struct.wibble.1028* %tmp9 to i8*
34 br label %bb12
35
36 bb11: ; preds = %bb7
37 br label %bb12
38
39 bb12: ; preds = %bb11, %bb8
40 %tmp13 = phi i8* [ %tmp, %bb11 ], [ %tmp10, %bb8 ]
41 call void @snork.1(i8* %tmp13) #1
42 br label %bb6
43
44 bb14: ; preds = %bb
45 ret i1 false
46 }
47
48 attributes #0 = { argmemonly }
49 attributes #1 = { nounwind }