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.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
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?
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. |
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. |
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()? |
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". |
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 |
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. |
Updated patch
- Renamed getConstrainedIntrinsic to getConstrainedIntrinsicID.
- Implementwd mapping using fix from D69887.
- Used EXPECT_EQ instead of EXPECT_TRUE in unit test.
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. |