From 8e64fa980b0e021a74d3e0e0f0f879b0f74028af Mon Sep 17 00:00:00 2001 From: Haopeng Liu Date: Thu, 9 May 2024 17:43:28 +0000 Subject: [PATCH] Encode bitwidth once for ConstantRangeList kind attr --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 5 +++-- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 536eff0478fb5a..f63e058217d88b 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2344,13 +2344,14 @@ Error BitcodeReader::parseAttributeGroupBlock() { SmallVector Val; unsigned RangeSize = Record[++i]; + unsigned BitWidth = Record[++i]; if (i + 2 * RangeSize >= e) return error("Incomplete constant range list"); for (unsigned Idx = 0; Idx < RangeSize; ++Idx) { int64_t Start = BitcodeReader::decodeSignRotatedValue(Record[++i]); int64_t End = BitcodeReader::decodeSignRotatedValue(Record[++i]); - Val.push_back( - ConstantRange(APInt(64, Start, true), APInt(64, End, true))); + Val.push_back(ConstantRange(APInt(BitWidth, Start, true), + APInt(BitWidth, End, true))); } B.addConstantRangeListAttr(Kind, Val); } else { diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 6011aa72789acb..e9d6afb49cd9e9 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -958,6 +958,7 @@ void ModuleBitcodeWriter::writeAttributeGroupTable() { Record.push_back(getAttrKindEncoding(Attr.getKindAsEnum())); ArrayRef Val = Attr.getValueAsConstantRangeList(); Record.push_back(Val.size()); + Record.push_back(Val[0].getBitWidth()); for (auto &CR : Val) { emitConstantRange(Record, CR, /*EmitBitWidth=*/false); }