[PATCH] D109782: [SCEV] Stop applying contextual flags in applyLoopGuards
Philip Reames via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 14 13:33:50 PDT 2021
reames created this revision.
reames added reviewers: mkazantsev, fhahn, efriedma.
Herald added subscribers: bollu, hiraditya, mcrosier.
reames requested review of this revision.
Herald added a project: LLVM.
This fixes a violation of the wrap flag rules introduced in c4048d8f <https://reviews.llvm.org/rGc4048d8f50aaf2c4c13b8d3e138abc34a22da754>. As noted in the original review, the NUW is legal to infer from the structure of the replacee, but a) there's no test coverage, and b) this should be done generically for all multiplies.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D109782
Files:
llvm/lib/Analysis/ScalarEvolution.cpp
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -13495,6 +13495,11 @@
const SCEV *ScalarEvolution::applyLoopGuards(const SCEV *Expr, const Loop *L) {
auto CollectCondition = [&](ICmpInst::Predicate Predicate, const SCEV *LHS,
const SCEV *RHS, ValueToSCEVMapTy &RewriteMap) {
+ // WARNING: It is generally unsound to apply any wrap flags to the proposed
+ // replacement SCEV which isn't directly implied by the replacee SCEV. In
+ // particular, using contextual facts to imply flags is *NOT* legal. See
+ // the scoping rules for flags in the header to understand why.
+
// If we have LHS == 0, check if LHS is computing a property of some unknown
// SCEV %v which we can rewrite %v to express explicitly.
const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(RHS);
@@ -13507,10 +13512,7 @@
if (matchURem(LHS, URemLHS, URemRHS)) {
if (const SCEVUnknown *LHSUnknown = dyn_cast<SCEVUnknown>(URemLHS)) {
Value *V = LHSUnknown->getValue();
- auto Multiple =
- getMulExpr(getUDivExpr(URemLHS, URemRHS), URemRHS,
- (SCEV::NoWrapFlags)(SCEV::FlagNUW | SCEV::FlagNSW));
- RewriteMap[V] = Multiple;
+ RewriteMap[V] = getMulExpr(getUDivExpr(URemLHS, URemRHS), URemRHS);
return;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109782.372550.patch
Type: text/x-patch
Size: 1503 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210914/0c8a98b1/attachment.bin>
More information about the llvm-commits
mailing list