https://github.com/nikic commented: This basically looks fine to me. This is missing the flag drop in InstCombineSimplifyDemanded. Can you please also add a test to llvm/test/Transforms/SimplifyCFG/HoistCode.ll to cover the flag intersect? https://github.com/llvm/llvm-project/pull/72583