Do not return success after checking only the FIRST USE of a gep instruction.

Instead, check all uses.
This fixes bug: ScalarRepl/2003-09-12-IncorrectPromote.ll
This also fixes the miscompilation of Ptrdist/bc


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8493 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2003-09-12 16:02:12 +00:00
parent 69d903d5be
commit 8fce16ef1a

View File

@ -234,8 +234,11 @@ bool SROA::isSafeElementUse(Value *Ptr) {
I != E; ++I) { I != E; ++I) {
Instruction *User = cast<Instruction>(*I); Instruction *User = cast<Instruction>(*I);
switch (User->getOpcode()) { switch (User->getOpcode()) {
case Instruction::Load: return true; case Instruction::Load: break;
case Instruction::Store: return User->getOperand(0) != Ptr; case Instruction::Store:
// Store is ok if storing INTO the pointer, not storing the pointer
if (User->getOperand(0) == Ptr) return false;
break;
case Instruction::GetElementPtr: { case Instruction::GetElementPtr: {
GetElementPtrInst *GEP = cast<GetElementPtrInst>(User); GetElementPtrInst *GEP = cast<GetElementPtrInst>(User);
if (GEP->getNumOperands() > 1) { if (GEP->getNumOperands() > 1) {
@ -243,7 +246,8 @@ bool SROA::isSafeElementUse(Value *Ptr) {
!cast<Constant>(GEP->getOperand(1))->isNullValue()) !cast<Constant>(GEP->getOperand(1))->isNullValue())
return false; // Using pointer arithmetic to navigate the array... return false; // Using pointer arithmetic to navigate the array...
} }
return isSafeElementUse(GEP); if (!isSafeElementUse(GEP)) return false;
break;
} }
default: default:
DEBUG(std::cerr << " Transformation preventing inst: " << *User); DEBUG(std::cerr << " Transformation preventing inst: " << *User);