[llvm-dev] [RFC] Generalized Pattern Matching & InstSimplify

Simon Moll via llvm-dev llvm-dev at lists.llvm.org
Wed Nov 25 08:45:47 PST 2020


Hi,

How can we make InstSimplify/InstCombine work with intrinsics?

This RFC proposes generalized pattern matching to lift LLVM's existing InstSimplify to work on intrinsics as well as on regular instructions. For details, technical discussion, please refer to:

    https://reviews.llvm.org/D92086

The patch includes tests where InstSimplify optimizes @llvm.vp.add and @llvm.experimental.contrained.fadd as a proof of concept.

The idea is to pretend that the intrinsics were the actual instruction (eg an fadd) and run the existing InstSimplify logic. We augment pattern matching with a context object - if during pattern matching the context object is no longer sure that the intrinsics are a safe match (eg because there may be fp exceptions that we need to preserve), it aborts the match. In effect, only legal simplifications are performed.

We expect the approach to work as well for the [proposed] complex arithmetic intrinsics (by masking regular `fmul` and making `llvm.complex.fmul` pass as `fmul` instead).

The current patch only considers InstSimplify where patterns are replaced by leaf values. We know how to extend this to InstCombine where new code is emitted to replace the old one (by passing the context object to an IR Builder class) - this was implemented before in https://reviews.llvm.org/D57504 for VP intrinsics.

- Simon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201125/e5c97437/attachment.html>


More information about the llvm-dev mailing list