This is an archive of the discontinued LLVM Phabricator instance.

[flang] Propagate fastmath flags during intrinsics simplification.
ClosedPublic

Authored by vzakhari on Nov 15 2022, 11:14 AM.

Details

Summary

In general, the meaning of fastmath flags on a call during inlining
is that the call's operation flags must be ignored. For user functions
that means that the fastmath flags used for the function definition
override any call site's fastmath flags. For intrinsic functions
we can use the call site's fastmath flags, but we have to make sure
that the call sites with different flags produce/use different
simplified versions of the same intrinsic function.

Diff Detail

Event Timeline

vzakhari created this revision.Nov 15 2022, 11:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 15 2022, 11:14 AM
vzakhari requested review of this revision.Nov 15 2022, 11:14 AM

Note that this only works for dot_product now. If it looks okay, I will extend it to other cases.

jeanPerier accepted this revision.Nov 16 2022, 12:45 AM

Looks good to me. Have you considered having the flag copy part happening in fir::FirOpBuilder builder(op, kindMap); since the ctor has the op and is setting the builder ? But maybe that is too hidden and may not always be desired, so I am also OK with the explicit flag copy.

This revision is now accepted and ready to land.Nov 16 2022, 12:45 AM

Looks good to me. Have you considered having the flag copy part happening in fir::FirOpBuilder builder(op, kindMap); since the ctor has the op and is setting the builder ? But maybe that is too hidden and may not always be desired, so I am also OK with the explicit flag copy.

Thank you, Jean! Yes, I thought about automatically setting fastmath flags from the passed op, but it did not seem right to me. By definition, the passed op defines just the insertion point and does not necessarily refer to the operation that is being transformed. So there is a possibility that a pass transforms op1 with some fastmath flags, but uses op2 with other fastmath flags as an insertion point. I do not think it is possible now, but it may be the case later with MLIR-level inlining.

vzakhari updated this revision to Diff 475883.Nov 16 2022, 11:39 AM

Added support for reduction cases.

Looks good to me. Have you considered having the flag copy part happening in fir::FirOpBuilder builder(op, kindMap); since the ctor has the op and is setting the builder ? But maybe that is too hidden and may not always be desired, so I am also OK with the explicit flag copy.

Thank you, Jean! Yes, I thought about automatically setting fastmath flags from the passed op, but it did not seem right to me. By definition, the passed op defines just the insertion point and does not necessarily refer to the operation that is being transformed. So there is a possibility that a pass transforms op1 with some fastmath flags, but uses op2 with other fastmath flags as an insertion point. I do not think it is possible now, but it may be the case later with MLIR-level inlining.

Ok, that makes sense to me.