This is an archive of the discontinued LLVM Phabricator instance.

Mapping of FP operations to constrained intrinsics
ClosedPublic

Authored by sepavloff on Oct 29 2019, 6:18 AM.

Details

Summary

This change adds new function 'getConstainedIntrinsic', which for any
gived instruction returns corresponding constrained intrinsic, if the
instruction involves floating point operation. For other instructions,
including constrained intrinsics the function returns zero.

Diff Detail

Event Timeline

sepavloff created this revision.Oct 29 2019, 6:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 29 2019, 6:18 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
sepavloff updated this revision to Diff 227057.Oct 30 2019, 3:20 AM

Fixed typo

kpn added a comment.Nov 4 2019, 5:50 AM

The IRBuilder handles mapping non-constrained operations to constrained operations already. So a front-end just needs to enable strict mode in the IRBuilder and most everything "just works". And clang uses the IRBuilder, so we're good there. Are you working on a front-end that doesn't use the IRBuilder?

kpn added inline comments.Nov 4 2019, 6:46 AM
llvm/lib/IR/FloatingPoint.cpp
170 ↗(On Diff #227057)

Can you please update docs/AddingConstrainedIntrics.rst as well? When new intrinsics are added this switch here would need to be updated as well. Might as well document that fact.

simoll added a subscriber: simoll.Nov 4 2019, 9:36 AM
pengfei added a subscriber: pengfei.Nov 4 2019, 9:41 PM
sepavloff marked an inline comment as done.Nov 6 2019, 6:23 AM
In D69562#1732337, @kpn wrote:

The IRBuilder handles mapping non-constrained operations to constrained operations already. So a front-end just needs to enable strict mode in the IRBuilder and most everything "just works". And clang uses the IRBuilder, so we're good there. Are you working on a front-end that doesn't use the IRBuilder?

In the inliner (D69798) we need to know if we need to use constrained intrinsic prior to the instruction creation. Besides, instruction there are created without operands. So IRBuilder is not suitable in this case.

llvm/lib/IR/FloatingPoint.cpp
170 ↗(On Diff #227057)

Depending on whether D69887 will be accepted or not, the wording would be different. I will update the doc when things become definite.

kpn added inline comments.Nov 6 2019, 10:01 AM
llvm/lib/IR/FloatingPoint.cpp
81 ↗(On Diff #227057)

For something that's not part of a class, shouldn't it have a more specific name? Maybe getConstrainedIntrinsicID()?

kpn added inline comments.Nov 6 2019, 10:26 AM
llvm/lib/IR/FloatingPoint.cpp
81 ↗(On Diff #227057)

Eh, scratch half of that comment, but I do still prefer the more specific name "getConstrainedIntrinsicID".

arsenm added a subscriber: arsenm.Nov 6 2019, 10:41 AM
arsenm added inline comments.
llvm/lib/IR/FloatingPoint.cpp
85 ↗(On Diff #227057)

I would prefer direct returns rather than variable assign and break

172 ↗(On Diff #227057)

I think this should assert or something on unhandled target intrinsics. Right now it will just return then original ID which is probably not expected

172 ↗(On Diff #227057)

Nevermind, I can't read. It will return not_intrinsic although I still think this is a possible source of error

llvm/unittests/IR/InstructionsTest.cpp
524–525

EXPECT_EQ

kpn added inline comments.Nov 6 2019, 10:55 AM
llvm/lib/IR/FloatingPoint.cpp
172 ↗(On Diff #227057)

Honestly, I agree that this being a possible source of error. But I'm not sure we have an easy check that callers can make to find out if they should be calling this function in the first place. Without an easy check we're left with calling this function and checking the return value.

sepavloff updated this revision to Diff 228204.Nov 7 2019, 3:10 AM

Updated patch

  • Renamed getConstrainedIntrinsic to getConstrainedIntrinsicID.
  • Implementwd mapping using fix from D69887.
  • Used EXPECT_EQ instead of EXPECT_TRUE in unit test.
sepavloff marked 4 inline comments as done.Nov 7 2019, 4:22 AM
sepavloff added inline comments.
llvm/lib/IR/FloatingPoint.cpp
85 ↗(On Diff #227057)

Single exit point has advantages. For instance we could set a watch in debugger on return statement and filter interesting cases.

172 ↗(On Diff #227057)

This function must work correctly if Instr does not represent floating point operation. This property is mentioned in the function documentation. It is used in Inliner (D69798) to check if current instruction requires replacement with constrained intrinsic or may be processed with clone method.

sepavloff updated this revision to Diff 239861.Jan 23 2020, 5:17 AM

Rebased patch

sepavloff updated this revision to Diff 242026.Feb 3 2020, 4:56 AM

Updated patch

sepavloff updated this revision to Diff 418561.Mar 28 2022, 6:11 AM

Rebase plus cosmetic changes

Herald added a project: Restricted Project. · View Herald TranscriptMar 28 2022, 6:11 AM
andrew.w.kaylor accepted this revision.Mar 29 2022, 9:23 AM

This looks good. I have just a couple of minor nits.

llvm/include/llvm/IR/FPEnv.h
71
llvm/lib/IR/FPEnv.cpp
92

It may be worth having a comment here to explain why FCmp is handled separately.

This revision is now accepted and ready to land.Mar 29 2022, 9:23 AM
sepavloff updated this revision to Diff 419043.Mar 29 2022, 9:17 PM

Addressed reviewer's notes

This revision was landed with ongoing or failed builds.Mar 29 2022, 10:24 PM
This revision was automatically updated to reflect the committed changes.