I guess the problem here is that the AddRec is missing overflow flags, which means the expression may overflow and if that happens, the folded expression may not be equivalent to the original one in all cases.
If the AddRec has the overflow flags set, it looks something like `{16,+,8}<nuw><nsw><%loop>`. I’d check if the original IR had nuw/nsw flags on add instruction for the AddRec. The way those flags are managed in SCEV are sometimes a bit surprising, because the expressions are not tied to a specific location and the flags need to be valid for the whole scope the expression can be evaluated in.
Cheers,
Florian
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
> On Jul 31, 2020, at 12:34, Stefanos Baziotis <stefanos...@gmail.com> wrote:
>
> Indeed you're right, thanks! I need a nuw (which I have to invent, with a run-time check, since it doesn't exist in the original but anyway).
>
Right, I guess in your example, the flags on the add depend on the exact bound of the loop, which is omitted.