diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-12-07 12:21:22 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-12-31 16:17:14 +0100 |
commit | 27a0795943fee0f30b995fe5165428afc2dfd402 (patch) | |
tree | 078a02a51d3766d64e07039d5cb174ffaa313b04 /llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | |
parent | f5b7dd3c9ec041480d28d203f22929f0f0809d6e (diff) | |
download | bcm5719-llvm-27a0795943fee0f30b995fe5165428afc2dfd402.tar.gz bcm5719-llvm-27a0795943fee0f30b995fe5165428afc2dfd402.zip |
[InstCombine] Fix infinite loop due to bitcast <-> phi transforms
Fix for https://bugs.llvm.org/show_bug.cgi?id=44245.
The optimizeBitCastFromPhi() and FoldPHIArgOpIntoPHI() end up
fighting against each other, because optimizeBitCastFromPhi()
assumes that bitcasts of loads will get folded. This doesn't happen
here, because a dangling phi node prevents the one-use fold in
https://github.com/llvm/llvm-project/blob/master/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp#L620-L628 from triggering.
This patch fixes the issue by adding manually removing the old phis.
Differential Revision: https://reviews.llvm.org/D71164
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index 3ba56bbe53e..446e6758096 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -2370,6 +2370,12 @@ Instruction *InstCombiner::optimizeBitCastFromPhi(CastInst &CI, PHINode *PN) { llvm_unreachable("all uses should be handled"); } } + + // At this point the old phi has either no users, or is only used + // in other old phis. Replace with undef to break circles and remove + // the instruction. + replaceInstUsesWith(*OldPN, UndefValue::get(OldPN->getType())); + eraseInstFromFunction(*OldPN); } return RetVal; |