<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 --- - LLVM is unable to fold a call to pow() with complex arguments"
href="https://llvm.org/bugs/show_bug.cgi?id=31510">31510</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>LLVM is unable to fold a call to pow() with complex arguments
</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>davide@freebsd.org
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, simon.f.whittaker@gmail.com, spatel+llvm@rotateright.com
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Testcase:
#include <complex>
std::complex<double> foo()
{
using namespace std::complex_literals;
std::complex<double> z2 = std::pow(1i, 2);
return z2;
}
with (-O3 -std=c++14)
Clang 3.9 output:
.LCPI0_0:
.quad 4607182418800017408 # double 1
foo(): # @foo()
pushq %rbx
subq $16, %rsp
movl $2, %ebx
movsd .LCPI0_0(%rip), %xmm0 # xmm0 = mem[0],zero
xorpd %xmm1, %xmm1
movapd %xmm0, %xmm5
xorpd %xmm4, %xmm4
jmp .LBB0_1
.LBB0_9: # in Loop: Header=BB0_1 Depth=1
movapd %xmm7, %xmm0
movapd %xmm6, %xmm1
movapd %xmm4, %xmm2
movapd %xmm5, %xmm3
movsd %xmm4, 8(%rsp) # 8-byte Spill
movsd %xmm5, (%rsp) # 8-byte Spill
callq __muldc3
movsd (%rsp), %xmm5 # 8-byte Reload
movsd 8(%rsp), %xmm4 # 8-byte Reload
.LBB0_1: # =>This Loop Header: Depth=1
movapd %xmm0, %xmm7
movapd %xmm1, %xmm6
jmp .LBB0_2
.LBB0_5: # in Loop: Header=BB0_2 Depth=2
movapd %xmm0, %xmm2
movapd %xmm1, %xmm3
movsd %xmm6, 8(%rsp) # 8-byte Spill
movsd %xmm7, (%rsp) # 8-byte Spill
callq __muldc3
movsd (%rsp), %xmm7 # 8-byte Reload
movsd 8(%rsp), %xmm6 # 8-byte Reload
movapd %xmm0, %xmm4
movapd %xmm1, %xmm5
jmp .LBB0_6
.LBB0_2: # Parent Loop BB0_1 Depth=1
movapd %xmm4, %xmm0
movapd %xmm5, %xmm1
shrl %ebx
je .LBB0_10
movapd %xmm0, %xmm4
mulsd %xmm4, %xmm4
movapd %xmm1, %xmm2
mulsd %xmm2, %xmm2
movapd %xmm1, %xmm5
mulsd %xmm0, %xmm5
subsd %xmm2, %xmm4
addsd %xmm5, %xmm5
ucomisd %xmm4, %xmm4
jnp .LBB0_6
ucomisd %xmm5, %xmm5
jp .LBB0_5
.LBB0_6: # in Loop: Header=BB0_2 Depth=2
testb $1, %bl
je .LBB0_2
movapd %xmm7, %xmm0
mulsd %xmm4, %xmm0
movapd %xmm6, %xmm2
mulsd %xmm5, %xmm2
movapd %xmm7, %xmm3
mulsd %xmm5, %xmm3
movapd %xmm6, %xmm1
mulsd %xmm4, %xmm1
subsd %xmm2, %xmm0
addsd %xmm3, %xmm1
ucomisd %xmm0, %xmm0
jnp .LBB0_1
ucomisd %xmm1, %xmm1
jnp .LBB0_1
jmp .LBB0_9
.LBB0_10:
movapd %xmm7, %xmm0
movapd %xmm6, %xmm1
addq $16, %rsp
popq %rbx
retq
gcc7 output:
foo():
subq $8, %rsp
pxor %xmm2, %xmm2
movsd .LC0(%rip), %xmm3
movapd %xmm2, %xmm0
movapd %xmm3, %xmm1
call __muldc3
pxor %xmm3, %xmm3
movsd .LC0(%rip), %xmm2
call __muldc3
addq $8, %rsp
ret
.LC0:
.long 0
.long 1072693248
Compiler explorer link if you want to play at home:
<a href="https://godbolt.org/g/GGfaei">https://godbolt.org/g/GGfaei</a>
I think this is not limited only to pow() but it's a place to start (if anybody
is interested)</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>