Model matrices in the llvm IR like (<4 x 4 x float>)

I am going through this llvm ( This IR looks perfectly nice to me. As a beginner, I only want to ask is there any way to produce exactly same IR

%0 = load <4 x 4 x float>, <4 x 4 x float>* %a, align 16
%1 = load <4 x 4 x float>, <4 x 4 x float>* %b, align 16
%2 = call <4 x 4 x float> @llvm.matrix.multiply.m4_4f32.m4_4f32.m4_4f32(<4 x 4 x float> %0, <4 x 4 x float> %1)
store <4 x 4 x float> %2, <4 x 4 x float>* %c, align 16

from current llvm(release/16.x) using some passes. If the answer is no, so how to proceed to support this type of IR in both clang and llvm?

The current matrix support lowers matrixes as flat vector, so instead of <4 x 4 x float> it uses <16 x float>. See Compiler Explorer for an example

1 Like

Thank you for the clarification.

  1. By using the flag -print-before=lower-matrix-intrinsics, we are able to dump the instructions,

    however, could we generate the valid .ll file of the same, where we can iterate through each of the instructions?

  2. Also, if I want to store the matrix value like similar to the statement written below, how to do it?

matrix_ty A = {{1,2},{3,4}}; // similar to this statement, but with correct syntax

If you want to dump a module, you can use -mllvm -print-module-scope

That’s not supported at the moment, please see Matrix Types — Clang 17.0.0git documentation for the supported operations.

1 Like