[SCEV] Constant fold MultExpr before applying depth limit.
authorDenis Antrushin <dantrushin@gmail.com>
Wed, 13 May 2020 17:55:07 +0000 (20:55 +0300)
committerDenis Antrushin <dantrushin@gmail.com>
Fri, 22 May 2020 15:34:32 +0000 (18:34 +0300)
commit5451289abafd8879adf892ede7660ce8c46c6a6f
treeb7439f516ab6193a378fee466af8184ba10f3455
parent2419dce5d1c6338012002a9358c7c8fc6a7baca5
[SCEV] Constant fold MultExpr before applying depth limit.

Summary:
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 not apply depth limit to all constant
operands expression, allowing them to be folded.

Reviewers: reames, mkazantsev

Subscribers: hiraditya, javed.absar, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D79893
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/depth-limit-overrun.ll [new file with mode: 0644]
llvm/test/Analysis/ScalarEvolution/limit-depth.ll