File: full-unroll-trip-count-upper-bound.ll

package info (click to toggle)
llvm-toolchain-16 1%3A16.0.6-15~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,634,792 kB
  • sloc: cpp: 6,179,261; ansic: 1,216,205; asm: 741,319; python: 196,614; objc: 75,325; f90: 49,640; lisp: 32,396; pascal: 12,286; sh: 9,394; perl: 7,442; ml: 5,494; awk: 3,523; makefile: 2,723; javascript: 1,206; xml: 886; fortran: 581; cs: 573
file content (44 lines) | stat: -rw-r--r-- 1,332 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
; RUN: opt -passes=loop-unroll -S -mtriple aarch64 -mcpu=cortex-a57 %s | FileCheck %s -check-prefix=UNROLL
; RUN: opt -passes=loop-unroll -unroll-max-upperbound=0 -S -mtriple aarch64 -mcpu=cortex-a57 %s | FileCheck %s -check-prefix=NOUNROLL

; This IR comes from this C code:
;
;   for (int i = 0; i < 4; i++) {
;     if (src[i] == 1) {
;       *dst = i;
;       break;
;     }
;   }
;
; This test is meant to check that this loop is unrolled into four iterations.
; Note that the load on the last iteration is dead and thus doesn't appear in
; the output.

; UNROLL-LABEL: @test
; UNROLL: load i32, ptr
; UNROLL: load i32, ptr
; UNROLL: load i32, ptr
; UNROLL-NOT: load i32, ptr
; NOUNROLL-LABEL: @test
; NOUNROLL: load i32, ptr
; NOUNROLL-NOT: load i32, ptr

define void @test(ptr %dst, ptr %src) {
entry:
  br label %for.body

for.body:                                         ; preds = %entry, %for.body
  %i = phi i32 [ 0, %entry ], [ %inc, %for.body ]
  %0 = sext i32 %i to i64
  %1 = getelementptr inbounds i32, ptr %src, i64 %0
  %2 = load i32, ptr %1
  %inc = add nsw i32 %i, 1
  %cmp1 = icmp slt i32 %inc, 4
  %cmp3 = icmp eq i32 %2, 1
  %or.cond = and i1 %cmp3, %cmp1
  br i1 %or.cond, label %for.body, label %exit

exit:                                          ; preds = %for.body
  store i32 %i, ptr %dst
  ret void
}