In cases where a pointer value is an operand of a multiplication or

division operation, don't attempt to use the operation's value as
the base of a getelementptr. This fixes PR4271.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72422 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman
2009-05-26 17:41:16 +00:00
parent 74807f2520
commit f876ad0a70
2 changed files with 103 additions and 3 deletions

View File

@ -448,9 +448,14 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) {
ExposePointerBase(Base, RestArray[0], SE);
// If we found a pointer, expand the AddRec with a GEP.
if (const PointerType *PTy = dyn_cast<PointerType>(Base->getType())) {
Value *StartV = expand(Base);
assert(StartV->getType() == PTy && "Pointer type mismatch for GEP!");
return expandAddToGEP(RestArray, RestArray+1, PTy, Ty, StartV);
// Make sure the Base isn't something exotic, such as a multiplied
// or divided pointer value. In those cases, the result type isn't
// actually a pointer type.
if (!isa<SCEVMulExpr>(Base) && !isa<SCEVUDivExpr>(Base)) {
Value *StartV = expand(Base);
assert(StartV->getType() == PTy && "Pointer type mismatch for GEP!");
return expandAddToGEP(RestArray, RestArray+1, PTy, Ty, StartV);
}
}
}