Skip to content

Commit fc3f891

Browse files
committed
[GlobalISel] Combine (X == 0) & (Y == 0) -> (X | Y) == 0
Also combine (X != 0) | (Y != 0) -> (X | Y) != 0
1 parent 8e2bd05 commit fc3f891

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
@@ -903,6 +903,37 @@ def redundant_binop_in_equality : GICombineRule<
903903
[{ return Helper.matchRedundantBinOpInEquality(*${root}, ${info}); }]),
904904
(apply [{ Helper.applyBuildFn(*${root}, ${info}); }])>;
905905

906+
// Transform: (X == 0 & Y == 0) -> (X | Y) == 0
907+
def double_icmp_zero_and_combine: GICombineRule<
908+
(defs root:$root),
909+
(match (G_ICMP $d1, $p, $s1, 0),
910+
(G_ICMP $d2, $p, $s2, 0),
911+
(G_AND $root, $d1, $d2),
912+
[{ return ${p}.getPredicate() == CmpInst::ICMP_EQ &&
913+
!MRI.getType(${s1}.getReg()).isPointer() &&
914+
(MRI.getType(${s1}.getReg()) ==
915+
MRI.getType(${s2}.getReg())); }]),
916+
(apply (G_OR i32:$ordst, $s1, $s2),
917+
(G_ICMP $root, $p, $ordst, 0))
918+
>;
919+
920+
// Transform: (X != 0 | Y != 0) -> (X | Y) != 0
921+
def double_icmp_zero_or_combine: GICombineRule<
922+
(defs root:$root),
923+
(match (G_ICMP $d1, $p, $s1, 0),
924+
(G_ICMP $d2, $p, $s2, 0),
925+
(G_OR $root, $d1, $d2),
926+
[{ return ${p}.getPredicate() == CmpInst::ICMP_NE &&
927+
!MRI.getType(${s1}.getReg()).isPointer() &&
928+
(MRI.getType(${s1}.getReg()) ==
929+
MRI.getType(${s2}.getReg())); }]),
930+
(apply (G_OR i32:$ordst, $s1, $s2),
931+
(G_ICMP $root, $p, $ordst, 0))
932+
>;
933+
934+
def double_icmp_zero_and_or_combine : GICombineGroup<[double_icmp_zero_and_combine,
935+
double_icmp_zero_or_combine]>;
936+
906937
def and_or_disjoint_mask : GICombineRule<
907938
(defs root:$root, build_fn_matchinfo:$info),
908939
(match (wip_match_opcode G_AND):$root,
@@ -1265,7 +1296,7 @@ def all_combines : GICombineGroup<[trivial_combines, insert_vec_elt_combines,
12651296
intdiv_combines, mulh_combines, redundant_neg_operands,
12661297
and_or_disjoint_mask, fma_combines, fold_binop_into_select,
12671298
sub_add_reg, select_to_minmax, redundant_binop_in_equality,
1268-
fsub_to_fneg, commute_constant_to_rhs]>;
1299+
double_icmp_zero_and_or_combine, fsub_to_fneg, commute_constant_to_rhs]>;
12691300

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

0 commit comments

Comments
 (0)