When pushing a sub nsw 0, %x negation into an expression, try to preserve the nsw flag for the cases where this is possible. Do this by passing the flag through recursive Negator::negate() calls.
All of these except the -1 << X case work for NUW as well: https://alive2.llvm.org/ce/z/zzPZRQ
Maybe instead of a bool pass a bitmask of flags? Would make it easier to add NUW support in a followup.
You can have NSW on this mul given that Op1 is a constant.
Nit: I would rename IsNSW to MayNSW or ParentNSW as that seems to more accurately represent the usage.
sub nuw 0, %x is only non-poison when %x is zero. For that reason, it's not really something that occurs in practice, so I don't think it's worth handling.
Hm, looks like it's okay to keep nsw: https://alive2.llvm.org/ce/z/vnYqoi That's quite unexpected to me.