[PATCH] D65474: [SCEV] Return zero from computeConstantDifference(X, X)

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 30 15:56:22 PDT 2019


lebedev.ri added a comment.

In D65474#1607424 <https://reviews.llvm.org/D65474#1607424>, @n.bozhenov wrote:

> In D65474#1607285 <https://reviews.llvm.org/D65474#1607285>, @sanjoy wrote:
>
> > > We use computeConstantDifference in some downstream code, and I was surprised to find out that it fails to compute (X - X) difference, unless X is a SCEVAddExpr.
> >
> > Can you use `getMinusSCEV` instead (which should DTRT)?
> >
> > This looks like a small change, having many such cases (especially without unit tests) makes it difficult to refactor code confidently.
>
>
> Hi Sanjoy,
>
> What I need is to check if two arbitrary SCEV expressions are constant distance apart or not, and compute that difference. That's exactly what computeConstantDifference does (except for the (%x - %x) case). I would be ok to use getMinusSCEV, but it does not do the right thing unfortunately. Given {%x, +, 1}<loop1> and {%x, +, 1}<loop2>, getMinusSCEV crashes instead of returning SCEVCouldNotCompute. And I am not aware of any existing API that checks whether two SCEVs are safe to subtract or not.


That already sounds like a test.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D65474





More information about the llvm-commits mailing list