@@ -952,6 +952,37 @@ def redundant_binop_in_equality : GICombineRule<
952
952
[{ return Helper.matchRedundantBinOpInEquality(*${root}, ${info}); }]),
953
953
(apply [{ Helper.applyBuildFn(*${root}, ${info}); }])>;
954
954
955
+ // Transform: (X == 0 & Y == 0) -> (X | Y) == 0
956
+ def double_icmp_zero_and_combine: GICombineRule<
957
+ (defs root:$root),
958
+ (match (G_ICMP $d1, $p, $s1, 0),
959
+ (G_ICMP $d2, $p, $s2, 0),
960
+ (G_AND $root, $d1, $d2),
961
+ [{ return ${p}.getPredicate() == CmpInst::ICMP_EQ &&
962
+ !MRI.getType(${s1}.getReg()).getScalarType().isPointer() &&
963
+ (MRI.getType(${s1}.getReg()) ==
964
+ MRI.getType(${s2}.getReg())); }]),
965
+ (apply (G_OR $ordst, $s1, $s2),
966
+ (G_ICMP $root, $p, $ordst, 0))
967
+ >;
968
+
969
+ // Transform: (X != 0 | Y != 0) -> (X | Y) != 0
970
+ def double_icmp_zero_or_combine: GICombineRule<
971
+ (defs root:$root),
972
+ (match (G_ICMP $d1, $p, $s1, 0),
973
+ (G_ICMP $d2, $p, $s2, 0),
974
+ (G_OR $root, $d1, $d2),
975
+ [{ return ${p}.getPredicate() == CmpInst::ICMP_NE &&
976
+ !MRI.getType(${s1}.getReg()).getScalarType().isPointer() &&
977
+ (MRI.getType(${s1}.getReg()) ==
978
+ MRI.getType(${s2}.getReg())); }]),
979
+ (apply (G_OR $ordst, $s1, $s2),
980
+ (G_ICMP $root, $p, $ordst, 0))
981
+ >;
982
+
983
+ def double_icmp_zero_and_or_combine : GICombineGroup<[double_icmp_zero_and_combine,
984
+ double_icmp_zero_or_combine]>;
985
+
955
986
def and_or_disjoint_mask : GICombineRule<
956
987
(defs root:$root, build_fn_matchinfo:$info),
957
988
(match (wip_match_opcode G_AND):$root,
@@ -1343,7 +1374,7 @@ def all_combines : GICombineGroup<[trivial_combines, insert_vec_elt_combines,
1343
1374
and_or_disjoint_mask, fma_combines, fold_binop_into_select,
1344
1375
sub_add_reg, select_to_minmax, redundant_binop_in_equality,
1345
1376
fsub_to_fneg, commute_constant_to_rhs, match_ands, match_ors,
1346
- combine_concat_vector]>;
1377
+ combine_concat_vector, double_icmp_zero_and_or_combine ]>;
1347
1378
1348
1379
// A combine group used to for prelegalizer combiners at -O0. The combines in
1349
1380
// this group have been selected based on experiments to balance code size and
0 commit comments