-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Explain partial byte extraction logic. #92868
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
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.
LGTM with a nit.
@@ -1851,6 +1851,9 @@ void NVPTXAsmPrinter::bufferLEByte(const Constant *CPV, int Bytes, | |||
auto AddIntToBuffer = [AggBuffer, Bytes](const APInt &Val) { | |||
size_t NumBytes = (Val.getBitWidth() + 7) / 8; | |||
SmallVector<unsigned char, 16> Buf(NumBytes); | |||
// `extractBitsAsZExtValue` does not allow the extraction of bits beyond the | |||
// input's bit width. We handle the last byte separately, so we never |
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.
beyond the input's bit width
... and i1 arrays may not be in multiples of 8.
That was the missing piece for me. With that in mind, the code could be simplified to iterate over all bytes, but do extractBitsAsZExtValue(min(remaining bits, 8),...)
, without special-casing the last byte.
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.
Done. Sorry for the delay.
This is a follow-up to llvm#92506.
@llvm/pr-subscribers-backend-nvptx Author: Johannes Reifferscheid (jreiffers) ChangesThis is a follow-up to #92506. Full diff: https://github.com/llvm/llvm-project/pull/92868.diff 1 Files Affected:
diff --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
index f63697916d902..c30368a60c126 100644
--- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
@@ -1851,6 +1851,10 @@ void NVPTXAsmPrinter::bufferLEByte(const Constant *CPV, int Bytes,
auto AddIntToBuffer = [AggBuffer, Bytes](const APInt &Val) {
size_t NumBytes = (Val.getBitWidth() + 7) / 8;
SmallVector<unsigned char, 16> Buf(NumBytes);
+ // `extractBitsAsZExtValue` does not allow the extraction of bits beyond the
+ // input's bit width, and i1 arrays may not have a length that is a multuple
+ // of 8. We handle the last byte separately, so we never request out of
+ // bounds bits.
for (unsigned I = 0; I < NumBytes - 1; ++I) {
Buf[I] = Val.extractBitsAsZExtValue(8, I * 8);
}
|
This is a follow-up to llvm#92506.
This is a follow-up to #92506.