-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[LAA,Loads] Use loop guards and max BTC if needed when checking deref. #155672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2338,23 +2338,15 @@ bool ScalarEvolution::willNotOverflow(Instruction::BinaryOps BinOp, bool Signed, | |
| // Can we use context to prove the fact we need? | ||
| if (!CtxI) | ||
| return false; | ||
| // TODO: Support mul. | ||
| if (BinOp == Instruction::Mul) | ||
| return false; | ||
| auto *RHSC = dyn_cast<SCEVConstant>(RHS); | ||
| // TODO: Lift this limitation. | ||
| if (!RHSC) | ||
| return false; | ||
| APInt C = RHSC->getAPInt(); | ||
| unsigned NumBits = C.getBitWidth(); | ||
| if (BinOp == Instruction::Mul) { | ||
| // Multiplying by 0 or 1 never overflows | ||
| if (C.isZero() || C.isOne()) | ||
| return true; | ||
| if (Signed) | ||
| return false; | ||
| APInt Limit = APInt::getMaxValue(NumBits).udiv(C); | ||
| // To avoid overflow, we need to make sure that LHS <= MAX / C. | ||
| return isKnownPredicateAt(ICmpInst::ICMP_ULE, LHS, getConstant(Limit), | ||
| CtxI); | ||
| } | ||
|
||
| bool IsSub = (BinOp == Instruction::Sub); | ||
| bool IsNegativeConst = (Signed && C.isNegative()); | ||
| // Compute the direction and magnitude by which we need to check overflow. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some cases where we cannot apply loop guards effectively to MaxBTC (if it is an AddRec), but constant BTC computation uses them to get a tighter upper bound.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use the CtxI above as done previously? Would that along with the mulSCEVOverflow change allow to get whats needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately that's not enough in some cases, for example https://github.com/llvm/llvm-project/blob/main/llvm/test/Transforms/LoopVectorize/single_early_exit.ll#L333 where the trip count of the inner loop depends on an induction from the outer loop