forked from OSchip/llvm-project
[ScalarEvolution] Add an additional bailout to avoid NOT of pointer.
It's possible in some cases for the LHS to be a pointer where the RHS is not. This isn't directly possible for an icmp, but the analysis mixes up operands of different icmp expressions in some cases. This does not include a test case as the smallest reduced case we've managed is extremely fragile and unlikely to test anything meaningful in the long term. Also add an assertion to getNotSCEV() to make tracking down this sort of issue a bit easier in the future. Fixes https://bugs.llvm.org/show_bug.cgi?id=51787 . Differential Revision: https://reviews.llvm.org/D109546
This commit is contained in:
parent
2a69790bad
commit
bfa2a81e92
|
@ -4127,6 +4127,8 @@ static const SCEV *MatchNotExpr(const SCEV *Expr) {
|
|||
|
||||
/// Return a SCEV corresponding to ~V = -1-V
|
||||
const SCEV *ScalarEvolution::getNotSCEV(const SCEV *V) {
|
||||
assert(!V->getType()->isPointerTy() && "Can't negate pointer");
|
||||
|
||||
if (const SCEVConstant *VC = dyn_cast<SCEVConstant>(V))
|
||||
return getConstant(
|
||||
cast<ConstantInt>(ConstantExpr::getNot(VC->getValue())));
|
||||
|
@ -10672,15 +10674,21 @@ bool ScalarEvolution::isImpliedCondBalancedTypes(
|
|||
if (!isa<SCEVConstant>(FoundRHS) && !isa<SCEVAddRecExpr>(FoundLHS))
|
||||
return isImpliedCondOperands(Pred, LHS, RHS, FoundRHS, FoundLHS, Context);
|
||||
|
||||
// Don't try to getNotSCEV pointers.
|
||||
if (LHS->getType()->isPointerTy() || FoundLHS->getType()->isPointerTy())
|
||||
return false;
|
||||
// There's no clear preference between forms 3. and 4., try both. Avoid
|
||||
// forming getNotSCEV of pointer values as the resulting subtract is
|
||||
// not legal.
|
||||
if (!LHS->getType()->isPointerTy() && !RHS->getType()->isPointerTy() &&
|
||||
isImpliedCondOperands(FoundPred, getNotSCEV(LHS), getNotSCEV(RHS),
|
||||
FoundLHS, FoundRHS, Context))
|
||||
return true;
|
||||
|
||||
// There's no clear preference between forms 3. and 4., try both.
|
||||
return isImpliedCondOperands(FoundPred, getNotSCEV(LHS), getNotSCEV(RHS),
|
||||
FoundLHS, FoundRHS, Context) ||
|
||||
isImpliedCondOperands(Pred, LHS, RHS, getNotSCEV(FoundLHS),
|
||||
getNotSCEV(FoundRHS), Context);
|
||||
if (!FoundLHS->getType()->isPointerTy() &&
|
||||
!FoundRHS->getType()->isPointerTy() &&
|
||||
isImpliedCondOperands(Pred, LHS, RHS, getNotSCEV(FoundLHS),
|
||||
getNotSCEV(FoundRHS), Context))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Unsigned comparison is the same as signed comparison when both the operands
|
||||
|
|
Loading…
Reference in New Issue