[PATCH] D79893: [SCEV] Constant fold MultExpr before applying depth limit.

Denis Antrushin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 13 11:58:03 PDT 2020


dantrushin created this revision.
dantrushin added reviewers: reames, mkazantsev.
Herald added subscribers: llvm-commits, javed.absar, hiraditya.
Herald added a project: LLVM.

Users of SCEV reasonably assume that multiplication of two constant
SCEVs will in turn be constant.
However, that is not always the case:
First, we can get here with reached depth limit, and will create
MultExpr SCEV `C1 * C2` and cache it.
Then, we can get here with the same operands, but with small depth
level. But this time we will find existing MultExpr SCEV and return
it, instead of expected constant SCEV.

This patch changes getMultExpr to first try constant folding of SCEV
and then apply depth limit, just like getAddExpr does.
It might result in further get{Add|Mult}Expr calls, but they would
perform constant folding only and should not be too expensive.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79893

Files:
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/test/Analysis/ScalarEvolution/depth-limit-overrun.ll
  llvm/test/Analysis/ScalarEvolution/limit-depth.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79893.263802.patch
Type: text/x-patch
Size: 4628 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200513/3bbab1b6/attachment.bin>


More information about the llvm-commits mailing list