<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - LICM incorrectly preserves dereferenceability attributes" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24059&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=oIyFB0ckqDG5nMjfYTYz8gotIsUf7eiheyTZnuKYlMk&s=FpnNAJqcZSDfjoj3PqMLbQoDuGkPiC1FTYA4V6nzAhc&e=">24059</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>LICM incorrectly preserves dereferenceability attributes
</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>sanjoy@playingwithpointers.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>While this bug is easiest to demonstrate via LICM, it is a more
general issue. Currently LLVM does not strip the !dereferenceable
(and other associated) attribute when hoisting instructions over
control flow. This is problematic when the dereferencability of a
value is control dependent on the check LICM hoists the instruction
over.
For instance, running the following IR through -basicaa -licm moves
the load of %v_ptr to the loop's preheader while keeping the
!dereferencability intact, but it is possible %v_ptr is
dereferencability only if %cmp1 is true.
```
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
define void @test1(i32* noalias nocapture %a, i32* noalias nocapture readonly
%b, i32** nocapture readonly nonnull dereferenceable(16) %c, i32 %n) #0 {
entry:
%cmp11 = icmp sgt i32 %n, 0
br i1 %cmp11, label %for.body, label %for.end
for.body: ; preds = %entry, %for.inc
%indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
%arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
%v0 = load i32, i32* %arrayidx, align 4
%cmp1 = icmp sgt i32 %v0, 0
br i1 %cmp1, label %if.then, label %for.inc
if.then: ; preds = %for.body
%v_ptr = load i32*, i32** %c, align 4, !dereferenceable !0
%v1 = load i32, i32* %v_ptr, align 4
%arrayidx3 = getelementptr inbounds i32, i32* %b, i64 %indvars.iv
%v2 = load i32, i32* %arrayidx3, align 4
%mul = mul nsw i32 %v2, %v1
store i32 %mul, i32* %arrayidx, align 4
br label %for.inc
for.inc: ; preds = %for.body, %if.then
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
%lftr.wideiv = trunc i64 %indvars.iv.next to i32
%exitcond = icmp eq i32 %lftr.wideiv, %n
br i1 %exitcond, label %for.end, label %for.body
for.end: ; preds = %for.inc, %entry
ret void
}
!0 = !{i64 4}
!1 = !{i64 2}
!2 = !{}
```</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>