<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 - Incorrect optimization of gep without inbounds + load -> icmp eq"
href="https://bugs.llvm.org/show_bug.cgi?id=45210">45210</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Incorrect optimization of gep without inbounds + load -> icmp eq
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Keywords</th>
<td>miscompilation
</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>nunoplopes@sapo.pt
</td>
</tr>
<tr>
<th>CC</th>
<td>juneyoung.lee@sf.snu.ac.kr, lebedev.ri@gmail.com, llvm-bugs@lists.llvm.org, regehr@cs.utah.edu, spatel+llvm@rotateright.com
</td>
</tr></table>
<p>
<div>
<pre>The following unit test in "Transforms/InstCombine/load-cmp.ll" exposes an
incorrect optimization:
define i1 @test1_noinbounds(i32 %X) {
; CHECK-LABEL: @test1_noinbounds(
; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[X:%.*]], 9
; CHECK-NEXT: ret i1 [[R]]
;
%P = getelementptr [10 x i16], [10 x i16]* @G16, i32 0, i32 %X
%Q = load i16, i16* %P
%R = icmp eq i16 %Q, 0
ret i1 %R
}
Output of Alive2. TL;DR: the optimization is only correct with gep inbounds,
otherwise the transformation to "icmp eq" misses the overflow case.
@G16 = constant 20 bytes, align 16
define i1 @test1_noinbounds(i32 %X) {
#init:
store [10 x i16] { 35, 82, 69, 81, 85, 73, 82, 69, 68, 0 }, * @G16, align 16
br label %0
%0:
%P = gep * @G16, 20 x i32 0, 2 x i32 %X
%Q = load i16, * %P, align 2
%R = icmp eq i16 %Q, 0
ret i1 %R
}
=>
@G16 = constant 20 bytes, align 16
define i1 @test1_noinbounds(i32 %X) {
#init:
store [10 x i16] { 35, 82, 69, 81, 85, 73, 82, 69, 68, 0 }, * @G16, align 16
br label %0
%0:
%R = icmp eq i32 %X, 9
ret i1 %R
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
i32 %X = #x80000009 (2147483657, -2147483639)
Source:
* %P = pointer(non-local, block_id=1, offset=18)
i16 %Q = #x0000 (0)
i1 %R = #x1 (1)
Target:
i1 %R = #x0 (0)
Source value: #x1 (1)
Target value: #x0 (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>