[PATCH] D69563: [LV] Strip wrap flags from vectorized reductions

Denis Antrushin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 9 07:36:46 PST 2019


dantrushin added a comment.

In D69563#1739287 <https://reviews.llvm.org/D69563#1739287>, @hsaito wrote:

> Are we essentially saying that any reassociation can't preserve NSW/NUW flags?
>
> Say, X = MAX_INT, Y = -1, and Z = 1. "t1 = X + Y; t2 = t1 + Z" does not cause signed wrap. "t1 = X + Z; t2 = t1 + Y" does, right?
>
> If we agree on that, since vector reduction is a form of reassociation transformation. we need to drop NSW/NUW flags. We need to look at all other reassociation as well. Are we heading to that direction?


I'm not familiar with LLVM enough to answer your question. I hoped you'll tell me.
But I would expect NSW/NUW flags to be correct, since LLVM performs transformation based on them (e.g., throws some subexpressions out)
I also think that (speaking of vectorization) vector reduction is somewhat special/simpler case of reassociation and in my example, not clearing wrap flags leads to incorrect result even in case where
there cannot be any overflow issues in scalar case. 
For other compiler, I would simply clear NSW/NUW flags in `InnerLoopVectorizer::widenInstruction()` and recompute them afresh after vectorization,
but my understanding is that LLVM tries to preserve as much analysis as possible during transformations
I need that bug fixed and I'll be grateful for any suggestions how to fix it properly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69563





More information about the llvm-commits mailing list