[PATCH] D103877: [SCEV] Keep common flags when inlining SCEVAddExpr operands.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 8 11:24:55 PDT 2021


fhahn updated this revision to Diff 350670.
fhahn added a comment.

In D103877#2805474 <https://reviews.llvm.org/D103877#2805474>, @mkazantsev wrote:

> As far as I understand what is a `nsw` for multi-argument add, it means that there should be no wrap in between if we add the operands one by one in any order. Imagine the case when `a = c = SINT_MIN` and `b = d = SINT_MAX`. We can say that `a+b` has `<nsw>`, `c+d` has `<nsw>`, and `(a+b) + (c+d)` also has `nsw`. But if we say that `getAddExpr(getAddExpr(a, b, nsw), getAddExpr(c, d, nsw), nsw) = getAddExpr(a, b, c, d, nsw)`, it's not true if we compute the latter as `a + c + b + d`. It will overflow on `a + c` already. Is my understanding wrong here?

Good point, I was not aware that the flags need to apply for any order of evaluation, but it makes sense! I couldn't find any reference of that, do you think it would be worth to spell that out somewhere?

I think for NUW we should not have the same problem, right? I updated the patch to only consider common NUW flags for now.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103877/new/

https://reviews.llvm.org/D103877

Files:
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/test/Analysis/ScalarEvolution/no-wrap-add-exprs.ll
  llvm/test/Analysis/ScalarEvolution/no-wrap-symbolic-becount.ll
  llvm/unittests/Analysis/ScalarEvolutionTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103877.350670.patch
Type: text/x-patch
Size: 8547 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210608/2127afd7/attachment.bin>


More information about the llvm-commits mailing list