BUILD_VECTOR disambiguation

Hey devs,

From ISDOpcodes.h...

/// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a fixed-width vector
/// with the specified, possibly variable, elements. The number of elements
/// is required to be a power of two. The types of the operands must all be
/// the same and must match the vector element type, except that integer types
/// are allowed to be larger than the element type, in which case the operands
/// are implicitly truncated.
BUILD_VECTOR,

Must the operand types always be the same? Or could we see a
BUILD_VECTOR with mixed integer types? E.g.:

BUILD_VECTOR(i32, i32, i64, i32)

Thanks,
Cam

Hey devs,

From ISDOpcodes.h...

/// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a fixed-width vector
/// with the specified, possibly variable, elements. The number of elements
/// is required to be a power of two. The types of the operands must all be
/// the same and must match the vector element type, except that integer types

/// The types of the operands must all be the same and must match the vector element type,

^ ?

Mixed integer types are ok, but the values will get truncated to the element type of the output value. It's pretty much what the comment says.

Thanks for the clarification. The `except` seemed dangling to me, but
it's early here.

Just curious... how do we end up with a mixed type BUILD_VECTOR?
That's counterintuitive.

Sorry. Being pedantic, how do we end up with a mixed operand type BUILD_VECTOR?

The problem can happen when you want to build a vector of i8, but i8 itself is not legal on your target. All operands to BUILD_VECTOR will be legalized to the next legal integer type, so you can end up with a BUILD_VECTOR of vNi8 where all operands are i32, for example.

Actual mixed types are less likely to happen, but if you are doing your own target-specific lowering, you can end up with mixed types, simply because your code doesn't have to make them all the same.

Mixed types aren’t allowed. They are checked for in VerifySDNode in SelectionDAG.cpp and will fail an asserts build.

That's what I would expect. I don't see a good a priori reason to
build a vector with mixed operand types. IMO, the BUILD_VECTOR
specification should be tightened up.

Proposal to change the BUILD_VECTOR comment posted in D83413, if
anyone would like to comment.

Thanks again,
Cam