<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 - Useless PHI nodes created prevent constant folding"
href="https://bugs.llvm.org/show_bug.cgi?id=33885">33885</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Useless PHI nodes created prevent constant folding
</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>enhancement
</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>davide@freebsd.org
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>/home/davide/work/llvm-project-20170507/build-release/bin/clang -O2 -flto
golden.c -o golden.o -c
/home/davide/work/llvm-project-20170507/build-release/bin/clang -O2 -flto fib.c
-o fib.o -c
/home/davide/work/llvm-project-20170507/build-release/bin/clang
-fuse-ld=/home/davide/work/llvm-project-20170507/build-release/bin/ld.lld
-Wl,-save-temps golden.o fib.o -o patatino
/home/davide/work/llvm-project-20170507/build-release/bin/llvm-dis
patatino.0.4.opt.bc -o -
$ cat golden.c
#include <stdio.h>
extern int fib(int);
double approx_gr() {
return (double)fib(10) / fib(9);
}
int main() {
printf("%lf\n", approx_gr());
return 0;
}
$ cat fib.c
int fib(int n) {
int a=0, b=1, t=0;
while (n--) {
t = b;
b = b + a;
a = t;
}
return b;
}
The change triggering this is:
commit 5afb2ffdac5bb150a503e6ddbb9df6a7e486afaf
Author: Evgeny Stupachenko <<a href="mailto:evstupac@gmail.com">evstupac@gmail.com</a>>
Date: Thu Mar 2 17:38:46 2017 +0000
The patch turns on epilogue unroll for loops with constant recurency start.
The optimized bitcode reverting the change is:
define i32 @main() local_unnamed_addr #0 {
fib.exit17:
%0 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8],
[5 x i8]* @.str, i64
0, i64 0), double 0x3FF9E4129E4129E4)
ret i32 0
}
while ToT looks like:
define i32 @main() local_unnamed_addr #0 {
br label %1
; <label>:1: ; preds = %1, %0
%2 = phi i32 [ %5, %1 ], [ 34, %0 ]
%3 = phi i32 [ %2, %1 ], [ 21, %0 ]
%4 = phi i32 [ %6, %1 ], [ 2, %0 ]
%5 = add nsw i32 %2, %3
%6 = add nsw i32 %4, -1
%7 = icmp eq i32 %6, 0
br i1 %7, label %fib.exit, label %1, !llvm.loop !2
fib.exit: ; preds = %1
%8 = sitofp i32 %5 to double
%9 = fdiv double %8, 5.500000e+01
%10 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8],
[5 x i8]* @.str, i64
0, i64 0), double %9)
ret i32 0
}</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>