Previously LLVM was assuming 32-bit signed immediates which results in and with a bitmask that has bit 31 set to incorrectly include bits 63-32 in the result.
After applying this patch I can now compile all of the FreeBSD mips assembly code with clang.
This issue also affects the nor, slt and sltu macros and I will fix those in a separate review.
For the 64 bit case, you need to pick the corresponding 64 bit instruction definition. Picking the 32 bit version introduces a very subtle bug in that the instruction emitted will be (harmless) malformed.