[PATCH] D123337: Possible bug in isKnownPredicateViaConstantRanges

Dangeti Tharun kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 7 13:39:36 PDT 2022


tdangeti created this revision.
tdangeti added reviewers: sanjoy, fhahn, venkataramanan.kumar.llvm, ashutosh.nema, venur.
tdangeti added a project: LLVM.
Herald added subscribers: javed.absar, hiraditya.
Herald added a project: All.
tdangeti requested review of this revision.
Herald added a subscriber: llvm-commits.

I have a problem with getMinusSCEV in isKnownPredicateViaConstantRanges function:

The following is the scenario:
LHS = X,
RHS = -1,

SE already has a computed SCEV (X + 1)<nuw> in the cache. This SCEV corresponds to an instruction at different scope where nuw flag is valid.

I am expecting the "Diff = getMinusSCEV(LHS, RHS)" to be  = (X + 1) instead, I get (X + 1)<nuw> and isKnownNonZero(Diff) returns true.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123337

Files:
  llvm/lib/Analysis/ScalarEvolution.cpp


Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -10534,7 +10534,7 @@
     if (CheckRanges(getSignedRange(LHS), getSignedRange(RHS)) ||
         CheckRanges(getUnsignedRange(LHS), getUnsignedRange(RHS)))
       return true;
-    auto *Diff = getMinusSCEV(LHS, RHS);
+    auto *Diff = getMinusSCEV(LHS, RHS, SCEV::NoWrapMask);
     return !isa<SCEVCouldNotCompute>(Diff) && isKnownNonZero(Diff);
   }



-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123337.421330.patch
Type: text/x-patch
Size: 552 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220407/026da284/attachment.bin>


More information about the llvm-commits mailing list