diff options
author | Alexey Bataev <a.bataev@hotmail.com> | 2017-12-12 15:03:17 +0000 |
---|---|---|
committer | Alexey Bataev <a.bataev@hotmail.com> | 2017-12-12 15:03:17 +0000 |
commit | 1daef8a6678a066758e340d10e84f337979a0c6b (patch) | |
tree | d79659423d67a29e632fe447a9dd9ad1e8963b91 /llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp | |
parent | ef3191fcfd4345c0e8b15d428ed895fb500c4c0c (diff) | |
download | bcm5719-llvm-1daef8a6678a066758e340d10e84f337979a0c6b.tar.gz bcm5719-llvm-1daef8a6678a066758e340d10e84f337979a0c6b.zip |
[InstCombine] Fix PR35618: Instcombine hangs on single minmax load bitcast.
If we have pattern `store (load(bitcast(select (cmp(V1, V2), &V1,
&V2)))), bitcast)`, but the load is used in other instructions, it leads
to looping in InstCombiner. Patch adds additional check that all users
of the load instructions are stores and then replaces all uses of load
instruction by the new one with new type.
Reviewers: RKSimon, spatel, majnemer
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D41072
llvm-svn: 320483
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index 01fc1528681..9f00e6f8358 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -1354,9 +1354,24 @@ bool removeBitcastsFromLoadStoreOnMinMax(InstCombiner &IC, StoreInst &SI) { if (!isMinMaxWithLoads(LoadAddr)) return false; + if (!all_of(LI->users(), [LI](User *U) { + auto *SI = dyn_cast<StoreInst>(U); + return SI && SI->getPointerOperand() != LI && + !SI->getPointerOperand()->isSwiftError(); + })) + return false; + + IC.Builder.SetInsertPoint(LI); LoadInst *NewLI = combineLoadToNewType( IC, *LI, LoadAddr->getType()->getPointerElementType()); - combineStoreToNewValue(IC, SI, NewLI); + // Replace all the stores with stores of the newly loaded value. + for (auto *UI : LI->users()) { + auto *SI = cast<StoreInst>(UI); + IC.Builder.SetInsertPoint(SI); + combineStoreToNewValue(IC, *SI, NewLI); + IC.eraseInstFromFunction(*SI); + } + IC.Worklist.Add(LI); return true; } @@ -1385,7 +1400,7 @@ Instruction *InstCombiner::visitStoreInst(StoreInst &SI) { return eraseInstFromFunction(SI); if (removeBitcastsFromLoadStoreOnMinMax(*this, SI)) - return eraseInstFromFunction(SI); + return nullptr; // Replace GEP indices if possible. if (Instruction *NewGEPI = replaceGEPIdxWithZero(*this, Ptr, SI)) { |