[llvm] [LoopIdiomRecognizer] Implement CRC recognition (PR #79295)

Mikhail Gudim via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 23 22:02:11 PST 2024


mgudim wrote:

We should think through the high-level plan of how the implementation should work eventually for targets supporting this. At the same time, we can divide this into smaller pieces which has many advantages. 

I can suggest the following, but I really would appreciate feedback / approval of others (@kparzysz):

  (1) Create new (overloaded) intrinsics for performing a number of steps in polynomial division. Something like:
 `pdivstep(i8 dividend, i8 divisor, i32 nsteps)`. This intrinsic returns the result of performing `nsteps` steps in the polynomial divison of `dividend` by the `divisor`. Here it is assumed that the highest degree of polynomial corresponds to the MSB of the number representing it. Actual loop could be using reverse representation, but we can express it by combining with bitreverse intrinsics.

  (2) Add functions to `PreISelIntrinsicLowering` to expand the pdivstep intrinsic. We can expand back into a loop (or unrolled loop) like `expandMemCpyAsLoop`. Or we can emit a table lookup (like in this MR), or we can expand using `clmul` intrinsics.
For testing purposes, we can introduce flags to always (if possible) do specified type of expansion. We can start with "expand into a loop" and a "table lookup". We can add expansion using `clmul`s later.
  
  (3) Implement the recognition part in `LoopIdiomRecognize`. As in this MR, the generation of the intrinsic should be controlled by a flag. Also, the idiom should be "polynomial division", CRC is just one application of it. I don't know any other though :-)  If the whole plan is approved, we can merge this part first.

  (4) Recognize identities on `pdiv` intrinsics. I think in coremark, the 8-bit ones combine eventually into larger one. This should be after inlining, so probably we can do it in `PreISelIntrinsicLowering`?

  (5) Create a way for targets to specify if `pdiv` intrinsics should be generated. If yes, how should they be expanded (during `PreISelLowering`)?

https://github.com/llvm/llvm-project/pull/79295


More information about the llvm-commits mailing list