This is an archive of the discontinued LLVM Phabricator instance.

[RFC][mlir][math] Simplify pow(x, 0.75) into sqrt(sqrt(x)) * sqrt(x).
ClosedPublic

Authored by vzakhari on Nov 3 2022, 12:36 PM.

Details

Summary

Trivial simplification for CPU2017/503.bwaves resulting in 3.89%
speed-up on icelake.

I am not sure about this change. The backends (e.g. LLVM) may be better place for this,
especially if in some target implementations of libm pow(x, 0.75) is faster.
Please let me know what you think.

Diff Detail

Event Timeline

vzakhari created this revision.Nov 3 2022, 12:36 PM
vzakhari requested review of this revision.Nov 3 2022, 12:36 PM

I can confirm similar speedups are obtained on the AArch64 platform.

I think we will get the same transformation once the fast-math and related flags are enabled. I could see the transformation happening in classic-flang with Ofast and I see that the code is in Selection Dag https://github.com/llvm/llvm-project/blob/0589038a6ff12be452be2a2011ac23d1c0d8e7dc/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp#L15922

I guess since the code is not in a Target Specific portion of LLVM this might be an OK simplification to have here. Although LLVM users might not really require it (since the transformation is in LLVM), non-LLVM users (if any) might find it useful.

So, I am +1 for having it here.

vzakhari added a comment.EditedNov 3 2022, 4:28 PM

Kiran, thank you for pointing out the code in selection dag! I should have checked it :)

Edit: I meant to say that the selection dag is not target dependent, so such a canonicalization should be always profitable and it makes sense to have it in MLIR.

This revision is now accepted and ready to land.Nov 4 2022, 3:21 AM
Mogball accepted this revision.Nov 4 2022, 8:06 AM