<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 - InstCombine incorrectly folds 'gep(bitcast ptr), idx' into 'gep ptr, idx'"
href="https://bugs.llvm.org/show_bug.cgi?id=44321">44321</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>InstCombine incorrectly folds 'gep(bitcast ptr), idx' into 'gep ptr, idx'
</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>All
</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>Transformation Utilities
</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>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>```
$ cat gep-vector.ll
define i32* @bitcast_vec_to_array_gep(<7 x i32>* %x, i64 %y, i64 %z) {
%arr_ptr = bitcast <7 x i32>* %x to [7 x i32]*
%gep = getelementptr [7 x i32], [7 x i32]* %arr_ptr, i64 %y, i64 %z
ret i32* %gep
}
$ opt -instcombine gep-vector.ll -S -o -
define i32* @bitcast_vec_to_array_gep(<7 x i32>* %x, i64 %y, i64 %z) {
%gep = getelementptr <7 x i32>, <7 x i32>* %x, i64 %y, i64 %z
ret i32* %gep
}
```
This is incorrect because DataLayout::getTypeAllocSize(< 7 x i32 >) and
getTypeAllocSize([ 7 x i32 ]) may differ.
This can be double-checked by emitting assembly code before/after optimization.
<a href="https://godbolt.org/z/xB-p5u">https://godbolt.org/z/xB-p5u</a>
Before optimization, rax = rdi + 28 * rsi + 4 * rdx
After instcombine, rax = rdi + 32 * rsi + 4 * rdx.</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>