Skip to content

Commit

Permalink
scevexpander: get type information from scev operands
Browse files Browse the repository at this point in the history
`visitGEPPointer` used to get its type information from the expanded
first operand as a Value, however, this proved to be too coarse in some
cases.

Fixes: leaningtech/cheerp-meta#121
  • Loading branch information
Hyxogen authored and yuri91 committed Feb 12, 2024
1 parent 2a65996 commit 6818189
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,7 @@ Value *SCEVExpander::visitPtrToIntExpr(const SCEVPtrToIntExpr *S) {

Value *SCEVExpander::visitGEPPointer(const SCEVGEPPointer *S) {
llvm::Value* ptrVal = expand(S->getOperand(0));
llvm::Type* ptrType = ptrVal->getType();
llvm::Type* ptrType = S->getOperand(0)->getType();
SmallVector<Value *, 4> GepIndices;
// The pointer is implicitly dereferenced
GepIndices.push_back(ConstantInt::get(Type::getInt32Ty(SE.getContext()), 0));
Expand All @@ -1692,8 +1692,9 @@ Value *SCEVExpander::visitGEPPointer(const SCEVGEPPointer *S) {
sTy = directBase;
}
gepType = sTy;
ptrVal = Builder.CreateBitCast(ptrVal, sTy->getPointerTo());
}
if (ptrVal->getType() != gepType->getPointerTo())
ptrVal = Builder.CreateBitCast(ptrVal, gepType->getPointerTo());
Value *GEP = Builder.CreateGEP(gepType, ptrVal, GepIndices, "safescevgep");
rememberInstruction(GEP);
return GEP;
Expand Down

0 comments on commit 6818189

Please sign in to comment.