diff options
author | Duncan Sands <baldrick@free.fr> | 2012-03-04 13:25:19 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2012-03-04 13:25:19 +0000 |
commit | 190e5a3314808fc126f18119315ce986d0689089 (patch) | |
tree | 4e3c82a9f94f9a2f2982db16d687053759a5d9e6 /lib/Transforms/Scalar/GVN.cpp | |
parent | ed7692a136a9bcf513b91b7b5eb33a1e2d83e7ee (diff) |
Nick pointed out on IRC that GVN's propagateEquality wasn't propagating
equalities into phi node operands for which the equality is known to
hold in the incoming basic block. That's because replaceAllDominatedUsesWith
wasn't handling phi nodes correctly in general (that this didn't give wrong
results was just luck: the specific way GVN uses replaceAllDominatedUsesWith
precluded wrong changes to phi nodes).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152006 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/GVN.cpp')
-rw-r--r-- | lib/Transforms/Scalar/GVN.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index 37e970b8b6..dc13edff25 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -1953,7 +1953,17 @@ unsigned GVN::replaceAllDominatedUsesWith(Value *From, Value *To, for (Value::use_iterator UI = From->use_begin(), UE = From->use_end(); UI != UE; ) { Use &U = (UI++).getUse(); - if (DT->dominates(Root, cast<Instruction>(U.getUser())->getParent())) { + + // If From occurs as a phi node operand then the use implicitly lives in the + // corresponding incoming block. Otherwise it is the block containing the + // user that must be dominated by Root. + BasicBlock *UsingBlock; + if (PHINode *PN = dyn_cast<PHINode>(U.getUser())) + UsingBlock = PN->getIncomingBlock(U); + else + UsingBlock = cast<Instruction>(U.getUser())->getParent(); + + if (DT->dominates(Root, UsingBlock)) { U.set(To); ++Count; } |