This is an archive of the discontinued LLVM Phabricator instance.

[Matrix] Add LowerMatrixIntrinsics to the NPM
ClosedPublic

Authored by SjoerdMeijer on Jul 20 2020, 8:48 AM.

Details

Summary

LowerMatrixIntrinsics wasn't running yet running under the new pass manager, and this adds LowerMatrixIntrinsics to the pipeline. It's added early so that these matrix intrinsics, which are produced by Clang, to give other optimiser the opportunity to clean up / optimise this further.

Diff Detail

Event Timeline

SjoerdMeijer created this revision.Jul 20 2020, 8:48 AM
fhahn added inline comments.Jul 21 2020, 2:05 AM
llvm/lib/Passes/PassBuilder.cpp
933

I think we should keep this under the same enable-matrix flag like in the old pass manager for now and remove the flag for both when the pass only gets run on functions that contain matrix intrinsics.

SjoerdMeijer marked an inline comment as done.Jul 21 2020, 2:09 AM
SjoerdMeijer added inline comments.
llvm/lib/Passes/PassBuilder.cpp
933

Ah yeah, cheers, forgot about that! Will add that.

  • Check EnableMatrix for adding the pass, and
  • also add it to the -O0 pipeline.
fhahn added inline comments.Jul 21 2020, 9:04 AM
clang/lib/CodeGen/BackendUtil.cpp
1381 ↗(On Diff #279538)

IIUC this references the LLVM option. Does this actually work? Shouldn't that use LangOpts.MatrixTypes, which is set when passing -fenable-matrix to Clang.

clang/test/CodeGen/matrix-lowering-opt-levels.c
8

Might be good to add new-pm run-lines as well.

llvm/lib/Passes/PassBuilder.cpp
933

Is there reason this is run at a different position to the legacy pass manager? If not, I think we should run them at roughly the same location, to minimize differences between new and old PM. In the old pass manager, we run before the VectorizerStart callbacks. Here this would be around line 1102 I think.

SjoerdMeijer marked 3 inline comments as done.Jul 21 2020, 9:21 AM
SjoerdMeijer added inline comments.
clang/lib/CodeGen/BackendUtil.cpp
1381 ↗(On Diff #279538)

It does actually :) But must indeed be a layering violation...will fix.

clang/test/CodeGen/matrix-lowering-opt-levels.c
8

The many mysteries of the NPM..... Now looking I guess you mean adding -fexperimental-new-pass-manager (I was working with a build with the NPM enabled/built).

llvm/lib/Passes/PassBuilder.cpp
933

Since the intrinsics are generated by Clang I thought lowering them the earlier the better. And in the old PM, EarlyCSE was run after it, so that's why I put it right here just before EarlyCSE, but wouldn't mind moving it to where you suggested.

fhahn added inline comments.Jul 21 2020, 9:32 AM
clang/test/CodeGen/matrix-lowering-opt-levels.c
8

adding lines with -fexperimental-new-pass-manager is what I mean. Not sure if that works with NPM enabled builds though.

llvm/lib/Passes/PassBuilder.cpp
933

Yes, EarlyCSE runs after LowerMatrixIntrinsics in addition, if EnableMatrix. I think it's not worth diverging in the new PM. If there's a better position, we should use it for both new PM/LegacyPM.

Agreed, and comments addressed.

fhahn accepted this revision.Jul 21 2020, 9:43 AM

LGTM, thanks! It would be good to also run EarlyCSE as mentioned inline.

llvm/lib/Passes/PassBuilder.cpp
1099

We should probably also run EarlyCSE afterwards (if EnableMatrix is true), to keep things in sync with the legacy PM.

This revision is now accepted and ready to land.Jul 21 2020, 9:43 AM

Many thanks for reviewing again. Will fix that before committing.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 22 2020, 1:49 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
fhahn added a comment.Jul 22 2020, 3:21 AM

Awesome, thanks!