[llvm] [IR] Implementation and lowering of bitinsert and bitextract (PR #200605)
via llvm-commits
llvm-commits at lists.llvm.org
Sat May 30 13:28:07 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-x86
@llvm/pr-subscribers-llvm-selectiondag
Author: Pedro Vicente (pedroMVicente)
<details>
<summary>Changes</summary>
This commit introduces bitinsert and bitextract instructions for LLVM IR. These allow bit manipulation for Byte types. Both were lowered to GlobalIsel and SDag.
Tests were added for both LLVM IR and x86.
The langref was updated to document the new instructions.
This PR is based on the RFC: https://discourse.llvm.org/t/rfc-bitinsert-and-bitextract-instructions-for-llvm-ir-2/90764
---
Patch is 45.69 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/200605.diff
36 Files Affected:
- (modified) llvm/docs/LangRef.rst (+82)
- (modified) llvm/include/llvm-c/Core.h (+12)
- (modified) llvm/include/llvm/Analysis/InstSimplifyFolder.h (+12)
- (modified) llvm/include/llvm/Analysis/TargetFolder.h (+10)
- (modified) llvm/include/llvm/AsmParser/LLParser.h (+2)
- (modified) llvm/include/llvm/AsmParser/LLToken.h (+2)
- (modified) llvm/include/llvm/Bitcode/LLVMBitCodes.h (+2)
- (modified) llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h (+3)
- (modified) llvm/include/llvm/IR/ConstantFolder.h (+10)
- (modified) llvm/include/llvm/IR/IRBuilder.h (+14)
- (modified) llvm/include/llvm/IR/IRBuilderFolder.h (+6)
- (modified) llvm/include/llvm/IR/InstVisitor.h (+2)
- (modified) llvm/include/llvm/IR/Instruction.def (+3-1)
- (modified) llvm/include/llvm/IR/Instructions.h (+81)
- (modified) llvm/include/llvm/IR/NoFolder.h (+10)
- (modified) llvm/lib/AsmParser/LLLexer.cpp (+2)
- (modified) llvm/lib/AsmParser/LLParser.cpp (+49)
- (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+39)
- (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (+12)
- (modified) llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp (+70)
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (+67)
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h (+3)
- (modified) llvm/lib/CodeGen/TargetLoweringBase.cpp (+2)
- (modified) llvm/lib/IR/AsmWriter.cpp (+2-2)
- (modified) llvm/lib/IR/Core.cpp (+14)
- (modified) llvm/lib/IR/Instruction.cpp (+2)
- (modified) llvm/lib/IR/Instructions.cpp (+57)
- (modified) llvm/lib/IR/Verifier.cpp (+19)
- (added) llvm/test/Assembler/bitextract-invalid-1.ll (+6)
- (added) llvm/test/Assembler/bitinsert-bitextract.ll (+15)
- (added) llvm/test/Assembler/bitinsert-invalid-1.ll (+6)
- (added) llvm/test/CodeGen/X86/GlobalISel/bitinsert-bitextract.ll (+32)
- (added) llvm/test/CodeGen/X86/bitinsert-bitextract-x86.ll (+42)
- (added) llvm/test/ExecutionEngine/bitinsert-bitextract-runtime.ll (+29)
- (added) llvm/test/Verifier/bitextract-invalid-verifier.ll (+8)
- (modified) llvm/tools/llvm-c-test/echo.cpp (+14)
``````````diff
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 81694139fcea2..75a2f100c5536 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -11517,6 +11517,88 @@ Example:
<result> = xor i32 4, 8 ; yields i32:result = 12
<result> = xor i32 %V, -1 ; yields i32:result = ~%V
+Byte Operations
+-----------------
+
+Instructions for bit manipulation for bytes.
+
+.. _i_bitextract:
+
+'``bitextract``' Instruction
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Syntax:
+"""""""
+
+::
+
+ <result> = bitextract <ty>, <tx> <source>, i32 <offset>
+
+Overview:
+"""""""""
+
+The '``bitextract``' extracts a value from a byte.
+
+Arguments:
+""""""""""
+The '``bitextract``' instruction takes any first-class type ty (the
+return type), a Byte value source, and an offset.
+
+Semantics:
+""""""""""
+
+The '``bitextract``' instruction returns a value of the specified type.
+The returned value is first extracted from the source, starting at the
+bit specified by the offset, and then bitcasted to the return type.
+If the range offset+ty.bitwidth exceeds the source width, it returns
+poison. Bit 0 is the most significant bit.
+
+Example:
+""""""""
+
+.. code-block:: text
+
+ %result = bitextract i8, b32 %src, i32 24 ; Extract the last 8 bits from %src and return an 8-bit integer
+
+.. _i_bitinsert:
+
+'``bitinsert``' Instruction
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Syntax:
+"""""""
+
+::
+
+ <result> = bitinsert <tx> <base>, <ty> <val>, i32 <offset>
+
+Overview:
+"""""""""
+
+This instruction '``bitinsert``' inserts a value into a specific
+position within a byte.
+
+Arguments:
+""""""""""
+The first argument (base) of '``bitinsert``' must be of a byte type.
+The second operand (val) must be an arbitrary type.
+
+Semantics:
+""""""""""
+
+The returned value is of the same byte type as the first argument.
+It returns the first argument where the bits in the range
+[offset, offset + ty.bitlength - 1] have been replaced with val.
+If the range (offset + ty.bitwidth) is greater than the bitwidth of
+the first argument, it returns poison. Bit 0 is the most significant bit.
+
+Example:
+""""""""
+
+.. code-block:: text
+
+ %result = bitinsert b32 %x, i8 %y, i32 3 ; Inserts the %y bits into %x with an offset of 3
+
Vector Operations
-----------------
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index 86f636c636783..6aae7fc30dab6 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -133,6 +133,8 @@ typedef enum {
LLVMExtractValue = 53,
LLVMInsertValue = 54,
LLVMFreeze = 68,
+ LLVMBitInsert = 72,
+ LLVMBitExtract = 73,
/* Atomic operators */
LLVMFence = 55,
@@ -5142,6 +5144,16 @@ LLVM_C_ABI LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef,
unsigned Index, const char *Name);
LLVM_C_ABI LLVMValueRef LLVMBuildFreeze(LLVMBuilderRef, LLVMValueRef Val,
const char *Name);
+LLVM_C_ABI LLVMValueRef LLVMBuildBitExtract(LLVMBuilderRef,
+ LLVMTypeRef Type,
+ LLVMValueRef Src,
+ LLVMValueRef Offset,
+ const char *Name);
+LLVM_C_ABI LLVMValueRef LLVMBuildBitInsert(LLVMBuilderRef,
+ LLVMValueRef Base,
+ LLVMValueRef Val,
+ LLVMValueRef Offset,
+ const char *Name);
LLVM_C_ABI LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
const char *Name);
diff --git a/llvm/include/llvm/Analysis/InstSimplifyFolder.h b/llvm/include/llvm/Analysis/InstSimplifyFolder.h
index b0b8dde3b2967..d79c619114a72 100644
--- a/llvm/include/llvm/Analysis/InstSimplifyFolder.h
+++ b/llvm/include/llvm/Analysis/InstSimplifyFolder.h
@@ -115,6 +115,18 @@ class LLVM_ABI InstSimplifyFolder final : public IRBuilderFolder {
return simplifyShuffleVectorInst(V1, V2, Mask, RetTy, SQ);
}
+ Value *FoldBitInsert(Value *Base, Value *Val,
+ Value *Offset) const override {
+ // TODO
+ return nullptr;
+ }
+
+ Value *FoldBitExtract(Type *Ty, Value *Src,
+ Value *Offset) const override {
+ // TODO
+ return nullptr;
+ }
+
Value *FoldCast(Instruction::CastOps Op, Value *V,
Type *DestTy) const override {
return simplifyCastInst(Op, V, DestTy, SQ);
diff --git a/llvm/include/llvm/Analysis/TargetFolder.h b/llvm/include/llvm/Analysis/TargetFolder.h
index 596e3600f7306..dd8264c34e58e 100644
--- a/llvm/include/llvm/Analysis/TargetFolder.h
+++ b/llvm/include/llvm/Analysis/TargetFolder.h
@@ -184,6 +184,16 @@ class LLVM_ABI TargetFolder final : public IRBuilderFolder {
return nullptr;
}
+ Value *FoldBitInsert(Value *Base, Value *Val,
+ Value *Offset) const override {
+ return nullptr;
+ }
+
+ Value *FoldBitExtract(Type *Ty, Value *Src,
+ Value *Offset) const override {
+ return nullptr;
+ }
+
Value *FoldCast(Instruction::CastOps Op, Value *V,
Type *DestTy) const override {
if (auto *C = dyn_cast<Constant>(V))
diff --git a/llvm/include/llvm/AsmParser/LLParser.h b/llvm/include/llvm/AsmParser/LLParser.h
index 938a45951e074..0e7c073a47277 100644
--- a/llvm/include/llvm/AsmParser/LLParser.h
+++ b/llvm/include/llvm/AsmParser/LLParser.h
@@ -684,6 +684,8 @@ namespace llvm {
bool parseExtractElement(Instruction *&Inst, PerFunctionState &PFS);
bool parseInsertElement(Instruction *&Inst, PerFunctionState &PFS);
bool parseShuffleVector(Instruction *&Inst, PerFunctionState &PFS);
+ bool parseBitExtract(Instruction *&Inst, PerFunctionState &PFS);
+ bool parseBitInsert(Instruction *&Inst, PerFunctionState &PFS);
int parsePHI(Instruction *&Inst, PerFunctionState &PFS);
bool parseLandingPad(Instruction *&Inst, PerFunctionState &PFS);
bool parseCall(Instruction *&Inst, PerFunctionState &PFS,
diff --git a/llvm/include/llvm/AsmParser/LLToken.h b/llvm/include/llvm/AsmParser/LLToken.h
index a9864cfbcab25..eb2e3c97a43ce 100644
--- a/llvm/include/llvm/AsmParser/LLToken.h
+++ b/llvm/include/llvm/AsmParser/LLToken.h
@@ -380,6 +380,8 @@ enum Kind {
kw_dso_local_equivalent,
kw_no_cfi,
kw_ptrauth,
+ kw_bitinsert,
+ kw_bitextract,
kw_freeze,
diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
index 95787c595dff7..d5691877b20d2 100644
--- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h
+++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
@@ -703,6 +703,8 @@ enum FunctionCodes {
FUNC_CODE_DEBUG_RECORD_LABEL = 65, // [DILocation, DILabel]
FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE =
66, // [DILocation, DILocalVariable, DIExpression, ValueAsMetadata]
+ FUNC_CODE_INST_BITINSERT = 67, // BITINSERT: [val, val ,val]
+ FUNC_CODE_INST_BITEXTRACT = 68, // BITEXTRACT: [val, val, val]
};
enum UseListCodes {
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h b/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h
index 7815ad686cbaa..9622a3a158b7f 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h
@@ -569,6 +569,9 @@ class IRTranslator : public MachineFunctionPass {
bool translateFence(const User &U, MachineIRBuilder &MIRBuilder);
bool translateFreeze(const User &U, MachineIRBuilder &MIRBuilder);
+ bool translateBitExtract(const User &U, MachineIRBuilder &MIRBuilder);
+ bool translateBitInsert(const User &U, MachineIRBuilder &MIRBuilder);
+
// Stubs to keep the compiler happy while we implement the rest of the
// translation.
bool translateResume(const User &U, MachineIRBuilder &MIRBuilder) {
diff --git a/llvm/include/llvm/IR/ConstantFolder.h b/llvm/include/llvm/IR/ConstantFolder.h
index 384773027fb65..8bb5b8f45a314 100644
--- a/llvm/include/llvm/IR/ConstantFolder.h
+++ b/llvm/include/llvm/IR/ConstantFolder.h
@@ -172,6 +172,16 @@ class LLVM_ABI ConstantFolder final : public IRBuilderFolder {
return nullptr;
}
+ Value *FoldBitInsert(Value *Base, Value *Val,
+ Value *Offset) const override {
+ return nullptr;
+ }
+
+ Value *FoldBitExtract(Type *Ty, Value *Src,
+ Value *Offset) const override {
+ return nullptr;
+ }
+
Value *FoldCast(Instruction::CastOps Op, Value *V,
Type *DestTy) const override {
if (auto *C = dyn_cast<Constant>(V)) {
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index a10a59a9ae9e7..cdd0dc9e1a5d9 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -2694,6 +2694,20 @@ class IRBuilderBase {
return Insert(new FreezeInst(V), Name);
}
+ Value *CreateBitInsert(Value *Base, Value *Val, Value *Offset,
+ const Twine &Name = "") {
+ if (Value *V = Folder.FoldBitInsert(Base, Val, Offset))
+ return V;
+ return Insert(BitInsertInst::Create(Base, Val, Offset), Name);
+ }
+
+ Value *CreateBitExtract(Type *Ty, Value *Src, Value *Offset,
+ const Twine &Name = "") {
+ if (Value *V = Folder.FoldBitExtract(Ty, Src, Offset))
+ return V;
+ return Insert(BitExtractInst::Create(Ty, Src, Offset), Name);
+ }
+
//===--------------------------------------------------------------------===//
// Utility creation methods
//===--------------------------------------------------------------------===//
diff --git a/llvm/include/llvm/IR/IRBuilderFolder.h b/llvm/include/llvm/IR/IRBuilderFolder.h
index 3cf3bcd3d9522..6db2424155128 100644
--- a/llvm/include/llvm/IR/IRBuilderFolder.h
+++ b/llvm/include/llvm/IR/IRBuilderFolder.h
@@ -80,6 +80,12 @@ class LLVM_ABI IRBuilderFolder {
FoldBinaryIntrinsic(Intrinsic::ID ID, Value *LHS, Value *RHS, Type *Ty,
FastMathFlags FMF = FastMathFlags()) const = 0;
+ virtual Value *FoldBitInsert(Value *Base, Value *Val,
+ Value *Offset) const = 0;
+
+ virtual Value *FoldBitExtract(Type *Ty, Value *Src,
+ Value *Offset) const = 0;
+
//===--------------------------------------------------------------------===//
// Cast/Conversion Operators
//===--------------------------------------------------------------------===//
diff --git a/llvm/include/llvm/IR/InstVisitor.h b/llvm/include/llvm/IR/InstVisitor.h
index 45b2e59510b67..0f5f2ab6c1317 100644
--- a/llvm/include/llvm/IR/InstVisitor.h
+++ b/llvm/include/llvm/IR/InstVisitor.h
@@ -199,6 +199,8 @@ class InstVisitor {
RetTy visitCleanupPadInst(CleanupPadInst &I) { DELEGATE(FuncletPadInst); }
RetTy visitCatchPadInst(CatchPadInst &I) { DELEGATE(FuncletPadInst); }
RetTy visitFreezeInst(FreezeInst &I) { DELEGATE(Instruction); }
+ RetTy visitBitInsertInst(BitInsertInst &I) { DELEGATE(Instruction); }
+ RetTy visitBitExtractInst(BitExtractInst &I) { DELEGATE(Instruction); }
RetTy visitMemSetInst(MemSetInst &I) { DELEGATE(MemIntrinsic); }
RetTy visitMemSetPatternInst(MemSetPatternInst &I) {
diff --git a/llvm/include/llvm/IR/Instruction.def b/llvm/include/llvm/IR/Instruction.def
index 949a9d0beecb4..dc4c3c795fad7 100644
--- a/llvm/include/llvm/IR/Instruction.def
+++ b/llvm/include/llvm/IR/Instruction.def
@@ -220,7 +220,9 @@ HANDLE_OTHER_INST(66, ExtractValue, ExtractValueInst)// extract from aggregate
HANDLE_OTHER_INST(67, InsertValue, InsertValueInst) // insert into aggregate
HANDLE_OTHER_INST(68, LandingPad, LandingPadInst) // Landing pad instruction.
HANDLE_OTHER_INST(69, Freeze, FreezeInst) // Freeze instruction.
- LAST_OTHER_INST(69)
+HANDLE_OTHER_INST(70, BitInsert, BitInsertInst) // BitInsert Instruction.
+HANDLE_OTHER_INST(71, BitExtract, BitExtractInst) // BitExtract Instruction
+ LAST_OTHER_INST(71)
#undef FIRST_TERM_INST
#undef HANDLE_TERM_INST
diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h
index 365a4eee54eb6..400d996710b44 100644
--- a/llvm/include/llvm/IR/Instructions.h
+++ b/llvm/include/llvm/IR/Instructions.h
@@ -5415,6 +5415,87 @@ class FreezeInst : public UnaryInstruction {
}
};
+//===----------------------------------------------------------------------===//
+// BitInsert Class
+//===----------------------------------------------------------------------===//
+class BitInsertInst : public Instruction {
+ constexpr static IntrusiveOperandsAllocMarker AllocMarker{3};
+ LLVM_ABI explicit BitInsertInst(Value *Base, Value *Val, Value *Offset,
+ const Twine &NameStr = "",
+ InsertPosition InsertBefore = nullptr);
+
+protected:
+ // Note: Instruction needs to be a friend here to call cloneImpl.
+ friend class Instruction;
+ /// Clone an identical FreezeInst
+ LLVM_ABI BitInsertInst *cloneImpl() const;
+
+public:
+ static BitInsertInst *Create(Value *Base, Value *Val, Value *Offset,
+ const Twine &NameStr = "",
+ InsertPosition InsertBefore = nullptr) {
+ return new (AllocMarker)
+ BitInsertInst(Base, Val, Offset, NameStr, InsertBefore);
+ }
+ /// Transparently provide more efficient getOperand methods.
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+ /// Return true if an bitinsert instruction can be
+ /// formed with the specified operands.
+ LLVM_ABI static bool isValidOperands(const Value *Base, const Value *Val,
+ const Value *Offset);
+ // Methods for support type inquiry through isa, cast, and dyn_cast:
+ static inline bool classof(const Instruction *I) {
+ return I->getOpcode() == BitInsert;
+ }
+ static inline bool classof(const Value *V) {
+ return isa<Instruction>(V) && classof(cast<Instruction>(V));
+ }
+};
+template <>
+struct OperandTraits<BitInsertInst>
+ : public FixedNumOperandTraits<BitInsertInst, 3> {};
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BitInsertInst, Value)
+
+//===----------------------------------------------------------------------===//
+// BitExtract Class
+//===----------------------------------------------------------------------===//
+class BitExtractInst : public Instruction {
+ constexpr static IntrusiveOperandsAllocMarker AllocMarker{2};
+ LLVM_ABI BitExtractInst(Type *Ty, Value *Src, Value *Offset,
+ const Twine &NameStr = "",
+ InsertPosition InsertBefore = nullptr);
+
+protected:
+ // Note: Instruction needs to be a friend here to call cloneImpl.
+ friend class Instruction;
+ /// Clone an identical FreezeInst
+ LLVM_ABI BitExtractInst *cloneImpl() const;
+
+public:
+ static BitExtractInst *Create(Type *Ty, Value *Src, Value *Offset,
+ const Twine &NameStr = "",
+ InsertPosition InsertBefore = nullptr) {
+ return new (AllocMarker)
+ BitExtractInst(Ty, Src, Offset, NameStr, InsertBefore);
+ }
+ /// Transparently provide more efficient getOperand methods.
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+ /// Return true if an bitextract instruction can be
+ /// formed with the specified operands.
+ LLVM_ABI static bool isValidOperands(const Type *Ty, const Value *Val,
+ const Value *Offset);
+ // Methods for support type inquiry through isa, cast, and dyn_cast:
+ static inline bool classof(const Instruction *I) {
+ return I->getOpcode() == BitExtract;
+ }
+ static inline bool classof(const Value *V) {
+ return isa<Instruction>(V) && classof(cast<Instruction>(V));
+ }
+};
+template <>
+struct OperandTraits<BitExtractInst>
+ : public FixedNumOperandTraits<BitExtractInst, 2> {};
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BitExtractInst, Value)
} // end namespace llvm
#endif // LLVM_IR_INSTRUCTIONS_H
diff --git a/llvm/include/llvm/IR/NoFolder.h b/llvm/include/llvm/IR/NoFolder.h
index a8dbbf5eeb1c2..24b7856bc55df 100644
--- a/llvm/include/llvm/IR/NoFolder.h
+++ b/llvm/include/llvm/IR/NoFolder.h
@@ -109,6 +109,16 @@ class LLVM_ABI NoFolder final : public IRBuilderFolder {
return nullptr;
}
+ Value *FoldBitInsert(Value *Base, Value *Val,
+ Value *Offset) const override {
+ return nullptr;
+ }
+
+ Value *FoldBitExtract(Type *Ty, Value *Src,
+ Value *Offset) const override {
+ return nullptr;
+ }
+
Value *FoldCast(Instruction::CastOps Op, Value *V,
Type *DestTy) const override {
return nullptr;
diff --git a/llvm/lib/AsmParser/LLLexer.cpp b/llvm/lib/AsmParser/LLLexer.cpp
index e7d7cc4ba88ea..26d04800aef36 100644
--- a/llvm/lib/AsmParser/LLLexer.cpp
+++ b/llvm/lib/AsmParser/LLLexer.cpp
@@ -996,6 +996,8 @@ lltok::Kind LLLexer::LexIdentifier() {
INSTKEYWORD(cleanuppad, CleanupPad);
INSTKEYWORD(freeze, Freeze);
+ INSTKEYWORD(bitinsert, BitInsert);
+ INSTKEYWORD(bitextract, BitExtract);
#undef INSTKEYWORD
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 990febaacbe48..eb6da0bbe256f 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -4736,6 +4736,12 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
return true;
}
+ if (Opc == Instruction::BitExtract) {
+ if (parseType(Ty) ||
+ parseToken(lltok::comma, "expected comma after bitextract's type"))
+ return true;
+ }
+
if (parseGlobalValueVector(Elts) ||
parseToken(lltok::rparen, "expected ')' in constantexpr"))
return true;
@@ -7721,6 +7727,10 @@ int LLParser::parseInstruction(Instruction *&Inst, BasicBlock *BB,
return parseLandingPad(Inst, PFS);
case lltok::kw_freeze:
return parseFreeze(Inst, PFS);
+ case lltok::kw_bitinsert:
+ return parseBitInsert(Inst, PFS);
+ case lltok::kw_bitextract:
+ return parseBitExtract(Inst, PFS);
// Call.
case lltok::kw_call:
return parseCall(Inst, PFS, CallInst::TCK_None);
@@ -8538,6 +8548,45 @@ bool LLParser::parseInsertElement(Instruction *&Inst, PerFunctionState &PFS) {
return false;
}
+// parseBitExtract
+// ::= 'bitextract' Type ',' TypeAndValue ',' TypeAndValue
+bool LLParser::parseBitExtract(Instruction *&Inst, PerFunctionState &PFS) {
+ LocTy Loc;
+ Type *Ty = nullptr;
+ Value *Op0, *Op1;
+ if (parseType(Ty, Loc) ||
+ parseToken(lltok::comma, "expected ',' after bitextract type") ||
+ parseTypeAndValue(Op0, Loc, PFS) ||
+ parseToken(lltok::comma, "expected ',' after bitextract source value") ||
+ parseTypeAndValue(Op1, PFS))
+ return true;
+
+ if (!BitExtractInst::isValidOperands(Ty, Op0, Op1))
+ return error(Loc, "invalid bitextract operands");
+
+ Inst = BitExtractInst::Create(Ty, Op0, Op1);
+ return false;
+}
+
+// parseBitInsert
+// ::= 'bitinsert' TypeAndValue ',' TypeAndValue ',' TypeAndValue
+bool LLParser::parseBitInsert(Instruction *&Inst, PerFunctionState &PFS) {
+ LocTy Loc;
+ Value *Op0, *Op1, *Op2;
+ if (parseTypeAndValue(Op0, Loc, PFS) ||
+ parseToken(lltok::comma, "expected ',' after bitinsert source value") ||
+ parseTypeAndValue(Op1, PFS) ||
+ parseToken(lltok::comma, "expected ',' after bitinsert insert value") ||
+ parseTypeAndValue(Op2, PFS))
+ return true;
+
+ if (!BitInsertInst::isValidOperands(Op0, Op1, Op2))
+ return error(Loc, "invalid bitinsert operands");
+
+ Inst = BitInsertInst::Create(Op0, Op1, Op2);
+ return false;
+}
+
/// parseShuffleVector
/// ::= 'shufflevector' TypeAndValue ',' TypeAndValue ',' TypeAndValue
bool LLParser::parseShuffleVector(Instruction *&Inst, PerFunctionState &PFS) {
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 3e863f4786e1a..ef28f922a3b45 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1837,6 +1837,14 @@ Expected<Value *> BitcodeReader::materializeValue(unsigned StartValID,
I = new ShuffleVectorInst(Ops...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/200605
More information about the llvm-commits
mailing list