This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][Math] Add constant folder for powf
ClosedPublic

Authored by wsmoses on Mar 16 2022, 1:51 PM.

Details

Summary

Constant fold powf, given two constant operands and a compatible type

Diff Detail

Event Timeline

wsmoses created this revision.Mar 16 2022, 1:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 16 2022, 1:51 PM
wsmoses requested review of this revision.Mar 16 2022, 1:51 PM
ftynse accepted this revision.Mar 17 2022, 10:40 AM
ftynse added inline comments.
mlir/lib/Dialect/Math/IR/MathOps.cpp
93

Should we rather check for ft.getFloatSemantics() being Double/Float here?

This revision is now accepted and ready to land.Mar 17 2022, 10:40 AM
wsmoses added inline comments.Mar 17 2022, 10:46 AM
mlir/lib/Dialect/Math/IR/MathOps.cpp
93

I'm not aware of a good check on fltSemantics for that (https://llvm.org/doxygen/structllvm_1_1fltSemantics.html). If you know a better check, would be happy to use (and presumably also check the log2 one above). If I recall from the log2 case this is what LLVM itself does presently.

ftynse added inline comments.Mar 17 2022, 10:56 AM
mlir/lib/Dialect/Math/IR/MathOps.cpp
93

&APFloatBase::getIEEESingle() == &ft.getFloatSemantics() ? AFAIK, these are singleton objects return by-reference so you can just compare their addresses.

bondhugula added inline comments.
mlir/lib/Dialect/Math/IR/MathOps.cpp
76

The op definition guarantees that the result is float-like. Things enforced by the verifier need not be re-checked.

82

unsigned

82–84

Use llvm::all_of on operands?

mlir/test/Dialect/Math/canonicalize.mlir
79

This and the one above can be a CHECK-NEXT.

This revision was landed with ongoing or failed builds.Mar 17 2022, 11:19 AM
This revision was automatically updated to reflect the committed changes.
ftynse added inline comments.Mar 18 2022, 2:32 AM
mlir/lib/Dialect/Math/IR/MathOps.cpp
76

Float-like means it's a float scalar, a vector of floats or a tensor of floats. The logic below only applies to float scalars, so the check is required.

bondhugula added inline comments.Mar 18 2022, 3:50 AM
mlir/lib/Dialect/Math/IR/MathOps.cpp
76

Oh, missed that, thanks.