EarlyCSE's handleBranchCondition says:
// If the condition is AND operation, we can propagate its operands into the // true branch. If it is OR operation, we can propagate them into the false // branch.
This holds for the corresponding select patterns as well.
This is a part of an ongoing work for disabling buggy select->and/or transformations.
See llvm.org/pr48353 and D93065 for more context
Proof:
and: https://alive2.llvm.org/ce/z/MQWodU
or: https://alive2.llvm.org/ce/z/9GLbB_
As clang-format points out, these braces were probably intended to go around the whole block? With that fixed, you should be able to drop the nullptr initialization and use dyn_cast instead of dyn_cast_or_null below.