[llvm] [LV] Use IVUpdateMayOverflow to set HasNUW. (PR #111758)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 9 13:40:03 PDT 2024


================
@@ -8943,9 +8943,12 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
 
   DebugLoc DL = getDebugLocFromInstOrOperands(Legal->getPrimaryInduction());
   TailFoldingStyle Style = CM.getTailFoldingStyle(IVUpdateMayOverflow);
-  // When not folding the tail, we know that the induction increment will not
-  // overflow.
-  bool HasNUW = Style == TailFoldingStyle::None;
+  // Use NUW for the induction increment if we proved that it won't overflow in
+  // the vector loop or when not folding the tail. Then we know that the
+  // induction increment will not overflow as the vector trip count is >=
+  // increment and a multiple of the increment.
+  bool HasNUW = Style == !IVUpdateMayOverflow;
+  || TailFoldingStyle::None;
----------------
graphite-app[bot] wrote:

The boolean expression for `HasNUW` appears to be malformed. It's currently split across two lines with an invalid OR operator. To correctly set the `HasNUW` flag, consider consolidating the condition into a single, well-formed boolean expression. For example:

```cpp
bool HasNUW = !IVUpdateMayOverflow || Style == TailFoldingStyle::None;
```

This change would properly capture the intended logic: setting `HasNUW` to true when either the IV update is guaranteed not to overflow or when tail folding is not being applied.

*Spotted by [Graphite Reviewer](https://app.graphite.dev/graphite-reviewer/?org=llvm&ref=ai-review-comment)*<i class='graphite__hidden'><br /><br />Is this helpful? React 👍 or 👎 to let us know.</i>

https://github.com/llvm/llvm-project/pull/111758


More information about the llvm-commits mailing list