Skip to content

Commit 1eadb1f

Browse files
committed
[GlobalISel] Combine (X == 0) & (Y == 0) -> (X | Y) == 0
Also combine (X != 0) | (Y != 0) -> (X | Y) != 0
1 parent 2b804f8 commit 1eadb1f

File tree

3 files changed

+809
-37
lines changed

3 files changed

+809
-37
lines changed

llvm/include/llvm/Target/GlobalISel/Combine.td

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,37 @@ def redundant_binop_in_equality : GICombineRule<
945945
[{ return Helper.matchRedundantBinOpInEquality(*${root}, ${info}); }]),
946946
(apply [{ Helper.applyBuildFn(*${root}, ${info}); }])>;
947947

948+
// Transform: (X == 0 & Y == 0) -> (X | Y) == 0
949+
def double_icmp_zero_and_combine: GICombineRule<
950+
(defs root:$root),
951+
(match (G_ICMP $d1, $p, $s1, 0),
952+
(G_ICMP $d2, $p, $s2, 0),
953+
(G_AND $root, $d1, $d2),
954+
[{ return ${p}.getPredicate() == CmpInst::ICMP_EQ &&
955+
!MRI.getType(${s1}.getReg()).isPointer() &&
956+
(MRI.getType(${s1}.getReg()) ==
957+
MRI.getType(${s2}.getReg())); }]),
958+
(apply (G_OR $ordst, $s1, $s2),
959+
(G_ICMP $root, $p, $ordst, 0))
960+
>;
961+
962+
// Transform: (X != 0 | Y != 0) -> (X | Y) != 0
963+
def double_icmp_zero_or_combine: GICombineRule<
964+
(defs root:$root),
965+
(match (G_ICMP $d1, $p, $s1, 0),
966+
(G_ICMP $d2, $p, $s2, 0),
967+
(G_OR $root, $d1, $d2),
968+
[{ return ${p}.getPredicate() == CmpInst::ICMP_NE &&
969+
!MRI.getType(${s1}.getReg()).isPointer() &&
970+
(MRI.getType(${s1}.getReg()) ==
971+
MRI.getType(${s2}.getReg())); }]),
972+
(apply (G_OR $ordst, $s1, $s2),
973+
(G_ICMP $root, $p, $ordst, 0))
974+
>;
975+
976+
def double_icmp_zero_and_or_combine : GICombineGroup<[double_icmp_zero_and_combine,
977+
double_icmp_zero_or_combine]>;
978+
948979
def and_or_disjoint_mask : GICombineRule<
949980
(defs root:$root, build_fn_matchinfo:$info),
950981
(match (wip_match_opcode G_AND):$root,
@@ -1314,7 +1345,7 @@ def all_combines : GICombineGroup<[trivial_combines, insert_vec_elt_combines,
13141345
intdiv_combines, mulh_combines, redundant_neg_operands,
13151346
and_or_disjoint_mask, fma_combines, fold_binop_into_select,
13161347
sub_add_reg, select_to_minmax, redundant_binop_in_equality,
1317-
fsub_to_fneg, commute_constant_to_rhs]>;
1348+
double_icmp_zero_and_or_combine, fsub_to_fneg, commute_constant_to_rhs]>;
13181349

13191350
// A combine group used to for prelegalizer combiners at -O0. The combines in
13201351
// this group have been selected based on experiments to balance code size and

0 commit comments

Comments
 (0)