This is similar to the select logic just ahead of the new code. Min/max choose exactly one value from the inputs, so if both of those are a power-of-2, then the result must be a power-of-2. This might help with D98152, but we likely still need other pieces of the puzzle to avoid regressions.
The part I'm not sure about is the diff in PatternMatch.h. Without that, I get a pile of errors like:
error: assigning to 'llvm::Value *' from incompatible type 'const llvm::Value *'
...and I haven't been able to find a combination of const to avoid it. I did try const_cast<Value *>(V) in the caller code, and that also works. Is that better or worse?