llvm.org GIT mirror llvm / 4699964
fix a bug in my licm rewrite when a load from the promoted memory location is being re-stored to the memory location. We would get a dangling pointer from the SSAUpdate data structure and miss a use. This fixes PR8068 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113042 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 9 years ago
2 changed file(s) with 56 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
742742 // Okay, now we can iterate over all the blocks in the loop with uses,
743743 // processing them. Keep track of which loads are loading a live-in value.
744744 SmallVector LiveInLoads;
745 DenseMap ReplacedLoads;
745746
746747 for (unsigned LoopUse = 0, e = LoopUses.size(); LoopUse != e; ++LoopUse) {
747748 Instruction *User = LoopUses[LoopUse];
791792 Value *StoredValue = 0;
792793 for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E; ++II) {
793794 if (LoadInst *L = dyn_cast(II)) {
794 // If this is a load to an unrelated pointer, ignore it.
795 // If this is a load from an unrelated pointer, ignore it.
795796 if (!PointerMustAliases.count(L->getOperand(0))) continue;
796797
797798 // If we haven't seen a store yet, this is a live in use, otherwise
798799 // use the stored value.
799 if (StoredValue)
800 if (StoredValue) {
800801 L->replaceAllUsesWith(StoredValue);
801 else
802 ReplacedLoads[L] = StoredValue;
803 } else {
802804 LiveInLoads.push_back(L);
805 }
803806 continue;
804807 }
805808
845848 Value *NewVal = SSA.GetValueInMiddleOfBlock(ALoad->getParent());
846849 ALoad->replaceAllUsesWith(NewVal);
847850 CurAST->copyValue(ALoad, NewVal);
851 ReplacedLoads[ALoad] = NewVal;
848852 }
849853
850854 // Now that everything is rewritten, delete the old instructions from the body
851855 // of the loop. They should all be dead now.
852856 for (unsigned i = 0, e = LoopUses.size(); i != e; ++i) {
853857 Instruction *User = LoopUses[i];
858
859 // If this is a load that still has uses, then the load must have been added
860 // as a live value in the SSAUpdate data structure for a block (e.g. because
861 // the loaded value was stored later). In this case, we need to recursively
862 // propagate the updates until we get to the real value.
863 if (!User->use_empty()) {
864 Value *NewVal = ReplacedLoads[User];
865 assert(NewVal && "not a replaced load?");
866
867 // Propagate down to the ultimate replacee. The intermediately loads
868 // could theoretically already have been deleted, so we don't want to
869 // dereference the Value*'s.
870 DenseMap::iterator RLI = ReplacedLoads.find(NewVal);
871 while (RLI != ReplacedLoads.end()) {
872 NewVal = RLI->second;
873 RLI = ReplacedLoads.find(NewVal);
874 }
875
876 User->replaceAllUsesWith(NewVal);
877 CurAST->copyValue(User, NewVal);
878 }
879
854880 CurAST->deleteValue(User);
855881 User->eraseFromParent();
856882 }
0 ; RUN: opt -licm %s -disable-output
1
2 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
3 target triple = "x86_64-apple-darwin10.0.0"
4
5
6 ; PR8068
7 @g_12 = external global i8, align 1
8 define void @test1() nounwind ssp {
9 entry:
10 br label %for.body
11
12 for.body: ; preds = %for.cond, %bb.nph
13 store i8 0, i8* @g_12, align 1
14 %tmp6 = load i8* @g_12, align 1
15 br label %for.cond
16
17 for.cond: ; preds = %for.body
18 store i8 %tmp6, i8* @g_12, align 1
19 br i1 false, label %for.cond.for.end10_crit_edge, label %for.body
20
21 for.cond.for.end10_crit_edge: ; preds = %for.cond
22 br label %for.end10
23
24 for.end10: ; preds = %for.cond.for.end10_crit_edge, %entry
25 ret void
26 }