File: predicated-symbolic-max-backedge-taken-count.ll

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.6-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,304 kB
  • sloc: cpp: 7,438,677; ansic: 1,393,822; asm: 1,012,926; python: 241,650; f90: 86,635; objc: 75,479; lisp: 42,144; pascal: 17,286; sh: 10,027; ml: 5,082; perl: 4,730; awk: 3,523; makefile: 3,349; javascript: 2,251; xml: 892; fortran: 672
file content (105 lines) | stat: -rw-r--r-- 4,331 bytes parent folder | download | duplicates (6)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 5
; RUN: opt -passes='print<scalar-evolution>' -scalar-evolution-classify-expressions=0 -disable-output %s 2>&1 | FileCheck %s

; %i and %i + 1 can overflow.
define void @test1(i64 %x, ptr %a, ptr %b) {
; CHECK-LABEL: 'test1'
; CHECK-NEXT:  Determining loop execution counts for: @test1
; CHECK-NEXT:  Loop %header: <multiple exits> Unpredictable backedge-taken count.
; CHECK-NEXT:    exit count for header: ***COULDNOTCOMPUTE***
; CHECK-NEXT:    exit count for latch: ***COULDNOTCOMPUTE***
; CHECK-NEXT:    predicated exit count for latch: (-1 + (1 umax %x))
; CHECK-NEXT:     Predicates:
; CHECK-NEXT:      {1,+,1}<%header> Added Flags: <nusw>
; CHECK-EMPTY:
; CHECK-NEXT:  Loop %header: Unpredictable constant max backedge-taken count.
; CHECK-NEXT:  Loop %header: Unpredictable symbolic max backedge-taken count.
; CHECK-NEXT:    symbolic max exit count for header: ***COULDNOTCOMPUTE***
; CHECK-NEXT:    symbolic max exit count for latch: ***COULDNOTCOMPUTE***
; CHECK-NEXT:    predicated symbolic max exit count for latch: (-1 + (1 umax %x))
; CHECK-NEXT:     Predicates:
; CHECK-NEXT:      {1,+,1}<%header> Added Flags: <nusw>
; CHECK-EMPTY:
; CHECK-NEXT:  Loop %header: Predicated constant max backedge-taken count is i64 -2
; CHECK-NEXT:   Predicates:
; CHECK-NEXT:      {1,+,1}<%header> Added Flags: <nusw>
; CHECK-NEXT:  Loop %header: Predicated symbolic max backedge-taken count is (-1 + (1 umax %x))
; CHECK-NEXT:   Predicates:
; CHECK-NEXT:      {1,+,1}<%header> Added Flags: <nusw>
;
entry:
  br label %header

header:
  %conv11 = phi i64 [ 0, %entry ], [ %conv, %latch ]
  %i.010 = phi i32 [ 0, %entry ], [ %add, %latch ]
  %add = add i32 %i.010, 1
  %idxprom = zext i32 %add to i64
  %arrayidx = getelementptr inbounds i32, ptr %a, i64 %idxprom
  %ld = load i32, ptr %arrayidx, align 4
  %uncountable.c = icmp eq i32 %ld, 10
  br i1 %uncountable.c, label %exit, label %latch

latch:
  %add2 = add nsw i32 %ld, 1
  %arrayidx4 = getelementptr inbounds i32, ptr %b, i64 %conv11
  store i32 %add2, ptr %arrayidx4, align 4
  %conv = zext i32 %add to i64
  %cmp = icmp ult i64 %conv, %x
  br i1 %cmp, label %header, label %exit

exit:
  ret void
}

; %i can overflow.
;
; We need to check that i doesn't wrap, but we don't need a run-time alias
; check. We also need an extra no-wrap check to get the backedge taken count.
define void @test2(i64 %x, ptr %a) {
; CHECK-LABEL: 'test2'
; CHECK-NEXT:  Determining loop execution counts for: @test2
; CHECK-NEXT:  Loop %header: <multiple exits> Unpredictable backedge-taken count.
; CHECK-NEXT:    exit count for header: ***COULDNOTCOMPUTE***
; CHECK-NEXT:    exit count for latch: ***COULDNOTCOMPUTE***
; CHECK-NEXT:    predicated exit count for latch: (-1 + (1 umax %x))
; CHECK-NEXT:     Predicates:
; CHECK-NEXT:      {1,+,1}<%header> Added Flags: <nusw>
; CHECK-EMPTY:
; CHECK-NEXT:  Loop %header: Unpredictable constant max backedge-taken count.
; CHECK-NEXT:  Loop %header: Unpredictable symbolic max backedge-taken count.
; CHECK-NEXT:    symbolic max exit count for header: ***COULDNOTCOMPUTE***
; CHECK-NEXT:    symbolic max exit count for latch: ***COULDNOTCOMPUTE***
; CHECK-NEXT:    predicated symbolic max exit count for latch: (-1 + (1 umax %x))
; CHECK-NEXT:     Predicates:
; CHECK-NEXT:      {1,+,1}<%header> Added Flags: <nusw>
; CHECK-EMPTY:
; CHECK-NEXT:  Loop %header: Predicated constant max backedge-taken count is i64 -2
; CHECK-NEXT:   Predicates:
; CHECK-NEXT:      {1,+,1}<%header> Added Flags: <nusw>
; CHECK-NEXT:  Loop %header: Predicated symbolic max backedge-taken count is (-1 + (1 umax %x))
; CHECK-NEXT:   Predicates:
; CHECK-NEXT:      {1,+,1}<%header> Added Flags: <nusw>
;
entry:
  br label %header

header:
  %conv11 = phi i64 [ 0, %entry ], [ %conv, %latch ]
  %i.010 = phi i32  [ 0, %entry ], [ %inc, %latch ]
  %arrayidx = getelementptr inbounds i32, ptr %a, i64 %conv11
  %ld = load i32, ptr %arrayidx, align 4
  %uncountable.c = icmp eq i32 %ld, 10
  br i1 %uncountable.c, label %exit, label %latch

latch:
  %add = add nsw i32 %ld, 1
  store i32 %add, ptr %arrayidx, align 4
  %inc = add i32 %i.010, 1
  %conv = zext i32 %inc to i64
  %cmp = icmp ult i64 %conv, %x
  br i1 %cmp, label %header, label %exit

exit:
  ret void
}