-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[LoopRotate] Incorrect branch weights updating #66675
Comments
Thanks for the report! I did not consider zero-branch weights and they did cause an underflow here as my formula assumed that loop-entry weights should be equivalent to loop-exit weights which isn't really true for these weights that make things look like an endless loop. I pushed a PR that adds a special case to the code for this. Out of curiosity: I assume you are not using the IPGO? As the instrumentation there will always increase the counters a bit to avoid zero-weights as far as I can tell... (of course it makes sense to properly handle zero-counts in LoopRotation anyway) |
The formula I added to LoopRotationUtils does not produce reasonable results if some of the branch weights are zero. Add special case handling for this. This fixes llvm#66675
We aren't. We have a java based JIT compiler and IR is being built using custom PGO instrumentation, where zero-weights are possible :-) |
The formula I added to LoopRotationUtils does not produce reasonable results if some of the branch weights are zero. Add special case handling for this. This fixes #66675
In the revision https://reviews.llvm.org/D157462 branch weights updating was added to the
LoopRotate
.But let's run the pass
bin/opt -passes=loop-rotate test.ll
on with the test case with1:0
weights ratio:Resulting branch weigths looks weird:
It seems the reason is that we don't scale
OrigLoopExitWeight
when it's0
:https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp#L314
and the subsequent computation overflowing:
uint32_t ExitWeight1 = OrigLoopExitWeight - ExitWeight0;
The text was updated successfully, but these errors were encountered: