[RFC] Generalized Pattern Matching & InstSimplify

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:

  • Simon

Hi

Yes, this also works for InstCombine. Passing references actually makes it more robust because you can swap the actual IR instruction class for a helper that transparently mimics an IR instruction. Those are already in the patch asExtInstruction<Trait>, ExtBinaryOperator<Trait>, etc. To make InstCombine (ie emitting IR) work, you need to two things: 1.) Make the matcher context collect all information from the pattern that is needed to replace it with new code. For VP, that’s the match root’s %mask and %evl. For constrained FP and complex you need no further info. 2.) Specialize TraitBuilder<Trait> for your trait. That class is constructed with the matcher context. It emits intrinsics when it is told to emit the “real” IR instruction. Eg, for VP when told to emit an fadd, it emits a llvm.vp.fadd with the %mask and %evl from the matcher context. For constrained FP and complex, it will emit the corresponding intrinsics (with default FP round/except mode). - Simon Cheers,