From d2809a8474e7f80d6a4489e69af23861ed05f63c Mon Sep 17 00:00:00 2001 From: Johannes Reifferscheid Date: Tue, 21 May 2024 09:20:24 +0200 Subject: [PATCH] Explain partial byte extraction logic. This is a follow-up to #92506. --- llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp | 4 ++++ 1 file changed, 4 insertions(+) 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 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); }