[PATCH] D61653: [ConstantRange] Add makeAllowedNoWrapRegion()

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 23 12:00:14 PDT 2019


nikic added a comment.

@lebedev.ri For the mul part I think I have already extracted the reusable parts (the exact nuw/nsw calculation). For add/sub the code for guaranteed and allowed nowrap region is really similar, the only difference is basically that min/max is swapped everywhere. However, I'm not sure how I can share this code in a way that makes sense semantically.

One possibility that comes to mind is to extract more "exact" (single value) helper functions like this:

  static ConstantRange makeExactAddNSWRegion(const APInt &V) {
    APInt SignedMinVal = APInt::getSignedMinValue(V.getBitWidth());
    if (V.isNegative())
      return ConstantRange::getNonEmpty(SignedMinVal - V, SignedMinVal);
    else
      return ConstantRange::getNonEmpty(SignedMinVal, SignedMinVal - V);
  }

and then compute guaranteed/allowed as either an intersection or union of them:

  // guaranteed
  makeExactAddNSWRegion(Other.getSignedMin())
      .intersectWith(Other.getSignedMax())
  // allowed
  makeExactAddNSWRegion(Other.getSignedMin())
      .unionWith(Other.getSignedMax())

That would maybe be semantically cleaner, though less efficient than explicitly constructing the result range.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D61653





More information about the llvm-commits mailing list