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

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 10 23:20:39 PDT 2024


Author: Johannes Reifferscheid
Date: 2024-06-11T08:20:35+02:00
New Revision: bfa8150ef4748a364a496f8cdf285380ac3ec876

URL: https://github.com/llvm/llvm-project/commit/bfa8150ef4748a364a496f8cdf285380ac3ec876
DIFF: https://github.com/llvm/llvm-project/commit/bfa8150ef4748a364a496f8cdf285380ac3ec876.diff

LOG: Explain partial byte extraction logic. (#92868)

This is a follow-up to #92506.

Added: 
    

Modified: 
    llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
index 82770f8660850..ca077d41d36ba 100644
--- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
@@ -1845,6 +1845,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);
     }


        


More information about the llvm-commits mailing list