<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 - An IR program prints an incorrect result after it is compiled with -O0"
href="https://bugs.llvm.org/show_bug.cgi?id=40657">40657</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>An IR program prints an incorrect result after it is compiled with -O0
</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>Backend: X86
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>juneyoung.lee@sf.snu.ac.kr
</td>
</tr>
<tr>
<th>CC</th>
<td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, spatel+llvm@rotateright.com
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=21449" name="attach_21449" title="bug 1">attachment 21449</a> <a href="attachment.cgi?id=21449&action=edit" title="bug 1">[details]</a></span>
<a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED FIXED - Need to add product version numbers"
href="show_bug.cgi?id=1">bug 1</a>
Consider this program:
```
define i32 @main() {
entry:
%call = tail call i64 @f(i8 249, i8 101)
%call1 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x
i8], [4 x i8]* @.str, i64 0, i64 0), i64 %call)
ret i32 0
}
declare i32 @printf(i8* nocapture readonly, ...)
@.str = private unnamed_addr constant [4 x i8] c"%lu\00", align 1
define i64 @f(i8 %var2, i8 %var9) {
%var6 = trunc i8 %var9 to i1
%var7 = trunc i8 175 to i1
%var3 = sub nsw i1 %var6, %var7
%var4 = icmp eq i64 1114591064, 1114591064
%var1 = udiv i1 %var3, %var4
%var0 = trunc i8 %var2 to i1
%res = sub nsw nuw i1 %var0, %var1
%res.cast = zext i1 %res to i64
ret i64 %res.cast
}
```
This program should print 1, but it prints 0 after being compiled with -O0.
$ clang --version
clang version 9.0.0 (<a href="https://github.com/llvm-mirror/clang.git">https://github.com/llvm-mirror/clang.git</a>
23cffd780f5647d02c6c12491f9b2c928757c798)
(<a href="https://github.com/llvm-mirror/llvm.git">https://github.com/llvm-mirror/llvm.git</a>
903a5691e0214c29a4da3796f9a4d598ad3d18f3)
Target: x86_64-unknown-linux-gnu
$ clang -O0 -o a.out 2332174.ll
$ ./a.out
0
I attach a few more programs which should print 1 but they print 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>