[llvm] [SCEV] Prove no-self-wrap from negative power of two step (PR #101416)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 1 12:17:44 PDT 2024


================
@@ -10857,7 +10861,11 @@ bool ScalarEvolution::isKnownToBeAPowerOfTwo(const SCEV *S, bool OrZero) {
   auto *Mul = dyn_cast<SCEVMulExpr>(S);
   if (!Mul)
     return false;
-  return all_of(Mul->operands(), NonRecursive) && (OrZero || isKnownNonZero(S));
+  return all_of(Mul->operands(), NonRecursive) &&
+         (OrZero || isKnownNonZero(S)) &&
+         (!OrNegative || llvm::count_if(Mul->operands(), [this](const SCEV *S) {
----------------
nikic wrote:

I don't get why we need this condition.

If OrNegative=false the previous code is correct. If OrNegative=true, then we're fine with either a positive or negative power of two. So even if we have two negative factors, the result will be a positive power of two (or zero) and still be fine.

https://github.com/llvm/llvm-project/pull/101416


More information about the llvm-commits mailing list