|
| 1 | +; RUN: opt -passes=instcombine -mtriple aarch64 -mattr=+sve -S -o - < %s | FileCheck %s |
| 2 | +; |
| 3 | +; Test AArch64-specific InstCombine optimizations for SVE logical operations |
| 4 | +; with all-true predicates. |
| 5 | +; - a AND true = a |
| 6 | +; - a OR true = true |
| 7 | + |
| 8 | +declare <vscale x 16 x i1> @llvm.aarch64.sve.and.z.nxv16i1(<vscale x 16 x i1>, <vscale x 16 x i1>, <vscale x 16 x i1>) |
| 9 | +declare <vscale x 16 x i1> @llvm.aarch64.sve.orr.z.nxv16i1(<vscale x 16 x i1>, <vscale x 16 x i1>, <vscale x 16 x i1>) |
| 10 | +declare <vscale x 16 x i1> @llvm.aarch64.sve.convert.to.svbool.nxv8i1(<vscale x 8 x i1>) |
| 11 | +declare <vscale x 8 x i1> @llvm.aarch64.sve.convert.from.svbool.nxv8i1(<vscale x 16 x i1>) |
| 12 | +declare <vscale x 8 x i1> @llvm.aarch64.sve.pnext.nxv8i1(<vscale x 8 x i1>, <vscale x 8 x i1>) |
| 13 | + |
| 14 | +define <vscale x 16 x i1> @test_sve_and_z_all_true_right(<vscale x 16 x i1> %a) { |
| 15 | +; CHECK-LABEL: @test_sve_and_z_all_true_right( |
| 16 | +; CHECK-NEXT: ret <vscale x 16 x i1> [[A:%.*]] |
| 17 | + %all_true = tail call <vscale x 16 x i1> @llvm.aarch64.sve.convert.to.svbool.nxv8i1(<vscale x 8 x i1> splat (i1 true)) |
| 18 | + %result = tail call <vscale x 16 x i1> @llvm.aarch64.sve.and.z.nxv16i1(<vscale x 16 x i1> splat (i1 true), <vscale x 16 x i1> %a, <vscale x 16 x i1> %all_true) |
| 19 | + ret <vscale x 16 x i1> %result |
| 20 | +} |
| 21 | + |
| 22 | +define <vscale x 16 x i1> @test_sve_and_z_all_true_left(<vscale x 16 x i1> %a) { |
| 23 | +; CHECK-LABEL: @test_sve_and_z_all_true_left( |
| 24 | +; CHECK-NEXT: ret <vscale x 16 x i1> [[A:%.*]] |
| 25 | + %all_true = tail call <vscale x 16 x i1> @llvm.aarch64.sve.convert.to.svbool.nxv8i1(<vscale x 8 x i1> splat (i1 true)) |
| 26 | + %result = tail call <vscale x 16 x i1> @llvm.aarch64.sve.and.z.nxv16i1(<vscale x 16 x i1> splat (i1 true), <vscale x 16 x i1> %all_true, <vscale x 16 x i1> %a) |
| 27 | + ret <vscale x 16 x i1> %result |
| 28 | +} |
| 29 | + |
| 30 | +define <vscale x 16 x i1> @test_sve_orr_z_all_true_right(<vscale x 16 x i1> %a) { |
| 31 | +; CHECK-LABEL: @test_sve_orr_z_all_true_right( |
| 32 | +; CHECK-NEXT: [[ALL_TRUE:%.*]] = tail call <vscale x 16 x i1> @llvm.aarch64.sve.convert.to.svbool.nxv8i1(<vscale x 8 x i1> splat (i1 true)) |
| 33 | +; CHECK-NEXT: ret <vscale x 16 x i1> [[ALL_TRUE]] |
| 34 | + %all_true = tail call <vscale x 16 x i1> @llvm.aarch64.sve.convert.to.svbool.nxv8i1(<vscale x 8 x i1> splat (i1 true)) |
| 35 | + %result = tail call <vscale x 16 x i1> @llvm.aarch64.sve.orr.z.nxv16i1(<vscale x 16 x i1> splat (i1 true), <vscale x 16 x i1> %a, <vscale x 16 x i1> %all_true) |
| 36 | + ret <vscale x 16 x i1> %result |
| 37 | +} |
| 38 | + |
| 39 | +define <vscale x 16 x i1> @test_sve_orr_z_all_true_left(<vscale x 16 x i1> %a) { |
| 40 | +; CHECK-LABEL: @test_sve_orr_z_all_true_left( |
| 41 | +; CHECK-NEXT: [[ALL_TRUE:%.*]] = tail call <vscale x 16 x i1> @llvm.aarch64.sve.convert.to.svbool.nxv8i1(<vscale x 8 x i1> splat (i1 true)) |
| 42 | +; CHECK-NEXT: ret <vscale x 16 x i1> [[ALL_TRUE]] |
| 43 | + %all_true = tail call <vscale x 16 x i1> @llvm.aarch64.sve.convert.to.svbool.nxv8i1(<vscale x 8 x i1> splat (i1 true)) |
| 44 | + %result = tail call <vscale x 16 x i1> @llvm.aarch64.sve.orr.z.nxv16i1(<vscale x 16 x i1> splat (i1 true), <vscale x 16 x i1> %all_true, <vscale x 16 x i1> %a) |
| 45 | + ret <vscale x 16 x i1> %result |
| 46 | +} |
| 47 | + |
| 48 | +define <vscale x 16 x i1> @test_original_bug_case(<vscale x 16 x i1> %pg, <vscale x 16 x i1> %prev) { |
| 49 | +; CHECK-LABEL: @test_original_bug_case( |
| 50 | +; CHECK-NEXT: [[TMP1:%.*]] = tail call <vscale x 8 x i1> @llvm.aarch64.sve.convert.from.svbool.nxv8i1(<vscale x 16 x i1> [[PG:%.*]]) |
| 51 | +; CHECK-NEXT: [[TMP2:%.*]] = tail call <vscale x 8 x i1> @llvm.aarch64.sve.convert.from.svbool.nxv8i1(<vscale x 16 x i1> [[PREV:%.*]]) |
| 52 | +; CHECK-NEXT: [[TMP3:%.*]] = tail call <vscale x 8 x i1> @llvm.aarch64.sve.pnext.nxv8i1(<vscale x 8 x i1> [[TMP1]], <vscale x 8 x i1> [[TMP2]]) |
| 53 | +; CHECK-NEXT: [[TMP4:%.*]] = tail call <vscale x 16 x i1> @llvm.aarch64.sve.convert.to.svbool.nxv8i1(<vscale x 8 x i1> [[TMP3]]) |
| 54 | +; CHECK-NEXT: ret <vscale x 16 x i1> [[TMP4]] |
| 55 | + %1 = tail call <vscale x 8 x i1> @llvm.aarch64.sve.convert.from.svbool.nxv8i1(<vscale x 16 x i1> %pg) |
| 56 | + %2 = tail call <vscale x 8 x i1> @llvm.aarch64.sve.convert.from.svbool.nxv8i1(<vscale x 16 x i1> %prev) |
| 57 | + %3 = tail call <vscale x 8 x i1> @llvm.aarch64.sve.pnext.nxv8i1(<vscale x 8 x i1> %1, <vscale x 8 x i1> %2) |
| 58 | + %4 = tail call <vscale x 16 x i1> @llvm.aarch64.sve.convert.to.svbool.nxv8i1(<vscale x 8 x i1> %3) |
| 59 | + %5 = tail call <vscale x 16 x i1> @llvm.aarch64.sve.convert.to.svbool.nxv8i1(<vscale x 8 x i1> splat (i1 true)) |
| 60 | + %6 = tail call <vscale x 16 x i1> @llvm.aarch64.sve.and.z.nxv16i1(<vscale x 16 x i1> splat (i1 true), <vscale x 16 x i1> %4, <vscale x 16 x i1> %5) |
| 61 | + ret <vscale x 16 x i1> %6 |
| 62 | +} |
| 63 | + |
| 64 | +define <vscale x 16 x i1> @test_sve_and_z_not_all_true_predicate(<vscale x 16 x i1> %pred, <vscale x 16 x i1> %a) { |
| 65 | +; CHECK-LABEL: @test_sve_and_z_not_all_true_predicate( |
| 66 | +; CHECK-NEXT: [[ALL_TRUE:%.*]] = tail call <vscale x 16 x i1> @llvm.aarch64.sve.convert.to.svbool.nxv8i1(<vscale x 8 x i1> splat (i1 true)) |
| 67 | +; CHECK-NEXT: [[RESULT:%.*]] = tail call <vscale x 16 x i1> @llvm.aarch64.sve.and.z.nxv16i1(<vscale x 16 x i1> [[PRED:%.*]], <vscale x 16 x i1> [[A:%.*]], <vscale x 16 x i1> [[ALL_TRUE]]) |
| 68 | +; CHECK-NEXT: ret <vscale x 16 x i1> [[RESULT]] |
| 69 | + %all_true = tail call <vscale x 16 x i1> @llvm.aarch64.sve.convert.to.svbool.nxv8i1(<vscale x 8 x i1> splat (i1 true)) |
| 70 | + %result = tail call <vscale x 16 x i1> @llvm.aarch64.sve.and.z.nxv16i1(<vscale x 16 x i1> %pred, <vscale x 16 x i1> %a, <vscale x 16 x i1> %all_true) |
| 71 | + ret <vscale x 16 x i1> %result |
| 72 | +} |
| 73 | + |
| 74 | +define <vscale x 16 x i1> @test_sve_and_z_no_all_true_operands(<vscale x 16 x i1> %a, <vscale x 16 x i1> %b) { |
| 75 | +; CHECK-LABEL: @test_sve_and_z_no_all_true_operands( |
| 76 | +; CHECK-NEXT: [[RESULT:%.*]] = tail call <vscale x 16 x i1> @llvm.aarch64.sve.and.z.nxv16i1(<vscale x 16 x i1> splat (i1 true), <vscale x 16 x i1> [[A:%.*]], <vscale x 16 x i1> [[B:%.*]]) |
| 77 | +; CHECK-NEXT: ret <vscale x 16 x i1> [[RESULT]] |
| 78 | + %result = tail call <vscale x 16 x i1> @llvm.aarch64.sve.and.z.nxv16i1(<vscale x 16 x i1> splat (i1 true), <vscale x 16 x i1> %a, <vscale x 16 x i1> %b) |
| 79 | + ret <vscale x 16 x i1> %result |
| 80 | +} |
0 commit comments