vector instruction


is there a good way to determine that the instruction is a vector instruction? Or the only way like it’s size is multiple of the operands size?

This depends on what you mean by “instruction”. More context would have been useful.

LLVM IR is typed, and therefore you will see the operation applied to vector-typed arguments. For example %3 = add i32 %1, %2 is the scalar version, %3 = add <4 x i32> %1, %2 is the vectorised version (for a given IR vector type). The language reference has specifics on which instructions can operate on both vectors and scalars.

I don’t know anything about MIR.

If you’re looking at target-specific instructions (such as x86), you should look up the instruction documentation as provided by the manufacturer/ISA)


I’m also not sure what you mean by “its size is a multiple of the operands size”. An instruction’s (encoding) size has no correlation to the size of the registers it operates on in a general sense.

So if you’re looking for whether an IR instruction is a “vector instruction” (i.e. it operates on or produces vectors), you should keep in mind that every llvm::Instruction is an llvm::Value and you can get it’s type and check if it’s a vector type with something like I.getType()->isVectorTy().

For MachineInstr’s, I think you’d have to ensure that the operand you’re interested in is a register operand, get the register and check the MachineRegisterInfo::getRegClass() for whether it’s a vector register.

The reason I’ve put “vector instruction” in quotes is because that of course doesn’t have a clear definition. For example, is extractelt a vector instruction? How about insertelt? What I’m getting at is if an instruction has scalar inputs and vector outputs or vice-versa. Or if the instruction has a mixture of vector and scalar operands (think of loads/stores - address is likely in a scalar register or perhaps some kind of arithmetic binary operator between a vector and a scalar).

Ok, seems that I simply need to check by isVectorTy()