xref: /aosp_15_r20/external/llvm/test/CodeGen/AMDGPU/tti-unroll-prefs.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: opt -loop-unroll -S -mtriple=amdgcn-- -mcpu=SI %s | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Worker; This IR comes from this OpenCL C code:
4*9880d681SAndroid Build Coastguard Worker;
5*9880d681SAndroid Build Coastguard Worker; if (b + 4 > a) {
6*9880d681SAndroid Build Coastguard Worker;   for (int i = 0; i < 4; i++, b++) {
7*9880d681SAndroid Build Coastguard Worker;     if (b + 1 <= a)
8*9880d681SAndroid Build Coastguard Worker;       *(dst + c + b) = 0;
9*9880d681SAndroid Build Coastguard Worker;     else
10*9880d681SAndroid Build Coastguard Worker;       break;
11*9880d681SAndroid Build Coastguard Worker;   }
12*9880d681SAndroid Build Coastguard Worker; }
13*9880d681SAndroid Build Coastguard Worker;
14*9880d681SAndroid Build Coastguard Worker; This test is meant to check that this loop isn't unrolled into more than
15*9880d681SAndroid Build Coastguard Worker; four iterations.  The loop unrolling preferences we currently use cause this
16*9880d681SAndroid Build Coastguard Worker; loop to not be unrolled at all, but that may change in the future.
17*9880d681SAndroid Build Coastguard Worker
18*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test
19*9880d681SAndroid Build Coastguard Worker; CHECK: store i8 0, i8 addrspace(1)*
20*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: store i8 0, i8 addrspace(1)*
21*9880d681SAndroid Build Coastguard Worker; CHECK: ret void
22*9880d681SAndroid Build Coastguard Workerdefine void @test(i8 addrspace(1)* nocapture %dst, i32 %a, i32 %b, i32 %c) {
23*9880d681SAndroid Build Coastguard Workerentry:
24*9880d681SAndroid Build Coastguard Worker  %add = add nsw i32 %b, 4
25*9880d681SAndroid Build Coastguard Worker  %cmp = icmp sgt i32 %add, %a
26*9880d681SAndroid Build Coastguard Worker  br i1 %cmp, label %for.cond.preheader, label %if.end7
27*9880d681SAndroid Build Coastguard Worker
28*9880d681SAndroid Build Coastguard Workerfor.cond.preheader:                               ; preds = %entry
29*9880d681SAndroid Build Coastguard Worker  %cmp313 = icmp slt i32 %b, %a
30*9880d681SAndroid Build Coastguard Worker  br i1 %cmp313, label %if.then4.lr.ph, label %if.end7.loopexit
31*9880d681SAndroid Build Coastguard Worker
32*9880d681SAndroid Build Coastguard Workerif.then4.lr.ph:                                   ; preds = %for.cond.preheader
33*9880d681SAndroid Build Coastguard Worker  %0 = sext i32 %c to i64
34*9880d681SAndroid Build Coastguard Worker  br label %if.then4
35*9880d681SAndroid Build Coastguard Worker
36*9880d681SAndroid Build Coastguard Workerif.then4:                                         ; preds = %if.then4.lr.ph, %if.then4
37*9880d681SAndroid Build Coastguard Worker  %i.015 = phi i32 [ 0, %if.then4.lr.ph ], [ %inc, %if.then4 ]
38*9880d681SAndroid Build Coastguard Worker  %b.addr.014 = phi i32 [ %b, %if.then4.lr.ph ], [ %add2, %if.then4 ]
39*9880d681SAndroid Build Coastguard Worker  %add2 = add nsw i32 %b.addr.014, 1
40*9880d681SAndroid Build Coastguard Worker  %1 = sext i32 %b.addr.014 to i64
41*9880d681SAndroid Build Coastguard Worker  %add.ptr.sum = add nsw i64 %1, %0
42*9880d681SAndroid Build Coastguard Worker  %add.ptr5 = getelementptr inbounds i8, i8 addrspace(1)* %dst, i64 %add.ptr.sum
43*9880d681SAndroid Build Coastguard Worker  store i8 0, i8 addrspace(1)* %add.ptr5, align 1
44*9880d681SAndroid Build Coastguard Worker  %inc = add nsw i32 %i.015, 1
45*9880d681SAndroid Build Coastguard Worker  %cmp1 = icmp slt i32 %inc, 4
46*9880d681SAndroid Build Coastguard Worker  %cmp3 = icmp slt i32 %add2, %a
47*9880d681SAndroid Build Coastguard Worker  %or.cond = and i1 %cmp3, %cmp1
48*9880d681SAndroid Build Coastguard Worker  br i1 %or.cond, label %if.then4, label %for.cond.if.end7.loopexit_crit_edge
49*9880d681SAndroid Build Coastguard Worker
50*9880d681SAndroid Build Coastguard Workerfor.cond.if.end7.loopexit_crit_edge:              ; preds = %if.then4
51*9880d681SAndroid Build Coastguard Worker  br label %if.end7.loopexit
52*9880d681SAndroid Build Coastguard Worker
53*9880d681SAndroid Build Coastguard Workerif.end7.loopexit:                                 ; preds = %for.cond.if.end7.loopexit_crit_edge, %for.cond.preheader
54*9880d681SAndroid Build Coastguard Worker  br label %if.end7
55*9880d681SAndroid Build Coastguard Worker
56*9880d681SAndroid Build Coastguard Workerif.end7:                                          ; preds = %if.end7.loopexit, %entry
57*9880d681SAndroid Build Coastguard Worker  ret void
58*9880d681SAndroid Build Coastguard Worker}
59