Skip to content

#22966: Rewrite genericWordQuotRem2Op to improve performance (by approx. 24x)

This PR should improve #22966 (closed) by implementing the algorithm implemented in compiler-rt mentioned in the issue as a replacement for genericWordQuotRem2Op. On my M3 mac, this produces correct results for the the test quotRem2, though it might be prudent to add more tests (such as the ones found in compiler-rt). (I have a test written using the values from here which I'm using for performance measurement which I'll add to the test suite).

Initial testing shows this is approximately 24 times faster than the code it's replacing.

My main questions on this are:

  • licensing - the code for the function in question is included in comments (nearly) verbatim to help with understanding, which possibly means complying with the Apache 2.0 license (with LLVM Exceptions).
  • I haven't written much Cmm code, so there's likely to be many improvements, particularly around handling conditional execution (if, while).
  • The code is quite imperative looking, to mirror the cribbed compiler-rt code - I found this easier to make the translation than using the more functional composition of CmmAGraphs,

Please take a few moments to address the following points:

  • if your MR may break existing programs (e.g. touches base or causes the compiler to reject programs), please describe the expected breakage and add the user-facing label. This will run ghc/head.hackage> to characterise the effect of your change on Hackage.
  • ensure that your commits are either individually buildable or squashed
  • ensure that your commit messages describe what they do (referring to tickets using #NNNN syntax when appropriate)
  • have added source comments describing your change. For larger changes you likely should add a [Note][notes] and cross-reference it from the relevant places.
  • add a [testcase to the testsuite][adding test].
  • updates the users guide if applicable
  • mentions new features in the release notes for the next release
Edited by Sylvain Henry

Merge request reports