<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - Wrong unsigned rem operation when compared to zero"
href="https://llvm.org/bugs/show_bug.cgi?id=27707">27707</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Wrong unsigned rem operation when compared to zero
</td>
</tr>
<tr>
<th>Product</th>
<td>Polly
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Optimizer
</td>
</tr>
<tr>
<th>Assignee</th>
<td>polly-dev@googlegroups.com
</td>
</tr>
<tr>
<th>Reporter</th>
<td>chrisj@codeaurora.org
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=16356" name="attach_16356" title="test">attachment 16356</a> <a href="attachment.cgi?id=16356&action=edit" title="test">[details]</a></span>
test
Attached test is a simple pointer iteration.
%struct.A = type { i32, i64, i8 }
; Function Attrs: norecurse nounwind
define void @foo1(%struct.A* %a1, %struct.A* readnone %b1) #0 {
entry:
br label %entry.split
entry.split: ; preds = %entry
%cmp4 = icmp eq %struct.A* %a1, %b1
br i1 %cmp4, label %for.cond.cleanup, label %for.body.preheader
for.body.preheader: ; preds = %entry.split
br label %for.body
for.cond.cleanup.loopexit: ; preds = %for.body
br label %for.cond.cleanup
for.cond.cleanup: ; preds =
%for.cond.cleanup.loopexit, %entry.split
ret void
for.body: ; preds =
%for.body.preheader, %for.body
%start.05 = phi %struct.A* [ %incdec.ptr, %for.body ], [ %a1,
%for.body.preheader ]
%a = getelementptr inbounds %struct.A, %struct.A* %start.05, i64 0, i32 0
%0 = load i32, i32* %a, align 8
%add = add nsw i32 %0, 1
store i32 %add, i32* %a, align 8
%incdec.ptr = getelementptr inbounds %struct.A, %struct.A* %start.05, i64 1
%cmp = icmp eq %struct.A* %incdec.ptr, %b1
br i1 %cmp, label %for.cond.cleanup.loopexit, label %for.body
}
Now consider the polly condition generated in the schedule,
opt -polly-process-unprofitable -polly-code-generator=isl -polly-scops -
analyze test.ll -S
:: isl ast :: foo1 :: entry.split => for.cond.cleanup
if (1 && 0 == (a1 >= b1 + 1 || a1 >= b1 + 24 * floord(a1 - b1, 24) + 1 || b1 >=
a1 + 9223372036854775848))
if ((a1 - b1) % 24 == 0)
for (int c0 = 0; c0 < (-a1 + b1) / 24; c0 += 1)
Stmt_for_body(c0);
else
{ /* original code */ }
In polly.cond we generate a urem for the (a1 - b1) % 24,
opt -polly-process-unprofitable -polly-code-generator=isl -polly-scops
-polly-codegen test.ll -S
polly.cond: ; preds = %polly.start
%23 = ptrtoint %struct.A* %a1 to i64
%24 = ptrtoint %struct.A* %b1 to i64
%25 = sub nsw i64 %23, %24
%pexp.zdiv_r = urem i64 %25, 24 <==========
%26 = icmp eq i64 %pexp.zdiv_r, 0
br i1 %26, label %polly.then, label %polly.else
In case of when (a1 - b1) is negative, an unsigned remainder operation can give
unexpected results. For example if (a1 - b1) = -48 (0xFFFFFFFFFFFFFFD0), the
modulo with 24 would be 16.
In such cases we need to generate srem.</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>