<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - [SCEV] computeMaxBECountForLT() returns wrong result"
href="https://bugs.llvm.org/show_bug.cgi?id=42175">42175</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[SCEV] computeMaxBECountForLT() returns wrong result
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>zhaoshiz@quicinc.com
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>$ cat loop-small-runtime-upperbound.ll
target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
@global = dso_local local_unnamed_addr global i32 0, align 4
@global.1 = dso_local local_unnamed_addr global i8* null, align 4
define dso_local void @hoge(i8 %arg) {
entry:
%x = load i32, i32* @global, align 4
%0 = icmp ult i32 %x, 17
br i1 %0, label %loop, label %exit
loop:
%iv = phi i32 [ %x, %entry ], [ %iv.next, %loop ]
%iv.next = add nuw i32 %iv, 8
%1 = load i8*, i8** @global.1, align 4
%2 = getelementptr inbounds i8, i8* %1, i32 1
store i8* %2, i8** @global.1, align 4
store i8 %arg, i8* %1, align 1
%3 = icmp ult i32 %iv.next, 17
br i1 %3, label %loop, label %exit
exit: ; preds = %bb12, %bb
ret void
}
$ opt loop-small-runtime-upperbound.ll -analyze -scalar-evolution
Printing analysis 'Scalar Evolution Analysis' for function 'hoge':
Classifying expressions for: @hoge
%x = load i32, i32* @global, align 4
--> %x U: full-set S: full-set
%iv = phi i32 [ %x, %entry ], [ %iv.next, %loop ]
--> {%x,+,8}<nuw><%loop> U: full-set S: full-set Exits: ((8 *
((16 + (-1 * %x)) /u 8))<nuw> + %x) LoopDispositions: { %loop:
Computable }
%iv.next = add nuw i32 %iv, 8
--> {(8 + %x),+,8}<nuw><%loop> U: full-set S: full-set Exits:
(8 + (8 * ((16 + (-1 * %x)) /u 8))<nuw> + %x) LoopDispositions: {
%loop: Computable }
%1 = load i8*, i8** @global.1, align 4
--> %1 U: full-set S: full-set Exits: <<Unknown>>
LoopDispositions: { %loop: Variant }
%2 = getelementptr inbounds i8, i8* %1, i32 1
--> (1 + %1)<nsw> U: full-set S: full-set Exits: <<Unknown>>
LoopDispositions: { %loop: Variant }
Determining loop execution counts for: @hoge
Loop %loop: backedge-taken count is ((16 + (-1 * %x)) /u 8)
Loop %loop: max backedge-taken count is 3
Loop %loop: Predicated backedge-taken count is ((16 + (-1 * %x)) /u 8)
Predicates:
Loop %loop: Trip multiple is 1
The loop runs a max of 3 iters, but SCEV computes max BE-taken count as 3.
The same issue is also found in
test/Analysis/ScalarEvolution/2008-11-18-Stride2.ll, where max BE-taken count
is 333 instead of 334.
The problem is in computeMaxBECountForLT(), when Start is a (C + %x), where C
is a constant and %x is an unknown.
getUnsignedRangeMin(Start) returns full-set because of %x. But loop entry is
guarded by:
%0 = icmp ult i32 %x, 17
so x is known in [0, 17), thus MinStart shall be C rather than 0.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>