The sequence of instructions xor (ashr X, BW-1), C (or with a truncation xor (trunc (ashr X, BW-1)), C) takes a value, produces all zeros or all ones and with it optionally inverts a constant depending on whether the original input was positive or negative. This is the same as checking if the value is positive, and selecting between the constant and ~constant.
https://alive2.llvm.org/ce/z/NJ85qY
This is a fairly general version of the fold as part of D108049, which really only needs the constant to be a saturate INTMAX/INTMIN pair.
I'm not sure this one-use check does what you want it to do when there's trunc