@@ -747,6 +747,16 @@ def shl_ashr_to_sext_inreg : GICombineRule<
747747 (apply [{ Helper.applyAshShlToSextInreg(*${root}, ${info});}])
748748>;
749749
750+ // Fold sub 0, (and x, 1) -> sext_inreg x, 1
751+ def neg_and_one_to_sext_inreg : GICombineRule<
752+ (defs root:$dst),
753+ (match (G_AND $and, $x, 1),
754+ (G_SUB $dst, 0, $and),
755+ [{ return Helper.isLegalOrBeforeLegalizer(
756+ {TargetOpcode::G_SEXT_INREG, {MRI.getType(${x}.getReg())}}); }]),
757+ (apply (G_SEXT_INREG $dst, $x, 1))
758+ >;
759+
750760// Fold and(and(x, C1), C2) -> C1&C2 ? and(x, C1&C2) : 0
751761def overlapping_and: GICombineRule <
752762 (defs root:$root, build_fn_matchinfo:$info),
@@ -2013,7 +2023,7 @@ def all_combines : GICombineGroup<[integer_reassoc_combines, trivial_combines,
20132023 undef_combines, identity_combines, phi_combines,
20142024 simplify_add_to_sub, hoist_logic_op_with_same_opcode_hands, shifts_too_big,
20152025 reassocs, ptr_add_immed_chain, cmp_combines,
2016- shl_ashr_to_sext_inreg, sext_inreg_of_load,
2026+ shl_ashr_to_sext_inreg, neg_and_one_to_sext_inreg, sext_inreg_of_load,
20172027 width_reduction_combines, select_combines,
20182028 known_bits_simplifications, trunc_shift,
20192029 not_cmp_fold, opt_brcond_by_inverting_cond,
0 commit comments