[PATCH] D64869: [SCEV] get more accurate range for AddExpr with NW flag
Philip Reames via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 17 09:18:07 PDT 2019
reames requested changes to this revision.
reames added inline comments.
This revision now requires changes to proceed.
================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:5568
if (const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(S)) {
- ConstantRange X = getRangeRef(Add->getOperand(0), SignHint);
- for (unsigned i = 1, e = Add->getNumOperands(); i != e; ++i)
- X = X.add(getRangeRef(Add->getOperand(i), SignHint));
+ ConstantRange X(BitWidth, /*isFullSet=*/true);
+ if (maskFlags(Add->getNoWrapFlags(), SCEV::FlagNSW) == SCEV::FlagNSW) {
----------------
Stylistically, it would be much cleaner to add a function to ConstantRange with the signature
CR add(CR, NoWrapKind)
================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:5570
+ if (maskFlags(Add->getNoWrapFlags(), SCEV::FlagNSW) == SCEV::FlagNSW) {
+ if (auto *C = dyn_cast<SCEVConstant>(Add->getOperand(0))) {
+ X = getRangeRef(Add->getOperand(1), SignHint);
----------------
Your code is incorrect as implemented. There's no requirement that a SCEVAddExpr have only two operands.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D64869/new/
https://reviews.llvm.org/D64869
More information about the llvm-commits
mailing list