<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 - Folding 'gep p, (q - p)' to q should check it is never used for loads & stores"
href="https://bugs.llvm.org/show_bug.cgi?id=44403">44403</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Folding 'gep p, (q - p)' to q should check it is never used for loads & stores
</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>Scalar Optimizations
</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.ll
define i8* @f(i8* %p, i8* %q) {
%i = ptrtoint i8* %p to i64
%j = ptrtoint i8* %q to i64
%diff = sub i64 %j, %i
%p2 = getelementptr i8, i8* %p, i64 %diff
ret i8* %p2
}
$ opt -instcombine gep.ll -S -o -
; ModuleID = 'gep.ll'
source_filename = "gep.ll"
define i8* @f(i8* %p, i8* %q) {
ret i8* %q
}
```
According to the GEP document:
<a href="https://llvm.org/docs/GetElementPtr.html#can-i-compute-the-distance-between-two-objects-and-add-that-value-to-one-address-to-compute-the-other-address">https://llvm.org/docs/GetElementPtr.html#can-i-compute-the-distance-between-two-objects-and-add-that-value-to-one-address-to-compute-the-other-address</a>
Replacing ‘gep p, (q - p)’ with q is invalid when it is used by memory access
operations.
InstCombine and InstSimplify both do this.
`llc gep.ll -o -` emits an optimized assembly, so SelDag or MIR seem to already
have optimizations for these this pattern if my understanding is correct?</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>