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.