[PATCH] D37265: [SCEV] Ensure ScalarEvolution::createAddRecFromPHIWithCastsImpl properly handles out of range truncations of the start and accum values

Daniel Neilson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 29 10:04:08 PDT 2017


dneilson created this revision.

When constructing the predicate https://reviews.llvm.org/P1 in ScalarEvolution::createAddRecFromPHIWithCastsImpl() it is possible
for the PHISCEV from which the predicate is constructed to be a SCEVConstant instead of a SCEVAddRec. If
this happens, then the cast<SCEVAddRec>(PHISCEV) in the code will assert.

Such a PHISCEV is possible if either the start value or the accumulator value is a constant value
that not equal to its truncated value, and if the truncated value is zero.

This patch adds tests that demonstrate the cast<> assertion, and fixes this problem by checking
whether the PHISCEV is a constant before constructing the https://reviews.llvm.org/P1 predicate; if it is, then https://reviews.llvm.org/P1 is
equivalent to one of https://reviews.llvm.org/P2 or https://reviews.llvm.org/P3. Additionally, if we know that the start value or accumulator
value are constants then we check whether the https://reviews.llvm.org/P2 and/or https://reviews.llvm.org/P3 predicates are known false at compile
time; if either is, then we bail out of constructing the AddRec.

****NOTE****
 This patch is not in its final form. There are some options that we can take with it that I was
not entirely sure on the best way-forward with. I would like to settle on an option as part of
this review with reviewer input. To wit:

- Do we even want to check https://reviews.llvm.org/P2 and https://reviews.llvm.org/P3 for known false? Strikes me as a good idea, but it's not strictly necessary to avoid the cast<> assertion.
- If so, how? I have two options in the patch: 1) Check only the constant case; or (2) check more generically if the predicate is known false.


https://reviews.llvm.org/D37265

Files:
  lib/Analysis/ScalarEvolution.cpp
  test/Analysis/ScalarEvolution/overflow-addrec.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37265.113106.patch
Type: text/x-patch
Size: 6320 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170829/c3a07120/attachment.bin>


More information about the llvm-commits mailing list