<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 --- - ScalarEvolution creates redundant select from phi"
href="https://llvm.org/bugs/show_bug.cgi?id=28439">28439</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>ScalarEvolution creates redundant select from phi
</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>Global Analyses
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>rmoryle@synopsys.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=16699" name="attach_16699" title="C example">attachment 16699</a> <a href="attachment.cgi?id=16699&action=edit" title="C example">[details]</a></span>
C example
After <a href="http://reviews.llvm.org/D13378">http://reviews.llvm.org/D13378</a> SE can create SCEV expressions from
select-like phi nodes. But when such expression is expanded, instead of reusing
original phi node, SEExpander creates new select+icmp. This leads to code
duplication.
Simple example is attached. Use 'clang -O2 -S -emit-llvm test.c' to repoduce.
Output with select-like-phi recognition:
if.end: ; preds = %if.else, %if.then
%N.0 = phi i32 [ %A, %if.then ], [ %B, %if.else ]
%cmp17 = icmp sgt i32 %N.0, 0
br i1 %cmp17, label %for.body.preheader, label %for.end
for.body.preheader: ; preds = %if.end
%0 = icmp ult i32 %B, %A <<<<< This two instruction
%1 = select i1 %0, i32 %B, i32 %A <<<<< can be replaced with %N.0 phi
%2 = add i32 %1, -1
%3 = zext i32 %2 to i64
%4 = add nuw nsw i64 %3, 1
%scevgep = getelementptr i32, i32* %P, i64 %4
br label %for.end
for.end:
%P.addr.0.lcssa = phi i32* [ %P, %if.end ], [ %scevgep, %for.body.preheader ]
ret i32* %P.addr.0.lcssa
Code without select-like-phi recognition:
if.end: ; preds = %if.else, %if.then
%N.0 = phi i32 [ %A, %if.then ], [ %B, %if.else ]
%cmp17 = icmp sgt i32 %N.0, 0
%0 = add i32 %N.0, -1
%1 = zext i32 %0 to i64
%2 = add nuw nsw i64 %1, 1
%scevgep = getelementptr i32, i32* %P, i64 %2
%P.addr.0.lcssa = select i1 %cmp17, i32* %scevgep, i32* %P
ret i32* %P.addr.0.lcssa</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>