[PATCH] D48283: [SCEV] Properly solve quadratic equations

Krzysztof Parzyszek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 23 14:25:38 PDT 2018


kparzysz updated this revision to Diff 156872.
kparzysz added a comment.

Separated solving of a quadratic addrec into two cases:

1. 1. Solving for an exact solution (i.e. calculating unsigned overflow: //q(n) = k * 2^BW//, where 0 is considered a special case of it).
2. 2. Solving for exiting from range (includes signed and unsigned overflow).

Both cases now guarantee that if a valid solution is found (i.e. nullifying the addrec or leaving the range), it will be the smallest non-negative one.

Updated testcase to include checks for calculating failing solutions (i.e. non-minimal, etc.).

In some cases an addrec will only become 0 after a number of signed and unsigned overflows has occurred. `SolveQuadraticAddRecExact` will still return the location of the first unsigned overflow (which will fail validation), however separating it from `SolveQuadraticAddRecRange` makes it easier to change it in the future to look for an exact solution.

I have run this though 100k randomly generated testcases to detect potential crashes (none have occurred).


Repository:
  rL LLVM

https://reviews.llvm.org/D48283

Files:
  lib/Analysis/ScalarEvolution.cpp
  test/Analysis/ScalarEvolution/solve-quadratic-i1.ll
  test/Analysis/ScalarEvolution/solve-quadratic-overflow.ll
  test/Analysis/ScalarEvolution/solve-quadratic.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48283.156872.patch
Type: text/x-patch
Size: 46549 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180723/407a951f/attachment-0001.bin>


More information about the llvm-commits mailing list