Page MenuHomePhabricator

[SLC] Allow llvm.pow(x,2.0) -> x*x etc even if no pow() lib func
ClosedPublic

Authored by foad on Sep 30 2019, 9:32 AM.

Details

Summary

Previously, SLC was disallowing those optimizations if TLI said there is
no pow() library function.

Change-Id: I01c461df3537760b4919422b5ad3a2f004eb4f0f

Diff Detail

Event Timeline

tpr created this revision.Sep 30 2019, 9:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 30 2019, 9:32 AM
tpr added a subscriber: foad.Sep 30 2019, 11:05 AM

@foad pointed out that this fix is wrong. TLI saying pow() is not supported means if we find a call to a function called pow() then we don't know its semantics. So I will push a revised fix.

tpr updated this revision to Diff 222468.Sep 30 2019, 11:42 AM

V2: Better fix that does not accidentally allow pow() transforms.

I don't understand what the check is supposed to be doing in the first place. If we're in LibCallSimplifier::optimizePow, we've already checked that the call is actually calling a function with the right semantics, not just the name.

Indeed, it seemed to be a coarse check in case the following transformations end up calling pow(). However, the only transformation that calls pow() is when shrinking to powf(), which itself chacks for the availability of this routine. So this patch seems to address this issue the wrong way. It seems that removing this check would be better.

evandro added inline comments.Oct 7 2019, 3:21 PM
test/Transforms/InstCombine/pow-1.ll
120 ↗(On Diff #222468)

I don't see a good reason why this check was removed.

xbolva00 resigned from this revision.Nov 12 2019, 3:25 AM
foad commandeered this revision.Apr 30 2020, 9:19 AM
foad added a reviewer: tpr.
foad updated this revision to Diff 261259.Apr 30 2020, 9:19 AM

Rebase. Address review comments.

spatel added inline comments.May 1 2020, 8:15 AM
llvm/test/Transforms/InstCombine/pow-3.ll
9 ↗(On Diff #261259)

Please update/rebase - I added a test to cover the case that I assume was intended:
rG5013a788f8e

llvm/test/Transforms/InstCombine/pow-amdgcn.ll
1 ↗(On Diff #261259)

Can you add a RUN line for this to the existing "pow-1.ll" test file instead of adding a new test file? The existing file is already used to test various target combos.

foad updated this revision to Diff 261478.May 1 2020, 9:42 AM

Rebase. Merge pow-amdgcn.ll into pow-1.ll.

foad marked 2 inline comments as done.May 1 2020, 9:43 AM
lebedev.ri added a subscriber: lebedev.ri.EditedMay 1 2020, 11:44 PM

The patch description is only stating the previous status-quo as a fact,
but gives no reasoning as to why it should change, why it is legal/okay to change it.

Is this really sane?
Can we really invent calls to non-builtin (aka potentially user-provided/overriden) C math function?

foad added a comment.May 2 2020, 12:37 AM

Can we really invent calls to non-builtin (aka potentially user-provided/overriden) C math function?

We're not creating library calls. We're only creating instructions and generic intrinsic calls, neither of which (should) depend on what TLI says about the available library functions.

foad added a comment.May 2 2020, 12:44 AM

The patch description is only stating the previous status-quo as a fact,
but gives no reasoning as to why it should change, why it is legal/okay to change it.

How about something like: "optimizePow does not create any new calls to pow, so it should work regardless of whether the pow library function is available. This allows it to optimize the llvm.pow intrinsic on targets with no math library."

Annoyingly, if I change the commit message, arc diff doesn't propagate that to the web interface.

lebedev.ri added inline comments.May 2 2020, 1:18 AM
llvm/test/Transforms/InstCombine/pow-1.ll
3–16 ↗(On Diff #261478)

Can you precommit this please?

foad updated this revision to Diff 261757.May 4 2020, 1:58 AM

Rebase.

foad marked an inline comment as done.May 4 2020, 1:59 AM
lebedev.ri accepted this revision.May 4 2020, 2:21 AM

Patch description still needs an update but i think this looks okay.

This revision is now accepted and ready to land.May 4 2020, 2:21 AM
This revision was automatically updated to reflect the committed changes.