[llvm] Explain partial byte extraction logic. (PR #92868)
Johannes Reifferscheid via llvm-commits
llvm-commits at lists.llvm.org
Tue May 21 00:21:16 PDT 2024
https://github.com/jreiffers created https://github.com/llvm/llvm-project/pull/92868
This is a follow-up to #92506.
>From f7257bb9abb05a248b4e3d0fbc4a0b769cff2413 Mon Sep 17 00:00:00 2001
From: Johannes Reifferscheid <jreiffers at google.com>
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 | 3 +++
1 file changed, 3 insertions(+)
diff --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
index f63697916d902..5c03ddb54c2b6 100644
--- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
@@ -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
+ // 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