<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 - [InstCombiner] WRONG code"
href="https://bugs.llvm.org/show_bug.cgi?id=49689">49689</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[InstCombiner] WRONG code
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</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>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Scalar Optimizations
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>paulsson@linux.vnet.ibm.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=24683" name="attach_24683" title="reduced testcase">attachment 24683</a> <a href="attachment.cgi?id=24683&action=edit" title="reduced testcase">[details]</a></span>
reduced testcase
This program:
struct a {
int b;
} d;
int c = 3, e;
char f;
void g(int j);
struct a h() {
return d;
}
void i() { g(0); }
void g(int j) {
e = 27;
for (; e != 3; e = e - 4) {
int *k = &c;
{
long l;
if (*k) // == 3
*k |= j; // j == 0 => k = 3
else
break;
f = 0;
for (; f;)
h();
}
} // should exit when e == 3
}
int main() {
i();
printf("%d\n", e);
}
should print '3', which it does with
clang -O3 -march=arch13 wrong0.i -o a.out -w; ./a.out
However, it prints '23' with
clang -O3 -march=arch13 wrong0.i -o a.out -w -fno-inline -mllvm
-bonus-inst-threshold=2
It looks like InstCombiner is incorrectly causing the loop to exit after first
iteration:
*** IR Dump After SimplifyCFGPass ***
; Function Attrs: nofree noinline nounwind
define dso_local void @g(i32 signext %j) local_unnamed_addr #3 {
entry:
%tmp = alloca %struct.a, align 4
store i32 27, i32* @e, align 4, !tbaa !2
%.old = load i32, i32* @c, align 4, !tbaa !2
%tobool.not.old = icmp eq i32 %.old, 0
br i1 %tobool.not.old, label %for.end7, label %if.then
if.then: ; preds = %if.then, %entry
%or = or i32 %1, %j
store i32 %or, i32* @c, align 4, !tbaa !2
store i8 0, i8* @f, align 2, !tbaa !6
%0 = load i32, i32* @e, align 4, !tbaa !2
%sub = add nsw i32 %0, -4
store i32 %sub, i32* @e, align 4, !tbaa !2
%cmp.not = icmp eq i32 %sub, 3
%1 = load i32, i32* @c, align 4
%tobool.not = icmp eq i32 %1, 0
%or.cond = or i1 %cmp.not, %tobool.not
br i1 %or.cond, label %for.end7, label %if.then, !llvm.loop !7
for.end7: ; preds = %entry, %if.then
ret void
}
*** IR Dump After InstCombinePass ***
; Function Attrs: nofree noinline nounwind
define dso_local void @g(i32 signext %j) local_unnamed_addr #3 {
entry:
store i32 27, i32* @e, align 4, !tbaa !2
%.old = load i32, i32* @c, align 4, !tbaa !2
%tobool.not.old = icmp eq i32 %.old, 0
br i1 %tobool.not.old, label %for.end7, label %if.then
if.then: ; preds = %if.then, %entry
store i8 0, i8* @f, align 2, !tbaa !6
%0 = load i32, i32* @e, align 4, !tbaa !2
%sub = add nsw i32 %0, -4
store i32 %sub, i32* @e, align 4, !tbaa !2
br i1 true, label %for.end7, label %if.then, !llvm.loop !7
for.end7: ; preds = %entry, %if.then
ret void
}</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>