Skip to content

Commit

Permalink
improve GEP check
Browse files Browse the repository at this point in the history
adds a check to see if the GEP with more then 2 operands is done on a pointer or an array, if this is the case we can compare the pointer/array and its offset directly without dereferencing the pointers
  • Loading branch information
rvan-mee committed Aug 15, 2024
1 parent 4ed1d4d commit 3dd1496
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions llvm/lib/CheerpWriter/CheerpWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1653,8 +1653,10 @@ void CheerpWriter::compileEqualPointersComparison(const llvm::Value* lhs, const
// NOTE: For any pointer-to-immutable, converting to CO is actually a dereference. (base[offset] in both cases)
// PA enforces that comparisons between pointers-to-immutable (which include pointers-to-pointers)
// need a SPLIT_REGULAR kind. Make sure to also use SPLIT_REGULAR if one kind is CONSTANT (e.g. null)
else if((lhsKind == REGULAR || lhsKind == SPLIT_REGULAR || lhsKind == RAW ||lhsKind == CONSTANT || (isGEP(lhs) && cast<User>(lhs)->getNumOperands()==2)) &&
(rhsKind == REGULAR || rhsKind == SPLIT_REGULAR || rhsKind == RAW ||rhsKind == CONSTANT || (isGEP(rhs) && cast<User>(rhs)->getNumOperands()==2)))
else if ((lhsKind == REGULAR || lhsKind == SPLIT_REGULAR || lhsKind == RAW ||lhsKind == CONSTANT ||
(isGEP(lhs) && (cast<User>(lhs)->getNumOperands()==2 || getGEPContainerType(cast<User>(lhs))->isArrayTy() || getGEPContainerType(cast<User>(lhs))->isPointerTy()))) &&
(rhsKind == REGULAR || rhsKind == SPLIT_REGULAR || rhsKind == RAW ||rhsKind == CONSTANT ||
(isGEP(rhs) && (cast<User>(rhs)->getNumOperands()==2 || getGEPContainerType(cast<User>(rhs))->isArrayTy() || getGEPContainerType(cast<User>(rhs))->isPointerTy()))))
{
assert(lhsKind != COMPLETE_OBJECT || !isa<Instruction>(lhs) ||
isInlineable(*cast<Instruction>(lhs), PA));
Expand Down

0 comments on commit 3dd1496

Please sign in to comment.