xref: /llvm-project/llvm/test/CodeGen/AArch64/sve-ptest-removal-sink.ll (revision a850dbcc5cf146b071a82812ea8cb29d4feb8709)
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc -mtriple=aarch64 -mattr=+sve < %s | FileCheck %s
3
4;
5; Ensure that the %ptrue from the preheader is sunk into the loop such that the ptest is removed.
6;
7
8define void @test_sink_ptrue_into_ptest(i32 %n) {
9; CHECK-LABEL: test_sink_ptrue_into_ptest:
10; CHECK:       // %bb.0: // %entry
11; CHECK-NEXT:    whilelt p0.s, wzr, w0
12; CHECK-NEXT:    b.pl .LBB0_3
13; CHECK-NEXT:  // %bb.1: // %for.body.preheader
14; CHECK-NEXT:    mov w8, wzr
15; CHECK-NEXT:    cntw x9
16; CHECK-NEXT:  .LBB0_2: // %for.body
17; CHECK-NEXT:    // =>This Inner Loop Header: Depth=1
18; CHECK-NEXT:    whilelt p0.s, w8, w0
19; CHECK-NEXT:    add w8, w8, w9
20; CHECK-NEXT:    b.mi .LBB0_2
21; CHECK-NEXT:  .LBB0_3: // %exit
22; CHECK-NEXT:    ret
23entry:
24  %vscale = tail call i32 @llvm.vscale.i32()
25  %step = shl nuw nsw i32 %vscale, 2
26  %ptrue.ph = tail call <vscale x 4 x i1> @llvm.aarch64.sve.ptrue.nxv4i1(i32 31)
27  %while.ph = tail call <vscale x 4 x i1> @llvm.aarch64.sve.whilelt.nxv4i1.i32(i32 0, i32 %n)
28  %ptest.ph = tail call i1 @llvm.aarch64.sve.ptest.first.nxv4i1(<vscale x 4 x i1> %ptrue.ph, <vscale x 4 x i1> %while.ph)
29  br i1 %ptest.ph, label %for.body, label %exit
30
31for.body:
32  %i = phi i32 [ 0, %entry ], [ %i.next, %for.body ]
33  %i.next = add i32 %i, %step
34  %while = call <vscale x 4 x i1> @llvm.aarch64.sve.whilelt.nxv4i1.i32(i32 %i, i32 %n)
35  %ptest = call i1 @llvm.aarch64.sve.ptest.first.nxv4i1(<vscale x 4 x i1> %ptrue.ph, <vscale x 4 x i1> %while)
36  br i1 %ptest, label %for.body, label %exit
37
38exit:
39  ret void
40}
41
42declare i32 @llvm.vscale.i32()
43declare <vscale x 4 x i1> @llvm.aarch64.sve.ptrue.nxv4i1(i32 immarg)
44declare <vscale x 4 x i1> @llvm.aarch64.sve.whilelt.nxv4i1.i32(i32, i32)
45declare i1 @llvm.aarch64.sve.ptest.first.nxv4i1(<vscale x 4 x i1>, <vscale x 4 x i1>)
46