-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[InstrProf] Change step from 64-bit to pointer-sized int #83239
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
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be 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 If you have received no comments on your PR for a week, you can request a review 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. |
@llvm/pr-subscribers-pgo @llvm/pr-subscribers-llvm-ir Author: Jovan Dmitrović (jdmitrovic-syrmia) ChangesFixed 64-bit step can lead to creating atomic instructions unsupported by the target architecture (see rust-lang/rust#112313). Full diff: https://github.com/llvm/llvm-project/pull/83239.diff 1 Files Affected:
diff --git a/llvm/lib/IR/IntrinsicInst.cpp b/llvm/lib/IR/IntrinsicInst.cpp
index 89403e1d7fcb4d..0f0a6bf23ffe43 100644
--- a/llvm/lib/IR/IntrinsicInst.cpp
+++ b/llvm/lib/IR/IntrinsicInst.cpp
@@ -288,7 +288,8 @@ Value *InstrProfIncrementInst::getStep() const {
}
const Module *M = getModule();
LLVMContext &Context = M->getContext();
- return ConstantInt::get(Type::getInt64Ty(Context), 1);
+ const auto &DL = M->getDataLayout();
+ return ConstantInt::get(DL.getIntPtrType(Context), 1);
}
std::optional<RoundingMode> ConstrainedFPIntrinsic::getRoundingMode() const {
|
@@ -288,7 +288,8 @@ Value *InstrProfIncrementInst::getStep() const { | |||
} | |||
const Module *M = getModule(); | |||
LLVMContext &Context = M->getContext(); | |||
return ConstantInt::get(Type::getInt64Ty(Context), 1); | |||
const auto &DL = M->getDataLayout(); | |||
return ConstantInt::get(DL.getIntPtrType(Context), 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With a 64-bit type, very few counters will overflow. With a pointer-width type, more counters will overflow, especially on 16-bit targets, but even on 32-bit targets. I speculate this is why 64-bit integers are used currently. How should we address this concern?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I pushed some changes, creating additional getStep
function for atomics. This way, we can use a larger type.
Also, I've taken the liberty of changing the existing code to use the largest legal int available instead of the 64-bit int.
a45c783
to
b7407d3
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
b7407d3
to
34a4663
Compare
@jdmitrovic-syrmia I would love to review this but I am not an LLVM project member and I don't understand the implementation well enough to offer useful feedback on the implementation. For my interests, I am primarily interested in code coverage and not profiling. I also found https://discourse.llvm.org/t/rfc-single-byte-counters-for-source-based-code-coverage/75685 which addresses the problem in a different way. Note that it is claimed there that "A nice advantage of single-byte counters is that it is already thread-safe without needing atomics." It was just merged a couple of weeks ago; see #75425. |
Fixed 64-bit step can lead to creating atomic instructions unsupported by the target architecture (see rust-lang/rust#112313). When using atomics, type of the step is a pointer-sized integer. Otherwise, type of the step is of a largest legal integer type.
34a4663
to
530c1a6
Compare
@briansmith It seems to me that #75425 concerns code coverage, and not profiling. I don't think this PR is affecting the code coverage analysis. Also, #75425 doesn't resolve the Rust issue I mentioned. |
This is incorrect. See rust-lang/rust#112313 |
@jdmitrovic-syrmia As an alternative solution, why not implement a (perhaps slow) atomic 64-bit fallback implementation that uses a global lock? |
Fixed 64-bit step can lead to creating atomic instructions unsupported by the target architecture (see rust-lang/rust#112313).