<html>
<head>
<base href="http://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 --- - [InstCombine] prematurely promoting floating point negation"
href="http://llvm.org/bugs/show_bug.cgi?id=21914">21914</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[InstCombine] prematurely promoting floating point negation
</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>wujingyue@gmail.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>The optimization that transforms (-x * y) to -(x * y) for floating pointer
numbers seems premature.
<a href="http://llvm.org/doxygen/InstCombineMulDivRem_8cpp_source.html#l00602">http://llvm.org/doxygen/InstCombineMulDivRem_8cpp_source.html#l00602</a>
00602 if (Opnd0->hasOneUse()) {
00603 // -X * Y => -(X*Y) (Promote negation as high as possible)
00604 Value *T = Builder->CreateFMul(N0, Opnd1);
00605 Value *Neg = Builder->CreateFNeg(T);
00606 Neg->takeName(&I);
00607 return ReplaceInstUsesWith(I, Neg);
00608 }
While I understand the motivation of this transformation, it prevents potential
LICM if X is a loop invariant and Y is a loop variant. For instance,
int bar(int, int);
void foo(int n, float *output, float beta) {
float sum = 0;
for (int i = 0; i < n; ++i)
sum += bar(i, i * (-beta));
*output = sum;
}
With i*(-beta) transformed to -(i*beta), the LICM passes after instcombine is
unable to hoist -beta outside the loop. As a result, "opt -O3" leaves a fsub
instruction inside the loop:
define void @_Z3fooiPff(i32 %n, float* nocapture %output, float %beta) #0 {
entry:
%cmp7 = icmp sgt i32 %n, 0
br i1 %cmp7, label %for.body.lr.ph, label %for.end
for.body.lr.ph: ; preds = %entry
%0 = add i32 %n, -1
br label %for.body
for.body: ; preds = %for.body,
%for.body.lr.ph
%i.09 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
%sum.08 = phi float [ 0.000000e+00, %for.body.lr.ph ], [ %add, %for.body ]
%conv = sitofp i32 %i.09 to float
%1 = fmul float %conv, %beta
%mul = fsub float -0.000000e+00, %1
%conv1 = fptosi float %mul to i32
%call = tail call i32 @_Z3barii(i32 %i.09, i32 %conv1)
%conv2 = sitofp i32 %call to float
%add = fadd float %sum.08, %conv2
%inc = add nsw i32 %i.09, 1
%exitcond = icmp eq i32 %i.09, %0
br i1 %exitcond, label %for.end.loopexit, label %for.body
for.end.loopexit: ; preds = %for.body
%add.lcssa = phi float [ %add, %for.body ]
br label %for.end
for.end: ; preds = %for.end.loopexit,
%entry
%sum.0.lcssa = phi float [ 0.000000e+00, %entry ], [ %add.lcssa,
%for.end.loopexit ]
store float %sum.0.lcssa, float* %output, align 4, !tbaa !1
ret void
}
Jingyue</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>