[llvm-dev] Question about ScalarEvolution::isMonotonicPredicateImpl

Sanjoy Das via llvm-dev llvm-dev at lists.llvm.org
Mon Sep 2 09:20:06 PDT 2019


+llvm-dev +Artur Pilipenko

On Mon, Sep 2, 2019 at 5:35 AM Danila Malyutin
<Danila.Malyutin at synopsys.com> wrote:
>
> Hi, I hope you don’t mind if I ask you a few questions regarding SCEV.
> I was reading the isLoopInvariantPredicate code to try and investigate infinite loop bug I was having and I couldn’t quite understand the logic behind isMonotonicPredicate you authored.
>
> The loops exit cond SCEV was reported as:
>
> {3,+,-3}<nuw><nsw><%for.body>
>
> (for UGT comparison with 0), which by isMonotonicPredicate logic is monotonic increasing, since there is NUW flag.
>
> However, if I understood the definition of the monotonic predicate  given in the nearby comment, it’s not the case, since after the first iteration it becomes false (!(0 > 0)), i.e. if anything it’s decreasing.
> Is this correct reasoning or there is something else I’m missing?

If it is NUW then we know that after the first iteration the add rec
will produce poison (which is like undefined behavior).  So for
analyzing monotonicity we can assume the containing loop only executes
iteration 0.

-- Sanjoy

> I’d submit it as a bug but I can’t reproduce it on the latest trunk since there exit SCEV is missing <nuw> flag for whatever reason (and I’m not sure if it’s correct or not, seems like SCEV with different wrapping flags are treated as identical).
>
> I’m writing to you because I saw this change you authored that relates to my problem: https://github.com/llvm-project/llvm/commit/93011351eadeb5343daf5351eaabfd5289e845c3#diff-f9b969568b6cdc33f6ebd61dcf27c612R6744
>
>
>
> --
>
> Danila
>
>


More information about the llvm-dev mailing list