Skip to content

Conversation

@Bhuvan1527
Copy link

Minor misoptimization. The PVS-Studio warning: V791 The initial value of the index in the nested loop equals 'I'. Perhaps, 'I + 1' should be used instead. LoopUnrollAndJam.cpp 793

Minor misoptimization. The PVS-Studio warning: V791 The initial value of the index in the nested loop equals 'I'. Perhaps, 'I + 1' should be used instead. LoopUnrollAndJam.cpp 793
@github-actions
Copy link

github-actions bot commented Dec 1, 2025

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Dec 1, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Bala_Bhuvan_Varma (Bhuvan1527)

Changes

Minor misoptimization. The PVS-Studio warning: V791 The initial value of the index in the nested loop equals 'I'. Perhaps, 'I + 1' should be used instead. LoopUnrollAndJam.cpp 793


Full diff: https://github.com/llvm/llvm-project/pull/170162.diff

1 Files Affected:

  • (modified) llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp (+1-1)
diff --git a/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp b/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp index 1e614bd29ee6e..663e45e89c5da 100644 --- a/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp @@ -789,7 +789,7 @@ checkDependencies(Loop &Root, const BasicBlockSet &SubLoopBlocks, size_t NumInsts = CurrentLoadsAndStores.size(); for (size_t I = 0; I < NumInsts; ++I) { - for (size_t J = I; J < NumInsts; ++J) { + for (size_t J = I + 1; J < NumInsts; ++J) { if (!checkDependency(CurrentLoadsAndStores[I], CurrentLoadsAndStores[J], LoopDepth, CurLoopDepth, true, DI)) return false; 
Copy link
Contributor

@boomanaiden154 boomanaiden154 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this preserve the existing semantics or serve as an optimization in any way?

@Bhuvan1527
Copy link
Author

How does this preserve the existing semantics or serve as an optimization in any way?

Hi @boomanaiden154
Well, I went with the logic that,

When var J = I, then we are checking the dependency of an instruction with itself, is that check even necessary?

So, this will save the existing semantics. I even ran all the llvm tests before raising the pr.

And the optimization can be reducing an iteration of J loop I believe.

Would love to discuss more, if you have question. I'm new to LLVM. So lets learn.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants