When InstCombine simplifies a load -> extract element to gep -> load, place
the new load by the old load instead of by the extract element because
a store could have occurred between the load and extract element.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78891 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index b875420..04c225f 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -12465,12 +12465,14 @@
unsigned AS =
cast<PointerType>(I->getOperand(0)->getType())->getAddressSpace();
Value *Ptr = InsertBitCastBefore(I->getOperand(0),
- PointerType::get(EI.getType(), AS),EI);
+ PointerType::get(EI.getType(), AS),*I);
GetElementPtrInst *GEP =
GetElementPtrInst::Create(Ptr, EI.getOperand(1), I->getName()+".gep");
cast<GEPOperator>(GEP)->setIsInBounds(true);
- InsertNewInstBefore(GEP, EI);
- return new LoadInst(GEP);
+ InsertNewInstBefore(GEP, *I);
+ LoadInst* Load = new LoadInst(GEP, "tmp");
+ InsertNewInstBefore(Load, *I);
+ return ReplaceInstUsesWith(EI, Load);
}
}
if (InsertElementInst *IE = dyn_cast<InsertElementInst>(I)) {