The code was hashing a pointer to the mask, not the mask itself.
The critical change here is the change to hash_value in MachineOperand.cpp; the other changes are just to pass around the size of the mask.
I'm not sure if this fixes any visible issues in the places hashing is currently used; this was found by inspection while looking into D61975.
These should use EXPECT