[PATCH] D88015: [SCEV] Support unsigned predicates in isKnownPredicateViaNoOverflow

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 21 06:41:31 PDT 2020


lebedev.ri accepted this revision.
lebedev.ri added a comment.
This revision is now accepted and ready to land.

In D88015#2285077 <https://reviews.llvm.org/D88015#2285077>, @lebedev.ri wrote:

> What about swapped cases, like `(X + C)<nuw> u<= X`?

Disregard. We return true if the predicate is known-true, and false in all other cases.
Looks reasonable to me.



================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:9302-9303
+  case ICmpInst::ICMP_ULE:
+    // X u<= (X + C)<nuw> for any C
+    if (MatchBinaryAddToConst(RHS, LHS, C, SCEV::FlagNUW))
+      return true;
----------------
It is unclear how much it matters in practice, but
i don't think `C` needs to be a constant,
which means that we only need to check that RHS is an `NUW` `SCEVAddExpr`, and that
`any_of(AE->operands(), [L](SCEV*Op){ return Op == L; })`.


================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:9311
+  case ICmpInst::ICMP_ULT:
+    // X u< (X + C)<nuw> if C != 0
+    if (MatchBinaryAddToConst(RHS, LHS, C, SCEV::FlagNUW) && !C.isNullValue())
----------------
Likely even less real-world, but likewise, i'd think we want to check
that RHS is a NUW `SCEVAddExpr`, `any_of(AE->operands(), [L](SCEV*Op){ return Op == L; })`,
and that `(AE - L) != 0`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88015/new/

https://reviews.llvm.org/D88015



More information about the llvm-commits mailing list