Page MenuHomePhabricator

Mapping of FP operations to constrained intrinsics
Needs ReviewPublic

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.

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.Wed, Nov 6, 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.Wed, Nov 6, 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.Wed, Nov 6, 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.Wed, Nov 6, 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
436–437

EXPECT_EQ

kpn added inline comments.Wed, Nov 6, 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.Thu, Nov 7, 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.Thu, Nov 7, 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.