[llvm] [LoopUnroll] Add NUW to IV increment introduced by runtime unrolling. (PR #83246)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 29 13:32:07 PST 2024


================
@@ -940,7 +940,7 @@ bool llvm::UnrollRuntimeLoopRemainder(
     B2.SetInsertPoint(LatchBR);
     auto *Zero = ConstantInt::get(NewIdx->getType(), 0);
     auto *One = ConstantInt::get(NewIdx->getType(), 1);
-    Value *IdxNext = B2.CreateAdd(NewIdx, One, NewIdx->getName() + ".next");
+    Value *IdxNext = B2.CreateNUWAdd(NewIdx, One, NewIdx->getName() + ".next");
----------------
preames wrote:

This contradicts the comment just above: 
// Subtle: TestVal can be 0 if we wrapped when computing the trip count,
// thus we must compare the post-increment (wrapping) value."

So I don't believe it holds?

It should hold if we can prove TestVal != 0, but we should already get that in a bunch of places, so unless there's a pass ordering issue, adding it here might not be worthwhile. 

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


More information about the llvm-commits mailing list