File: pr48225.ll

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (98 lines) | stat: -rw-r--r-- 4,318 bytes parent folder | download | duplicates (3)
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
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
; RUN: opt < %s -disable-output "-passes=print<scalar-evolution>" 2>&1 | FileCheck %s

; Tests demonstrate the bug reported as PR48225 by Congzhe Cao.

; When %boolcond = false and %cond = 0:
; - %cond.false.on.first.iter is false on 1st iteration;
; - %cond.false.on.second.iter is false on 2nd iteration;
; - Therefore, their AND is false on first two iterations, and the backedge is taken twice.
;  'max backedge-taken count is 1' is a bug caused by wrong treatment of AND
;  condition in the computation logic. It should be 2.
define void @test_and(i1 %boolcond) {
; CHECK-LABEL: 'test_and'
; CHECK-NEXT:  Classifying expressions for: @test_and
; CHECK-NEXT:    %conv = zext i1 %boolcond to i32
; CHECK-NEXT:    --> (zext i1 %boolcond to i32) U: [0,2) S: [0,2)
; CHECK-NEXT:    %iv = phi i32 [ 0, %entry ], [ %inc, %backedge ]
; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%loop> U: [0,3) S: [0,3) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
; CHECK-NEXT:    %or.cond = and i1 %cond.false.on.first.iter, %cond.false.on.second.iter
; CHECK-NEXT:    --> %or.cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
; CHECK-NEXT:    %inc = add nuw nsw i32 %iv, 1
; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%loop> U: [1,4) S: [1,4) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
; CHECK-NEXT:  Determining loop execution counts for: @test_and
; CHECK-NEXT:  Loop %loop: <multiple exits> Unpredictable backedge-taken count.
; CHECK-NEXT:    exit count for loop: 2
; CHECK-NEXT:    exit count for backedge: ***COULDNOTCOMPUTE***
; CHECK-NEXT:  Loop %loop: max backedge-taken count is 2
; CHECK-NEXT:  Loop %loop: Unpredictable predicated backedge-taken count.
;
entry:
  %conv = zext i1 %boolcond to i32
  br label %loop

loop:
  %iv = phi i32 [ 0, %entry ], [ %inc, %backedge ]
  %cmp = icmp ult i32 %iv, 2
  br i1 %cmp, label %backedge, label %for.end

backedge:
  %cond.false.on.first.iter = icmp ne i32 %iv, 0
  %cond.false.on.second.iter = icmp eq i32 %iv, %conv
  %or.cond = and i1 %cond.false.on.first.iter, %cond.false.on.second.iter
  %inc = add nuw nsw i32 %iv, 1
  br i1 %or.cond, label %exit, label %loop

exit:
  unreachable

for.end:
  ret void
}

; When %boolcond = false and %cond = 0:
; - %cond.true.on.first.iter is true on 1st iteration;
; - %cond.true.on.second.iter is true on 2nd iteration;
; - Therefore, their OR is true on first two iterations, and the backedge is taken twice.
;  'max backedge-taken count is 1' is a bug caused by wrong treatment of OR
;  condition in the computation logic. It should be 2.
define void @test_or(i1 %boolcond) {
; CHECK-LABEL: 'test_or'
; CHECK-NEXT:  Classifying expressions for: @test_or
; CHECK-NEXT:    %conv = zext i1 %boolcond to i32
; CHECK-NEXT:    --> (zext i1 %boolcond to i32) U: [0,2) S: [0,2)
; CHECK-NEXT:    %iv = phi i32 [ 0, %entry ], [ %inc, %backedge ]
; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%loop> U: [0,3) S: [0,3) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
; CHECK-NEXT:    %or.cond = or i1 %cond.true.on.first.iter, %cond.true.on.second.iter
; CHECK-NEXT:    --> %or.cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
; CHECK-NEXT:    %inc = add nuw nsw i32 %iv, 1
; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%loop> U: [1,4) S: [1,4) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
; CHECK-NEXT:  Determining loop execution counts for: @test_or
; CHECK-NEXT:  Loop %loop: <multiple exits> Unpredictable backedge-taken count.
; CHECK-NEXT:    exit count for loop: 2
; CHECK-NEXT:    exit count for backedge: ***COULDNOTCOMPUTE***
; CHECK-NEXT:  Loop %loop: max backedge-taken count is 2
; CHECK-NEXT:  Loop %loop: Unpredictable predicated backedge-taken count.
;
entry:
  %conv = zext i1 %boolcond to i32
  br label %loop

loop:
  %iv = phi i32 [ 0, %entry ], [ %inc, %backedge ]
  %cmp = icmp ult i32 %iv, 2
  br i1 %cmp, label %backedge, label %for.end

backedge:
  %cond.true.on.first.iter = icmp eq i32 %iv, 0
  %cond.true.on.second.iter = icmp ne i32 %iv, %conv
  %or.cond = or i1 %cond.true.on.first.iter, %cond.true.on.second.iter
  %inc = add nuw nsw i32 %iv, 1
  br i1 %or.cond, label %loop, label %exit

exit:
  unreachable

for.end:
  ret void
}