[llvm-dev] [RFC] Using basic block attributes to implement non-default floating point environment

Doerfert, Johannes via llvm-dev llvm-dev at lists.llvm.org
Thu Oct 3 11:54:34 PDT 2019

On 10/03, Kaylor, Andrew via llvm-dev wrote:
> I’d like to emphasize that the constrained intrinsics prevent
> optimizations *by default*. We have a plan to go back and teach
> individual optimizations how to handle these intrinsics. The idea is
> that if an optimization knows nothing about the constrained intrinsics
> then it won’t try to transform them, but if an optimization has been
> taught to handle the intrinsics correctly then it isn’t limited by
> anything other than the semantics of the constraints. Once we’ve
> updated an optimization pass, it will be able to do everything with a
> constrained intrinsic that has the “relaxed” settings
> (“fpexcept.ignore” and “fpround.tonearest”) that it would be able to
> do with the regular operation.

The way I understood it, the constraint intrinsics are not the only
problem but the regular ones can be. That is, optimizations will move
around/combine/replace/... regular floating operations in the presence
of constraint intrinsics because they do not impact each other (other
than def-use). If that understanding is correct, and this is a problem,
then I doubt that we want basic block attributes. Also, given that the
constraint intrinsics are inaccessible_mem_only, optimizations will work
with them as they work with other opaque instructions for which certain
effects are known.

(Btw. is it intentional that these can unwind?)

> This philosophy is key to the way that we’re approaching FPENV
> support. One of the primary goals is that any optimization that isn’t
> specifically aware of the mechanisms we’re using will automatically
> get conservatively correct behavior. The problem with relying on basic
> block attributes is that it requires teaching all current
> optimizations to look for the attribute.

Agreed, totally.

> We had a somewhat similar problem when we implemented Windows
> exception handling. The implementation introduced basic blocks that
> instructions shouldn’t be hoisted or sunk into. We ended up having to
> chase down a lot of cases where our rules were violated. I think this
> stems from not having a single place to check the legality of code
> motion.

Agreed. Outlineing seems a reasonable approach to avoid code motion or
at least restrict the locations that need to know about the constraints.
Given that we already have no implicit float, it seems natural to use it
here and make sure IPOs honor it.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191003/f5e9a424/attachment.sig>

More information about the llvm-dev mailing list