Skip to content

Commit 71c06bb

Browse files
authored
[GlobalISel] Combine (X == 0) & (Y == 0) -> (X | Y) == 0 (#71949)
Also combine (X != 0) | (Y != 0) -> (X | Y) != 0
1 parent 81d94ca commit 71c06bb

File tree

2 files changed

+1276
-1
lines changed

2 files changed

+1276
-1
lines changed

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

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

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+
955986
def and_or_disjoint_mask : GICombineRule<
956987
(defs root:$root, build_fn_matchinfo:$info),
957988
(match (wip_match_opcode G_AND):$root,
@@ -1343,7 +1374,7 @@ def all_combines : GICombineGroup<[trivial_combines, insert_vec_elt_combines,
13431374
and_or_disjoint_mask, fma_combines, fold_binop_into_select,
13441375
sub_add_reg, select_to_minmax, redundant_binop_in_equality,
13451376
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]>;
13471378

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

0 commit comments

Comments
 (0)