This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine][SimplifyLibCalls] An extra sqrtf was produced because of transformations in optimizePow function
ClosedPublic

Authored by vdsered on Mar 8 2021, 10:53 PM.

Details

Summary

See: https://bugs.llvm.org/show_bug.cgi?id=47613

There was an extra sqrt call because shrinking emitted a new powf and at the same time optimizePow replaces the previous pow with sqrt and as the result we have two instructions that will be in worklist of InstCombie despite the fact that %powf is not used by anyone (it is alive because of errno).

As the result we have two instructions:

%powf = call fast float @powf(float %x, float 5.000000e-01)
%sqrt = call fast double @sqrt(double %dx)

%powf will be converted to %sqrtf on a later iteration.

As a quick fix for that I moved shrinking to the end of optimizePow so that pow is replaced with sqrt at first that allows not to emit a new shrunk powf.

Diff Detail

Event Timeline

vdsered created this revision.Mar 8 2021, 10:53 PM
vdsered requested review of this revision.Mar 8 2021, 10:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 8 2021, 10:53 PM
vdsered removed a subscriber: sqrt.Mar 8 2021, 10:54 PM
lebedev.ri edited the summary of this revision. (Show Details)Mar 8 2021, 11:09 PM
lebedev.ri retitled this revision from An extra sqrtf was produced because of transformations in optimizePow function to [InstCombine][SimplifyLibCalls] An extra sqrtf was produced because of transformations in optimizePow function.Mar 8 2021, 11:14 PM
spatel added inline comments.Mar 9 2021, 4:55 AM
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
1817

We can localize "Shrunk" to make this clearer:

if (Value *Shrunk = optimizeBinaryDoubleFP(Pow, B, true))
  return Shrunk;

(and remove the declaration at line 1707).

vdsered updated this revision to Diff 329528.Mar 9 2021, 9:39 PM
vdsered added inline comments.Mar 9 2021, 9:42 PM
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
1817

Fixed.

vdsered updated this revision to Diff 329533.Mar 9 2021, 9:56 PM
spatel accepted this revision.Mar 10 2021, 4:16 AM

LGTM

This revision is now accepted and ready to land.Mar 10 2021, 4:16 AM
Harbormaster completed remote builds in B93008: Diff 329528.