<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 - partial loop-unswitch infers wrong values for conditions with multiple invariants"
href="https://bugs.llvm.org/show_bug.cgi?id=39568">39568</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>partial loop-unswitch infers wrong values for conditions with multiple invariants
</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>Loop Optimizer
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>fedor.v.sergeev@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>] cat partial-bad-unswitch.ll
define i32 @mainReduced(i8 %pre28, i8 %pr) {
entry:
%entry_check = icmp slt i8 %pre28, 4
%pr_zero = icmp ne i8 %pr, 0
; here with our arguments we have entry_check == false
; and pr_zero == true
br label %loop
loop:
%idx = phi i32 [ 1, %entry ], [ %idxplus, %loopexit ]
; by "partially" unswitching on (entry_check OR pr_zero) to be true
; we cant enforce BOTH to be true
%idxcheck = icmp ne i32 %idx, 30
%brmerge = or i1 %entry_check, %pr_zero
%brmerge2 = or i1 %brmerge, %idxcheck
br i1 %brmerge2, label %loopexit, label %deopt
loopexit:
; here we need to select second value
; YET partial unswitch replaces %entry_check with true
%mux = select i1 %entry_check, i32 83, i32 0
%idxplus = add nuw nsw i32 %idx, 1
%check = icmp ugt i32 %idx, 241
br i1 %check, label %return, label %loop
return:
ret i32 %mux
deopt:
unreachable
}
define i32 @main() {
%res = call i32 @mainReduced(i8 20, i8 10) ; should calculate 0, not 83
ret i32 %res
}
] bin/opt -loop-unswitch partial-bad-unswitch.ll | bin/lli; echo $?
0
] bin/opt -enable-nontrivial-unswitch -simple-loop-unswitch
partial-bad-unswitch.ll | bin/lli; echo $?
83
83 is incorrect here. Simple-loop-unswitch leads to a miscompile.</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>