diff --git a/llvm/lib/Target/AArch64/SVEInstrFormats.td b/llvm/lib/Target/AArch64/SVEInstrFormats.td --- a/llvm/lib/Target/AArch64/SVEInstrFormats.td +++ b/llvm/lib/Target/AArch64/SVEInstrFormats.td @@ -627,6 +627,8 @@ let Constraints = "$Pdn = $_Pdn"; let Defs = [NZCV]; + let isPTestLike = 1; + let ElementSize = pprty.ElementSize; } multiclass sve_int_pfirst opc, string asm, SDPatternOperator op> { diff --git a/llvm/test/CodeGen/AArch64/sve-ptest-removal-pnext.ll b/llvm/test/CodeGen/AArch64/sve-ptest-removal-pnext.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/AArch64/sve-ptest-removal-pnext.ll @@ -0,0 +1,144 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc -mtriple=aarch64--linux-gnu -mattr=+sve %s -o - | FileCheck %s + +define i32 @pfirst_16( %pg, %a) { +; CHECK-LABEL: pfirst_16: +; CHECK: // %bb.0: +; CHECK-NEXT: pfirst p1.b, p0, p1.b +; CHECK-NEXT: cset w0, ne +; CHECK-NEXT: ret + %1 = tail call @llvm.aarch64.sve.pfirst.nxv16i1( %pg, %a) + %2 = tail call i1 @llvm.aarch64.sve.ptest.any.nxv16i1( %pg, %1) + %conv = zext i1 %2 to i32 + ret i32 %conv +} + +define i32 @pfirst_neg_16( %pg, %a) { +; CHECK-LABEL: pfirst_neg_16: +; CHECK: // %bb.0: +; CHECK-NEXT: mov p2.b, p1.b +; CHECK-NEXT: pfirst p2.b, p0, p2.b +; CHECK-NEXT: ptest p1, p2.b +; CHECK-NEXT: cset w0, ne +; CHECK-NEXT: ret + %1 = tail call @llvm.aarch64.sve.pfirst.nxv16i1( %pg, %a) + %2 = tail call i1 @llvm.aarch64.sve.ptest.any.nxv16i1( %a, %1) + %conv = zext i1 %2 to i32 + ret i32 %conv +} + +define i32 @pnext_16( %pg, %a) { +; CHECK-LABEL: pnext_16: +; CHECK: // %bb.0: +; CHECK-NEXT: pnext p1.b, p0, p1.b +; CHECK-NEXT: cset w0, ne +; CHECK-NEXT: ret + %1 = tail call @llvm.aarch64.sve.pnext.nxv16i1( %pg, %a) + %2 = tail call i1 @llvm.aarch64.sve.ptest.any.nxv16i1( %pg, %1) + %conv = zext i1 %2 to i32 + ret i32 %conv +} + +define i32 @pnext_neg_16( %pg, %a) { +; CHECK-LABEL: pnext_neg_16: +; CHECK: // %bb.0: +; CHECK-NEXT: mov p2.b, p1.b +; CHECK-NEXT: pnext p2.b, p0, p2.b +; CHECK-NEXT: ptest p1, p2.b +; CHECK-NEXT: cset w0, ne +; CHECK-NEXT: ret + %1 = tail call @llvm.aarch64.sve.pnext.nxv16i1( %pg, %a) + %2 = tail call i1 @llvm.aarch64.sve.ptest.any.nxv16i1( %a, %1) + %conv = zext i1 %2 to i32 + ret i32 %conv +} + +define i32 @pnext_8( %pg, %a) { +; CHECK-LABEL: pnext_8: +; CHECK: // %bb.0: +; CHECK-NEXT: pnext p1.h, p0, p1.h +; CHECK-NEXT: cset w0, ne +; CHECK-NEXT: ret + %1 = tail call @llvm.aarch64.sve.pnext.nxv8i1( %pg, %a) + %2 = tail call i1 @llvm.aarch64.sve.ptest.any.nxv8i1( %pg, %1) + %conv = zext i1 %2 to i32 + ret i32 %conv +} + +define i32 @pnext_neg_8( %pg, %a) { +; CHECK-LABEL: pnext_neg_8: +; CHECK: // %bb.0: +; CHECK-NEXT: mov p2.b, p1.b +; CHECK-NEXT: pnext p2.h, p0, p2.h +; CHECK-NEXT: ptest p1, p2.b +; CHECK-NEXT: cset w0, ne +; CHECK-NEXT: ret + %1 = tail call @llvm.aarch64.sve.pnext.nxv8i1( %pg, %a) + %2 = tail call i1 @llvm.aarch64.sve.ptest.any.nxv8i1( %a, %1) + %conv = zext i1 %2 to i32 + ret i32 %conv +} + +define i32 @pnext_4( %pg, %a) { +; CHECK-LABEL: pnext_4: +; CHECK: // %bb.0: +; CHECK-NEXT: pnext p1.s, p0, p1.s +; CHECK-NEXT: cset w0, ne +; CHECK-NEXT: ret + %1 = tail call @llvm.aarch64.sve.pnext.nxv4i1( %pg, %a) + %2 = tail call i1 @llvm.aarch64.sve.ptest.any.nxv4i1( %pg, %1) + %conv = zext i1 %2 to i32 + ret i32 %conv +} + +define i32 @pnext_neg_4( %pg, %a) { +; CHECK-LABEL: pnext_neg_4: +; CHECK: // %bb.0: +; CHECK-NEXT: mov p2.b, p1.b +; CHECK-NEXT: pnext p2.s, p0, p2.s +; CHECK-NEXT: ptest p1, p2.b +; CHECK-NEXT: cset w0, ne +; CHECK-NEXT: ret + %1 = tail call @llvm.aarch64.sve.pnext.nxv4i1( %pg, %a) + %2 = tail call i1 @llvm.aarch64.sve.ptest.any.nxv4i1( %a, %1) + %conv = zext i1 %2 to i32 + ret i32 %conv +} + +define i32 @pnext_2( %pg, %a) { +; CHECK-LABEL: pnext_2: +; CHECK: // %bb.0: +; CHECK-NEXT: pnext p1.d, p0, p1.d +; CHECK-NEXT: cset w0, ne +; CHECK-NEXT: ret + %1 = tail call @llvm.aarch64.sve.pnext.nxv2i1( %pg, %a) + %2 = tail call i1 @llvm.aarch64.sve.ptest.any.nxv2i1( %pg, %1) + %conv = zext i1 %2 to i32 + ret i32 %conv +} + +define i32 @pnext_neg_2( %pg, %a) { +; CHECK-LABEL: pnext_neg_2: +; CHECK: // %bb.0: +; CHECK-NEXT: mov p2.b, p1.b +; CHECK-NEXT: pnext p2.d, p0, p2.d +; CHECK-NEXT: ptest p1, p2.b +; CHECK-NEXT: cset w0, ne +; CHECK-NEXT: ret + %1 = tail call @llvm.aarch64.sve.pnext.nxv2i1( %pg, %a) + %2 = tail call i1 @llvm.aarch64.sve.ptest.any.nxv2i1( %a, %1) + %conv = zext i1 %2 to i32 + ret i32 %conv +} + +declare @llvm.aarch64.sve.pfirst.nxv16i1(, ) + +declare @llvm.aarch64.sve.pnext.nxv16i1(, ) +declare @llvm.aarch64.sve.pnext.nxv8i1(, ) +declare @llvm.aarch64.sve.pnext.nxv4i1(, ) +declare @llvm.aarch64.sve.pnext.nxv2i1(, ) + +declare i1 @llvm.aarch64.sve.ptest.any.nxv16i1(, ) +declare i1 @llvm.aarch64.sve.ptest.any.nxv8i1(, ) +declare i1 @llvm.aarch64.sve.ptest.any.nxv4i1(, ) +declare i1 @llvm.aarch64.sve.ptest.any.nxv2i1(, )