This assertion fails when an i16 constant is promoted to i32.
Example: https://godbolt.org/z/rxo649jEo
The value i16 -32768 is within the range of i16 but is promoted to
positive i32 32768 by an earlier call to DAG.getConstant().
Another option would be to modify the assert to:
assert((ImmVal >= -32768) && (ImmVal <= 65535));
not sure if this is any better.
I think the way lowering currently works, we currently don't have any guarantee at all about what the high bits of ImmVal contain; this follows from the definition of SPLAT_VECTOR. So probably we should be explicitly masking off the high bits. I doubt that has any practical effect here, though; just deleting the assertion is probably good enough.