[llvm] Explain partial byte extraction logic. (PR #92868)

Artem Belevich via llvm-commits llvm-commits at lists.llvm.org
Tue May 21 10:44:09 PDT 2024


================
@@ -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
----------------
Artem-B wrote:

> 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.

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


More information about the llvm-commits mailing list