[AArch64] Combine SVE AND and XOR to BIC for _m form #238784
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-aarch64
Author: Vimal Patel (pvimal816a)
<details>
<summary>Changes</summary>
Add patterns to combine the expressions of the following type to BIC when possible:
return svand_u32_m(svptrue_b32(), a, sveor_u32_x(svptrue_b32(), a, b));
Cover symmetric case where result of AND is used by EOR for the above expression.
Cover cases where the inner node is of _u form like sveor_u32_u or sveand_u32_u.
Cover cases where the inner node is of _m/_z form under matching predicates or all-active predicates for the inner node.
Also, cover the case where the inner node is a normal LLVM AND(or XOR) node.
Lower the case where both the predicates are all-active to unpredicated BIC.
---
Full diff: https://github.com/llvm/llvm-project/pull/238784.diff
3 Files Affected:
````````````diff --git a/llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td b/llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
index f097d88be226e..142e12f83af45 100644
--- a/llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
+++ b/llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
@@ -918,6 +918,88 @@ let Predicates = [HasSVE_or_SME] in {
defm : SVEMergingAndNotPats<nxv8i16, nxv8i1, BIC_ZPmZ_H>;
defm : SVEMergingAndNotPats<nxv4i32, nxv4i1, BIC_ZPmZ_S>;
defm : SVEMergingAndNotPats<nxv2i64, nxv2i1, BIC_ZPmZ_D>;
+
+ multiclass SVEMergingAndXorPats<ValueType VT, ValueType PT, Instruction PredBic> {
+ // Inactive lanes in EOR may be replaced by a & ~b in the result.
+ def : Pat<(VT (int_aarch64_sve_and PT:$pg, VT:$a,
+ (VT (SVEEorU (PT srcvalue), VT:$a, VT:$b)))),
+ (PredBic $pg, $a, $b)>;
+
+ // Matching predicate ensures that active lanes in AND can be replaced by a & ~b.
+ def : Pat<(VT (int_aarch64_sve_and PT:$pg, VT:$a,
+ (VT (int_aarch64_sve_eor PT:$pg, VT:$a, VT:$b)))),
+ (PredBic $pg, $a, $b)>;
+
+ // Similar to above, matching predicate ensures that inactive lanes in EOR are don't
+ // care for final result. Rests are equivalent to a & ~b.
+ def : Pat<(VT (int_aarch64_sve_and PT:$pg, VT:$a,
+ (VT (int_aarch64_sve_eor_z PT:$pg, VT:$a, VT:$b)))),
+ (PredBic $pg, $a, $b)>;
+
+ // All active lanes in EOR ensures that all active lanes in AND are equivalent to a & ~b.
+ def : Pat<(VT (int_aarch64_sve_and PT:$pg, VT:$a,
+ (VT (int_aarch64_sve_eor (PT (SVEAllActive)), VT:$a, VT:$b)))),
+ (PredBic $pg, $a, $b)>;
+
+ // Similar to the preceding pattern but for _z form of EOR.
+ def : Pat<(VT (int_aarch64_sve_and PT:$pg, VT:$a,
+ (VT (int_aarch64_sve_eor_z (PT (SVEAllActive)), VT:$a, VT:$b)))),
+ (PredBic $pg, $a, $b)>;
+
+ // Normal LLVM XOR.
+ def : Pat<(VT (int_aarch64_sve_and PT:$pg, VT:$a, (xor VT:$a, VT:$b))),
+ (PredBic $pg, $a, $b)>;
+
+ // There is no active lane in AND. So, unpredicated BIC could be used.
+ def : Pat<(VT (int_aarch64_sve_and (PT (SVEAllActive)), VT:$a,
+ (VT (int_aarch64_sve_eor_z (PT (SVEAllActive)), VT:$a, VT:$b)))),
+ (BIC_ZZZ $a, $b)>;
+ }
+ defm : SVEMergingAndXorPats<nxv16i8, nxv16i1, BIC_ZPmZ_B>;
+ defm : SVEMergingAndXorPats<nxv8i16, nxv8i1, BIC_ZPmZ_H>;
+ defm : SVEMergingAndXorPats<nxv4i32, nxv4i1, BIC_ZPmZ_S>;
+ defm : SVEMergingAndXorPats<nxv2i64, nxv2i1, BIC_ZPmZ_D>;
+
+ multiclass SVEMergingXorAndPats<ValueType VT, ValueType PT, Instruction PredBic> {
+ // Inactive lanes in AND may be replaced by a & b in the result.
+ def : Pat<(VT (int_aarch64_sve_eor PT:$pg, VT:$a,
+ (VT (SVEAndU (PT srcvalue), VT:$a, VT:$b)))),
+ (PredBic $pg, $a, $b)>;
+
+ // Matching predicate ensures that active lanes in EOR can be replaced by a & ~b.
+ def : Pat<(VT (int_aarch64_sve_eor PT:$pg, VT:$a,
+ (VT (int_aarch64_sve_and PT:$pg, VT:$a, VT:$b)))),
+ (PredBic $pg, $a, $b)>;
+
+ // Similar to above, matching predicate ensures that inactive lanes in AND are don't
+ // care for final result. Rests are equivalent to a & ~b.
+ def : Pat<(VT (int_aarch64_sve_eor PT:$pg, VT:$a,
+ (VT (int_aarch64_sve_and_z PT:$pg, VT:$a, VT:$b)))),
+ (PredBic $pg, $a, $b)>;
+
+ // All active lanes in AND ensures that all active lanes in EOR are equivalent to a & ~b.
+ def : Pat<(VT (int_aarch64_sve_eor PT:$pg, VT:$a,
+ (VT (int_aarch64_sve_and (PT (SVEAllActive)), VT:$a, VT:$b)))),
+ (PredBic $pg, $a, $b)>;
+
+ // Similarly, for _z form of AND.
+ def : Pat<(VT (int_aarch64_sve_eor PT:$pg, VT:$a,
+ (VT (int_aarch64_sve_and_z (PT (SVEAllActive)), VT:$a, VT:$b)))),
+ (PredBic $pg, $a, $b)>;
+
+ // Normal LLVM AND.
+ def : Pat<(VT (int_aarch64_sve_eor PT:$pg, VT:$a, (and VT:$a, VT:$b))),
+ (PredBic $pg, $a, $b)>;
+
+ // With both predicates all-active, no inactive lanes need preserving.
+ def : Pat<(VT (int_aarch64_sve_eor (PT (SVEAllActive)), VT:$a,
+ (VT (int_aarch64_sve_and_z (PT (SVEAllActive)), VT:$a, VT:$b)))),
+ (BIC_ZZZ $a, $b)>;
+ }
+ defm : SVEMergingXorAndPats<nxv16i8, nxv16i1, BIC_ZPmZ_B>;
+ defm : SVEMergingXorAndPats<nxv8i16, nxv8i1, BIC_ZPmZ_H>;
+ defm : SVEMergingXorAndPats<nxv4i32, nxv4i1, BIC_ZPmZ_S>;
+ defm : SVEMergingXorAndPats<nxv2i64, nxv2i1, BIC_ZPmZ_D>;
} // End HasSVE_or_SME
let Predicates = [HasSVE_or_SME, UseExperimentalZeroingPseudos] in {
diff --git a/llvm/test/CodeGen/AArch64/sve-intrinsics-and-xor.ll b/llvm/test/CodeGen/AArch64/sve-intrinsics-and-xor.ll
index f7b9934bad87e..0b2c1e9f312e4 100644
--- a/llvm/test/CodeGen/AArch64/sve-intrinsics-and-xor.ll
+++ b/llvm/test/CodeGen/AArch64/sve-intrinsics-and-xor.ll
@@ -97,6 +97,88 @@ define <vscale x 4 x i32> @and_u_eor_z_all_active(<vscale x 4 x i1> %pg, <vscale
ret <vscale x 4 x i32> %and
}
+define <vscale x 4 x i32> @and_m_eor_u(<vscale x 4 x i1> %pg1, <vscale x 4 x i1> %pg2, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b) {
+; CHECK-LABEL: and_m_eor_u:
+; CHECK: // %bb.0:
+; CHECK-NEXT: bic z0.s, p1/m, z0.s, z1.s
+; CHECK-NEXT: ret
+ %eor = tail call <vscale x 4 x i32> @llvm.aarch64.sve.eor.u.nxv4i32(<vscale x 4 x i1> %pg1, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b)
+ %and = tail call <vscale x 4 x i32> @llvm.aarch64.sve.and.nxv4i32(<vscale x 4 x i1> %pg2, <vscale x 4 x i32> %a, <vscale x 4 x i32> %eor)
+ ret <vscale x 4 x i32> %and
+}
+
+define <vscale x 4 x i32> @and_m_xor(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b) {
+; CHECK-LABEL: and_m_xor:
+; CHECK: // %bb.0:
+; CHECK-NEXT: bic z0.s, p0/m, z0.s, z1.s
+; CHECK-NEXT: ret
+ %xor = xor <vscale x 4 x i32> %a, %b
+ %and = tail call <vscale x 4 x i32> @llvm.aarch64.sve.and.nxv4i32(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %xor)
+ ret <vscale x 4 x i32> %and
+}
+
+define <vscale x 4 x i32> @and_m_eor_m(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b) {
+; CHECK-LABEL: and_m_eor_m:
+; CHECK: // %bb.0:
+; CHECK-NEXT: bic z0.s, p0/m, z0.s, z1.s
+; CHECK-NEXT: ret
+ %eor = tail call <vscale x 4 x i32> @llvm.aarch64.sve.eor.nxv4i32(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b)
+ %and = tail call <vscale x 4 x i32> @llvm.aarch64.sve.and.nxv4i32(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %eor)
+ ret <vscale x 4 x i32> %and
+}
+
+define <vscale x 4 x i32> @and_m_eor_m_pred_mismatch(<vscale x 4 x i1> %pg1, <vscale x 4 x i1> %pg2, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b) {
+; CHECK-LABEL: and_m_eor_m_pred_mismatch:
+; CHECK: // %bb.0:
+; CHECK-NEXT: mov z2.d, z0.d
+; CHECK-NEXT: eor z2.s, p0/m, z2.s, z1.s
+; CHECK-NEXT: and z0.s, p1/m, z0.s, z2.s
+; CHECK-NEXT: ret
+ %eor = tail call <vscale x 4 x i32> @llvm.aarch64.sve.eor.nxv4i32(<vscale x 4 x i1> %pg1, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b)
+ %and = tail call <vscale x 4 x i32> @llvm.aarch64.sve.and.nxv4i32(<vscale x 4 x i1> %pg2, <vscale x 4 x i32> %a, <vscale x 4 x i32> %eor)
+ ret <vscale x 4 x i32> %and
+}
+
+define <vscale x 4 x i32> @and_m_eor_z(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b) {
+; CHECK-LABEL: and_m_eor_z:
+; CHECK: // %bb.0:
+; CHECK-NEXT: bic z0.s, p0/m, z0.s, z1.s
+; CHECK-NEXT: ret
+ %eor = tail call <vscale x 4 x i32> @llvm.aarch64.sve.eor.z.nxv4i32(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b)
+ %and = tail call <vscale x 4 x i32> @llvm.aarch64.sve.and.nxv4i32(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %eor)
+ ret <vscale x 4 x i32> %and
+}
+
+define <vscale x 4 x i32> @and_m_eor_m_all_active(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b) {
+; CHECK-LABEL: and_m_eor_m_all_active:
+; CHECK: // %bb.0:
+; CHECK-NEXT: bic z0.s, p0/m, z0.s, z1.s
+; CHECK-NEXT: ret
+ %eor = tail call <vscale x 4 x i32> @llvm.aarch64.sve.eor.nxv4i32(<vscale x 4 x i1> splat (i1 true), <vscale x 4 x i32> %a, <vscale x 4 x i32> %b)
+ %and = tail call <vscale x 4 x i32> @llvm.aarch64.sve.and.nxv4i32(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %eor)
+ ret <vscale x 4 x i32> %and
+}
+
+define <vscale x 4 x i32> @and_m_eor_z_all_active(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b) {
+; CHECK-LABEL: and_m_eor_z_all_active:
+; CHECK: // %bb.0:
+; CHECK-NEXT: bic z0.s, p0/m, z0.s, z1.s
+; CHECK-NEXT: ret
+ %eor = tail call <vscale x 4 x i32> @llvm.aarch64.sve.eor.z.nxv4i32(<vscale x 4 x i1> splat (i1 true), <vscale x 4 x i32> %a, <vscale x 4 x i32> %b)
+ %and = tail call <vscale x 4 x i32> @llvm.aarch64.sve.and.nxv4i32(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %eor)
+ ret <vscale x 4 x i32> %and
+}
+
+define <vscale x 4 x i32> @and_m_all_active_eor_z_all_active(<vscale x 4 x i32> %a, <vscale x 4 x i32> %b) {
+; CHECK-LABEL: and_m_all_active_eor_z_all_active:
+; CHECK: // %bb.0:
+; CHECK-NEXT: bic z0.d, z0.d, z1.d
+; CHECK-NEXT: ret
+ %eor = tail call <vscale x 4 x i32> @llvm.aarch64.sve.eor.z.nxv4i32(<vscale x 4 x i1> splat (i1 true), <vscale x 4 x i32> %a, <vscale x 4 x i32> %b)
+ %and = tail call <vscale x 4 x i32> @llvm.aarch64.sve.and.nxv4i32(<vscale x 4 x i1> splat (i1 true), <vscale x 4 x i32> %a, <vscale x 4 x i32> %eor)
+ ret <vscale x 4 x i32> %and
+}
+
define <vscale x 16 x i8> @and_u_xor_i8(<vscale x 16 x i1> %pg, <vscale x 16 x i8> %a, <vscale x 16 x i8> %b) {
; CHECK-LABEL: and_u_xor_i8:
; CHECK: // %bb.0:
@@ -107,8 +189,42 @@ define <vscale x 16 x i8> @and_u_xor_i8(<vscale x 16 x i1> %pg, <vscale x 16 x i
ret <vscale x 16 x i8> %and
}
+define <vscale x 16 x i8> @and_m_xor_i8(<vscale x 16 x i1> %pg, <vscale x 16 x i8> %a, <vscale x 16 x i8> %b) {
+; CHECK-LABEL: and_m_xor_i8:
+; CHECK: // %bb.0:
+; CHECK-NEXT: bic z0.b, p0/m, z0.b, z1.b
+; CHECK-NEXT: ret
+ %xor = xor <vscale x 16 x i8> %a, %b
+ %and = tail call <vscale x 16 x i8> @llvm.aarch64.sve.and.nxv16i8(<vscale x 16 x i1> %pg, <vscale x 16 x i8> %a, <vscale x 16 x i8> %xor)
+ ret <vscale x 16 x i8> %and
+}
+
+define <vscale x 8 x i16> @and_m_xor_i16(<vscale x 8 x i1> %pg, <vscale x 8 x i16> %a, <vscale x 8 x i16> %b) {
+; CHECK-LABEL: and_m_xor_i16:
+; CHECK: // %bb.0:
+; CHECK-NEXT: bic z0.h, p0/m, z0.h, z1.h
+; CHECK-NEXT: ret
+ %xor = xor <vscale x 8 x i16> %a, %b
+ %and = tail call <vscale x 8 x i16> @llvm.aarch64.sve.and.nxv8i16(<vscale x 8 x i1> %pg, <vscale x 8 x i16> %a, <vscale x 8 x i16> %xor)
+ ret <vscale x 8 x i16> %and
+}
+
+define <vscale x 2 x i64> @and_m_xor_i64(<vscale x 2 x i1> %pg, <vscale x 2 x i64> %a, <vscale x 2 x i64> %b) {
+; CHECK-LABEL: and_m_xor_i64:
+; CHECK: // %bb.0:
+; CHECK-NEXT: bic z0.d, p0/m, z0.d, z1.d
+; CHECK-NEXT: ret
+ %xor = xor <vscale x 2 x i64> %a, %b
+ %and = tail call <vscale x 2 x i64> @llvm.aarch64.sve.and.nxv2i64(<vscale x 2 x i1> %pg, <vscale x 2 x i64> %a, <vscale x 2 x i64> %xor)
+ ret <vscale x 2 x i64> %and
+}
+
+declare <vscale x 16 x i8> @llvm.aarch64.sve.and.nxv16i8(<vscale x 16 x i1>, <vscale x 16 x i8>, <vscale x 16 x i8>)
declare <vscale x 16 x i8> @llvm.aarch64.sve.and.u.nxv16i8(<vscale x 16 x i1>, <vscale x 16 x i8>, <vscale x 16 x i8>)
+declare <vscale x 8 x i16> @llvm.aarch64.sve.and.nxv8i16(<vscale x 8 x i1>, <vscale x 8 x i16>, <vscale x 8 x i16>)
+declare <vscale x 4 x i32> @llvm.aarch64.sve.and.nxv4i32(<vscale x 4 x i1>, <vscale x 4 x i32>, <vscale x 4 x i32>)
declare <vscale x 4 x i32> @llvm.aarch64.sve.and.u.nxv4i32(<vscale x 4 x i1>, <vscale x 4 x i32>, <vscale x 4 x i32>)
+declare <vscale x 2 x i64> @llvm.aarch64.sve.and.nxv2i64(<vscale x 2 x i1>, <vscale x 2 x i64>, <vscale x 2 x i64>)
declare <vscale x 4 x i32> @llvm.aarch64.sve.eor.u.nxv4i32(<vscale x 4 x i1>, <vscale x 4 x i32>, <vscale x 4 x i32>)
declare <vscale x 4 x i32> @llvm.aarch64.sve.eor.nxv4i32(<vscale x 4 x i1>, <vscale x 4 x i32>, <vscale x 4 x i32>)
declare <vscale x 4 x i32> @llvm.aarch64.sve.eor.z.nxv4i32(<vscale x 4 x i1>, <vscale x 4 x i32>, <vscale x 4 x i32>)
diff --git a/llvm/test/CodeGen/AArch64/sve-intrinsics-xor-and.ll b/llvm/test/CodeGen/AArch64/sve-intrinsics-xor-and.ll
index fff20818d9b0d..d742fcc50ab34 100644
--- a/llvm/test/CodeGen/AArch64/sve-intrinsics-xor-and.ll
+++ b/llvm/test/CodeGen/AArch64/sve-intrinsics-xor-and.ll
@@ -97,6 +97,88 @@ define <vscale x 4 x i32> @eor_u_and_z_all_active(<vscale x 4 x i1> %pg, <vscale
ret <vscale x 4 x i32> %eor
}
+define <vscale x 4 x i32> @eor_m_and_u(<vscale x 4 x i1> %pg1, <vscale x 4 x i1> %pg2, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b) {
+; CHECK-LABEL: eor_m_and_u:
+; CHECK: // %bb.0:
+; CHECK-NEXT: bic z0.s, p1/m, z0.s, z1.s
+; CHECK-NEXT: ret
+ %and = tail call <vscale x 4 x i32> @llvm.aarch64.sve.and.u.nxv4i32(<vscale x 4 x i1> %pg1, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b)
+ %eor = tail call <vscale x 4 x i32> @llvm.aarch64.sve.eor.nxv4i32(<vscale x 4 x i1> %pg2, <vscale x 4 x i32> %a, <vscale x 4 x i32> %and)
+ ret <vscale x 4 x i32> %eor
+}
+
+define <vscale x 4 x i32> @eor_m_and(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b) {
+; CHECK-LABEL: eor_m_and:
+; CHECK: // %bb.0:
+; CHECK-NEXT: bic z0.s, p0/m, z0.s, z1.s
+; CHECK-NEXT: ret
+ %and = and <vscale x 4 x i32> %a, %b
+ %eor = tail call <vscale x 4 x i32> @llvm.aarch64.sve.eor.nxv4i32(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %and)
+ ret <vscale x 4 x i32> %eor
+}
+
+define <vscale x 4 x i32> @eor_m_and_m(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b) {
+; CHECK-LABEL: eor_m_and_m:
+; CHECK: // %bb.0:
+; CHECK-NEXT: bic z0.s, p0/m, z0.s, z1.s
+; CHECK-NEXT: ret
+ %and = tail call <vscale x 4 x i32> @llvm.aarch64.sve.and.nxv4i32(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b)
+ %eor = tail call <vscale x 4 x i32> @llvm.aarch64.sve.eor.nxv4i32(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %and)
+ ret <vscale x 4 x i32> %eor
+}
+
+define <vscale x 4 x i32> @eor_m_and_m_pred_mismatch(<vscale x 4 x i1> %pg1, <vscale x 4 x i1> %pg2, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b) {
+; CHECK-LABEL: eor_m_and_m_pred_mismatch:
+; CHECK: // %bb.0:
+; CHECK-NEXT: mov z2.d, z0.d
+; CHECK-NEXT: and z2.s, p0/m, z2.s, z1.s
+; CHECK-NEXT: eor z0.s, p1/m, z0.s, z2.s
+; CHECK-NEXT: ret
+ %and = tail call <vscale x 4 x i32> @llvm.aarch64.sve.and.nxv4i32(<vscale x 4 x i1> %pg1, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b)
+ %eor = tail call <vscale x 4 x i32> @llvm.aarch64.sve.eor.nxv4i32(<vscale x 4 x i1> %pg2, <vscale x 4 x i32> %a, <vscale x 4 x i32> %and)
+ ret <vscale x 4 x i32> %eor
+}
+
+define <vscale x 4 x i32> @eor_m_and_z(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b) {
+; CHECK-LABEL: eor_m_and_z:
+; CHECK: // %bb.0:
+; CHECK-NEXT: bic z0.s, p0/m, z0.s, z1.s
+; CHECK-NEXT: ret
+ %and = tail call <vscale x 4 x i32> @llvm.aarch64.sve.and.z.nxv4i32(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b)
+ %eor = tail call <vscale x 4 x i32> @llvm.aarch64.sve.eor.nxv4i32(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %and)
+ ret <vscale x 4 x i32> %eor
+}
+
+define <vscale x 4 x i32> @eor_m_and_m_all_active(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b) {
+; CHECK-LABEL: eor_m_and_m_all_active:
+; CHECK: // %bb.0:
+; CHECK-NEXT: bic z0.s, p0/m, z0.s, z1.s
+; CHECK-NEXT: ret
+ %and = tail call <vscale x 4 x i32> @llvm.aarch64.sve.and.nxv4i32(<vscale x 4 x i1> splat (i1 true), <vscale x 4 x i32> %a, <vscale x 4 x i32> %b)
+ %eor = tail call <vscale x 4 x i32> @llvm.aarch64.sve.eor.nxv4i32(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %and)
+ ret <vscale x 4 x i32> %eor
+}
+
+define <vscale x 4 x i32> @eor_m_and_z_all_active(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b) {
+; CHECK-LABEL: eor_m_and_z_all_active:
+; CHECK: // %bb.0:
+; CHECK-NEXT: bic z0.s, p0/m, z0.s, z1.s
+; CHECK-NEXT: ret
+ %and = tail call <vscale x 4 x i32> @llvm.aarch64.sve.and.z.nxv4i32(<vscale x 4 x i1> splat (i1 true), <vscale x 4 x i32> %a, <vscale x 4 x i32> %b)
+ %eor = tail call <vscale x 4 x i32> @llvm.aarch64.sve.eor.nxv4i32(<vscale x 4 x i1> %pg, <vscale x 4 x i32> %a, <vscale x 4 x i32> %and)
+ ret <vscale x 4 x i32> %eor
+}
+
+define <vscale x 4 x i32> @eor_m_all_active_and_z_all_active(<vscale x 4 x i32> %a, <vscale x 4 x i32> %b) {
+; CHECK-LABEL: eor_m_all_active_and_z_all_active:
+; CHECK: // %bb.0:
+; CHECK-NEXT: bic z0.d, z0.d, z1.d
+; CHECK-NEXT: ret
+ %and = tail call <vscale x 4 x i32> @llvm.aarch64.sve.and.z.nxv4i32(<vscale x 4 x i1> splat (i1 true), <vscale x 4 x i32> %a, <vscale x 4 x i32> %b)
+ %eor = tail call <vscale x 4 x i32> @llvm.aarch64.sve.eor.nxv4i32(<vscale x 4 x i1> splat (i1 true), <vscale x 4 x i32> %a, <vscale x 4 x i32> %and)
+ ret <vscale x 4 x i32> %eor
+}
+
define <vscale x 16 x i8> @eor_u_and_i8(<vscale x 16 x i1> %pg, <vscale x 16 x i8> %a, <vscale x 16 x i8> %b) {
; CHECK-LABEL: eor_u_and_i8:
; CHECK: // %bb.0:
@@ -107,11 +189,45 @@ define <vscale x 16 x i8> @eor_u_and_i8(<vscale x 16 x i1> %pg, <vscale x 16 x i
ret <vscale x 16 x i8> %eor
}
+define <vscale x 16 x i8> @eor_m_and_i8(<vscale x 16 x i1> %pg, <vscale x 16 x i8> %a, <vscale x 16 x i8> %b) {
+; CHECK-LABEL: eor_m_and_i8:
+; CHECK: // %bb.0:
+; CHECK-NEXT: bic z0.b, p0/m, z0.b, z1.b
+; CHECK-NEXT: ret
+ %and = and <vscale x 16 x i8> %a, %b
+ %eor = tail call <vscale x 16 x i8> @llvm.aarch64.sve.eor.nxv16i8(<vscale x 16 x i1> %pg, <vscale x 16 x i8> %a, <vscale x 16 x i8> %and)
+ ret <vscale x 16 x i8> %eor
+}
+
+define <vscale x 8 x i16> @eor_m_and_i16(<vscale x 8 x i1> %pg, <vscale x 8 x i16> %a, <vscale x 8 x i16> %b) {
+; CHECK-LABEL: eor_m_and_i16:
+; CHECK: // %bb.0:
+; CHECK-NEXT: bic z0.h, p0/m, z0.h, z1.h
+; CHECK-NEXT: ret
+ %and = and <vscale x 8 x i16> %a, %b
+ %eor = tail call <vscale x 8 x i16> @llvm.aarch64.sve.eor.nxv8i16(<vscale x 8 x i1> %pg, <vscale x 8 x i16> %a, <vscale x 8 x i16> %and)
+ ret <vscale x 8 x i16> %eor
+}
+
+define <vscale x 2 x i64> @eor_m_and_i64(<vscale x 2 x i1> %pg, <vscale x 2 x i64> %a, <vscale x 2 x i64> %b) {
+; CHECK-LABEL: eor_m_and_i64:
+; CHECK: // %bb.0:
+; CHECK-NEXT: bic z0.d, p0/m, z0.d, z1.d
+; CHECK-NEXT: ret
+ %and = and <vscale x 2 x i64> %a, %b
+ %eor = tail call <vscale x 2 x i64> @llvm.aarch64.sve.eor.nxv2i64(<vscale x 2 x i1> %pg, <vscale x 2 x i64> %a, <vscale x 2 x i64> %and)
+ ret <vscale x 2 x i64> %eor
+}
+
declare <vscale x 16 x i8> @llvm.aarch64.sve.eor.u.nxv16i8(<vscale x 16 x i1>, <vscale x 16 x i8>, <vscale x 16 x i8>)
+declare <vscale x 16 x i8> @llvm.aarch64.sve.eor.nxv16i8(<vscale x 16 x i1>, <vscale x 16 x i8>, <vscale x 16 x i8>)
+declare <vscale x 8 x i16> @llvm.aarch64.sve.eor.nxv8i16(<vscale x 8 x i1>, <vscale x 8 x i16>, <vscale x 8 x i16>)
declare <vscale x 4 x i32> @llvm.aarch64.sve.and.u.nxv4i32(<vscale x 4 x i1>, <vscale x 4 x i32>, <vscale x 4 x i32>)
declare <vscale x 4 x i32> @llvm.aarch64.sve.eor.u.nxv4i32(<vscale x 4 x i1>, <vscale x 4 x i32>, <vscale x 4 x i32>)
+declare <vscale x 4 x i32> @llvm.aarch64.sve.eor.nxv4i32(<vscale x 4 x i1>, <vscale x 4 x i32>, <vscale x 4 x i32>)
declare <vscale x 4 x i32> @llvm.aarch64.sve.and.nxv4i32(<vscale x 4 x i1>, <vscale x 4 x i32>, <vscale x 4 x i32>)
declare <vscale x 4 x i32> @llvm.aarch64.sve.and.z.nxv4i32(<vscale x 4 x i1>, <vscale x 4 x i32>, <vscale x 4 x i32>)
+declare <vscale x 2 x i64> @llvm.aarch64.sve.eor.nxv2i64(<vscale x 2 x i1>, <vscale x 2 x i64>, <vscale x 2 x i64>)
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
; SME: {{.*}}
; SVE: {{.*}}
</details>
Have you consider adding this to the multiclass where BIC_ZPmZ is defined
Looks like I missed it. Let me check.
CarolineConcatto
pvimal816a
Add patterns to combine the expressions of the following type to BIC when possible:
Cover symmetric case where result of AND is used by EOR for the above expression.
Cover cases where the inner node is of _u form like sveor_u32_u or sveand_u32_u.
Cover cases where the inner node is of _m/_z form under matching predicates or all-active predicates for the inner node.
Also, cover the case where the inner node is a normal LLVM AND(or XOR) node.
Lower the case where both the predicates are all-active to unpredicated BIC.