summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorAlexey Bataev <a.bataev@hotmail.com>2017-12-11 19:11:16 +0000
committerAlexey Bataev <a.bataev@hotmail.com>2017-12-11 19:11:16 +0000
commitec128ace8a4d7fdcdd9ffc10a94facbbda518c87 (patch)
treefb5a6c0c20d62f0fcda8c054b3ccf8c39745420c /llvm/lib/Transforms
parentba874922a2e039f6ef7e68e69e0a8dfbbd9f5561 (diff)
downloadbcm5719-llvm-ec128ace8a4d7fdcdd9ffc10a94facbbda518c87.tar.gz
bcm5719-llvm-ec128ace8a4d7fdcdd9ffc10a94facbbda518c87.zip
[InstCombine] Fix PR35618: Instcombine hangs on single minmax load bitcast.
Summary: 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: 320407
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index 29e0a091aa7..a729981a549 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -1344,9 +1344,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.eraseInstFromFunction(*LI);
return true;
}
@@ -1375,7 +1390,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)) {
OpenPOWER on IntegriCloud