@@ -430,6 +430,12 @@ def binop_right_undef_to_undef: GICombineRule<
430430 [{ return Helper.matchOperandIsUndef(*${root}, 2); }]),
431431 (apply [{ Helper.replaceInstWithUndef(*${root}); }])>;
432432
433+ def binop_right_poison_to_poison
434+ : GICombineRule<(defs root:$root),
435+ (match(wip_match_opcode G_SHL, G_ASHR, G_LSHR):$root,
436+ [{ return Helper.matchOperandIsPoison(*${root}, 2); }]),
437+ (apply [{ Helper.replaceInstWithPoison(*${root}); }])>;
438+
433439def unary_undef_to_zero: GICombineRule<
434440 (defs root:$root),
435441 (match (wip_match_opcode G_ABS):$root,
@@ -447,6 +453,17 @@ def unary_undef_to_undef : GICombineRule<
447453 (match (unary_undef_to_undef_frags $dst)),
448454 (apply [{ Helper.replaceInstWithUndef(*${dst}.getParent()); }])>;
449455
456+ def unary_poison_to_poison_frags
457+ : GICombinePatFrag<(outs root:$dst), (ins),
458+ !foreach(op,
459+ [G_TRUNC, G_BITCAST, G_ANYEXT, G_PTRTOINT,
460+ G_INTTOPTR, G_FPTOSI, G_FPTOUI],
461+ (pattern(op $dst, $x), (G_POISON $x)))>;
462+ def unary_poison_to_poison
463+ : GICombineRule<
464+ (defs root:$dst), (match(unary_poison_to_poison_frags $dst)),
465+ (apply [{ Helper.replaceInstWithPoison(*${dst}.getParent()); }])>;
466+
450467// Instructions where if any source operand is undef, the instruction can be
451468// replaced with undef.
452469def propagate_undef_any_op: GICombineRule<
@@ -455,6 +472,15 @@ def propagate_undef_any_op: GICombineRule<
455472 [{ return Helper.matchAnyExplicitUseIsUndef(*${root}); }]),
456473 (apply [{ Helper.replaceInstWithUndef(*${root}); }])>;
457474
475+ // Instructions where if any source operand is poison, the instruction can be
476+ // replaced with poison.
477+ def propagate_poison_any_op
478+ : GICombineRule<
479+ (defs root:$root),
480+ (match(wip_match_opcode G_ADD, G_SUB, G_XOR):$root,
481+ [{ return Helper.matchAnyExplicitUseIsPoison(*${root}); }]),
482+ (apply [{ Helper.replaceInstWithPoison(*${root}); }])>;
483+
458484// Instructions where if all source operands are undef, the instruction can be
459485// replaced with undef.
460486def propagate_undef_all_ops: GICombineRule<
@@ -463,6 +489,15 @@ def propagate_undef_all_ops: GICombineRule<
463489 [{ return Helper.matchAllExplicitUsesAreUndef(*${root}); }]),
464490 (apply [{ Helper.replaceInstWithUndef(*${root}); }])>;
465491
492+ // Instructions where if all source operands are poison, the instruction can be
493+ // replaced with poison.
494+ def propagate_poison_all_ops
495+ : GICombineRule<
496+ (defs root:$root),
497+ (match(wip_match_opcode G_SHUFFLE_VECTOR, G_BUILD_VECTOR):$root,
498+ [{ return Helper.matchAllExplicitUsesArePoison(*${root}); }]),
499+ (apply [{ Helper.replaceInstWithPoison(*${root}); }])>;
500+
466501// Replace a G_SHUFFLE_VECTOR with an undef mask with a G_IMPLICIT_DEF.
467502def propagate_undef_shuffle_mask: GICombineRule<
468503 (defs root:$root),
@@ -654,6 +689,13 @@ def erase_undef_store : GICombineRule<
654689 (apply [{ Helper.eraseInst(*${root}); }])
655690>;
656691
692+ // Erase stores of poison values.
693+ def erase_poison_store
694+ : GICombineRule<(defs root:$root),
695+ (match(wip_match_opcode G_STORE):$root,
696+ [{ return Helper.matchPoisonStore(*${root}); }]),
697+ (apply [{ Helper.eraseInst(*${root}); }])>;
698+
657699def simplify_add_to_sub_matchinfo: GIDefMatchData<"std::tuple<Register, Register>">;
658700def simplify_add_to_sub: GICombineRule <
659701 (defs root:$root, simplify_add_to_sub_matchinfo:$info),
@@ -1955,6 +1997,11 @@ def undef_combines : GICombineGroup<[undef_to_fp_zero, undef_to_int_zero,
19551997 erase_undef_store,
19561998 insert_extract_vec_elt_out_of_bounds]>;
19571999
2000+ def poison_combines
2001+ : GICombineGroup<[binop_right_poison_to_poison, unary_poison_to_poison,
2002+ propagate_poison_any_op, propagate_poison_all_ops,
2003+ erase_poison_store]>;
2004+
19582005def identity_combines : GICombineGroup<[select_same_val, right_identity_zero,
19592006 binop_same_val, binop_left_to_zero,
19602007 binop_right_to_zero, p2i_to_i2p,
@@ -2006,29 +2053,29 @@ def shuffle_combines : GICombineGroup<[combine_shuffle_concat,
20062053 combine_shuffle_undef_rhs,
20072054 combine_shuffle_disjoint_mask]>;
20082055
2009- def all_combines : GICombineGroup<[integer_reassoc_combines, trivial_combines,
2010- vector_ops_combines, freeze_combines, cast_combines,
2011- insert_vec_elt_combines, extract_vec_elt_combines, combines_for_extload ,
2012- combine_extracted_vector_load ,
2013- undef_combines, identity_combines, phi_combines ,
2014- simplify_add_to_sub, hoist_logic_op_with_same_opcode_hands, shifts_too_big ,
2015- reassocs, ptr_add_immed_chain, cmp_combines ,
2016- shl_ashr_to_sext_inreg, sext_inreg_of_load ,
2017- width_reduction_combines, select_combines ,
2018- known_bits_simplifications, trunc_shift ,
2019- not_cmp_fold, opt_brcond_by_inverting_cond ,
2020- const_combines, xor_of_and_with_same_reg, ptr_add_with_zero ,
2021- shift_immed_chain, shift_of_shifted_logic_chain, load_or_combine ,
2022- div_rem_to_divrem, funnel_shift_combines, bitreverse_shift, commute_shift ,
2023- form_bitfield_extract, constant_fold_binops, constant_fold_fma ,
2024- constant_fold_cast_op, fabs_fneg_fold ,
2025- intdiv_combines, mulh_combines, redundant_neg_operands ,
2026- and_or_disjoint_mask, fma_combines, fold_binop_into_select ,
2027- sub_add_reg, select_to_minmax,
2028- fsub_to_fneg, commute_constant_to_rhs, match_ands, match_ors,
2029- simplify_neg_minmax, combine_concat_vector,
2030- sext_trunc, zext_trunc, prefer_sign_combines, shuffle_combines,
2031- combine_use_vector_truncate, merge_combines, overflow_combines]>;
2056+ def all_combines
2057+ : GICombineGroup<
2058+ [integer_reassoc_combines, trivial_combines, vector_ops_combines ,
2059+ freeze_combines, cast_combines, insert_vec_elt_combines ,
2060+ extract_vec_elt_combines, combines_for_extload ,
2061+ combine_extracted_vector_load, undef_combines, poison_combines ,
2062+ identity_combines, phi_combines, simplify_add_to_sub ,
2063+ hoist_logic_op_with_same_opcode_hands, shifts_too_big, reassocs ,
2064+ ptr_add_immed_chain, cmp_combines, shl_ashr_to_sext_inreg ,
2065+ sext_inreg_of_load, width_reduction_combines, select_combines ,
2066+ known_bits_simplifications, trunc_shift, not_cmp_fold ,
2067+ opt_brcond_by_inverting_cond, const_combines ,
2068+ xor_of_and_with_same_reg, ptr_add_with_zero, shift_immed_chain ,
2069+ shift_of_shifted_logic_chain, load_or_combine, div_rem_to_divrem ,
2070+ funnel_shift_combines, bitreverse_shift, commute_shift ,
2071+ form_bitfield_extract, constant_fold_binops, constant_fold_fma ,
2072+ constant_fold_cast_op, fabs_fneg_fold, intdiv_combines ,
2073+ mulh_combines, redundant_neg_operands, and_or_disjoint_mask ,
2074+ fma_combines, fold_binop_into_select, sub_add_reg, select_to_minmax,
2075+ fsub_to_fneg, commute_constant_to_rhs, match_ands, match_ors,
2076+ simplify_neg_minmax, combine_concat_vector, sext_trunc, zext_trunc ,
2077+ prefer_sign_combines, shuffle_combines, combine_use_vector_truncate ,
2078+ merge_combines, overflow_combines]>;
20322079
20332080// A combine group used to for prelegalizer combiners at -O0. The combines in
20342081// this group have been selected based on experiments to balance code size and
0 commit comments