Index: docs/LangRef.rst =================================================================== --- docs/LangRef.rst +++ docs/LangRef.rst @@ -5171,6 +5171,59 @@ !0 = !{!"llvm.loop.unroll.full"} +'``llvm.loop.unroll_and_jam``' +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This metadata is treated very similarly to the ``llvm.loop.unroll`` metadata +above, but affect the unroll and jam pass. In addition any loop with +``llvm.loop.unroll`` metadata but no ``llvm.loop.unroll_and_jam`` metadata will +disable unroll and jam (so ``llvm.loop.unroll`` metadata will be left to the +unroller, plus ``llvm.loop.unroll.disable`` metadata will disable uroll and jam +too.) + +The metadata for unroll and jam otherwise is the same as for ``unroll``. +``llvm.loop.unroll_and_jam.enable``, ``llvm.loop.unroll_and_jam.disable`` and +``llvm.loop.unroll_and_jam.count`` do the same as for unroll. +``llvm.loop.unroll_and_jam.full`` is not supported. Again these are only hints +and the normal safety checks will still be performed. + +'``llvm.loop.unroll_and_jam.count``' Metadata +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This metadata suggests an unroll and jam factor to use, similarly to +``llvm.loop.unroll_and_jam.count``. The first operand is the string +``llvm.loop.unroll.count`` and the second operand is a positive integer +specifying the unroll factor. For example: + +.. code-block:: llvm + + !0 = !{!"llvm.loop.unroll_and_jam.count", i32 4} + +If the trip count of the loop is less than the unroll count the loop +will be partially unroll and jammed. + +'``llvm.loop.unroll_and_jam.disable``' Metadata +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This metadata disables loop unroll and jamming. The metadata has a single +operand which is the string ``llvm.loop.unroll_and_jam.disable``. For example: + +.. code-block:: llvm + + !0 = !{!"llvm.loop.unroll_and_jam.disable"} + +'``llvm.loop.unroll_and_jam.enable``' Metadata +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This metadata suggests that the loop should be fully unroll and jammed if the +trip count is known at compile time and partially unrolled if the trip count is +not known at compile time. The metadata has a single operand which is the +string ``llvm.loop.unroll_and_jam.enable``. For example: + +.. code-block:: llvm + + !0 = !{!"llvm.loop.unroll_and_jam.enable"} + '``llvm.loop.licm_versioning.disable``' Metadata ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Index: docs/Passes.rst =================================================================== --- docs/Passes.rst +++ docs/Passes.rst @@ -83,6 +83,8 @@ A pass which can be used to count how many alias queries are being made and how the alias analysis implementation being used responds. +.. _passes-da: + ``-da``: Dependence Analysis ---------------------------- @@ -825,6 +827,27 @@ been canonicalized by the :ref:`indvars ` pass, allowing it to determine the trip counts of loops easily. +``-loop-unroll-and-jam``: Unroll and Jam loops +---------------------------------------------- + +This pass implements a simple unroll and jam classical loop optimisation pass. +It transforms loop from: + +.. code-block:: c++ + + for i.. i+= 1 for i.. i+= 4 + for j.. for j.. + code(i, j) code(i, j) + code(i+1, j) + code(i+2, j) + code(i+3, j) + remainder loop + +Which can be seen as unrolling the outer loop and "jamming" (fusing) the inner +loops into one. When variables or loads can be shared in the new inner loop, this +can lead to significant performance improvements. It uses +:ref:`Dependence Analysis ` for proving the transformations are safe. + ``-loop-unswitch``: Unswitch loops ----------------------------------