This is an archive of the discontinued LLVM Phabricator instance.

Bug 49739 - [Matrix] Support #pragma clang fp
ClosedPublic

Authored by effective-light on Apr 20 2021, 2:43 AM.

Details

Summary

From https://bugs.llvm.org/show_bug.cgi?id=49739:

Currently, #pragma clang fp are ignored for matrix types.

For the code below, the contract fast-math flag should be added to the generated call to llvm.matrix.multiply and fadd

typedef float fx2x2_t __attribute__((matrix_type(2, 2)));

void foo(fx2x2_t &A, fx2x2_t &C, fx2x2_t &B) {
  #pragma clang fp contract(fast)
  C = A*B + C;
}

Diff Detail

Event Timeline

effective-light requested review of this revision.Apr 20 2021, 2:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 20 2021, 2:43 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
fhahn added a subscriber: mibintc.

Awesome, thanks for the patch! I'm also adding @mibintc who I think was working on adding support for the pragma & co.

Could you add a brief description to the patch and also reference the bug report on bugs.llvm.org?

clang/test/CodeGen/fp-matrix-pragma.c
2

I don't think we need --target=arm64-unknown-iphoneos or -g0?

24

could you also add a float test that has both contract(fast) reassociate(on)?

effective-light edited the summary of this revision. (Show Details)Apr 20 2021, 3:10 AM

Remove the unnecessary flags and add another test

effective-light marked 2 inline comments as done.Apr 20 2021, 4:04 AM

The diff appears to be 2 separate commits, so on first glance this is only patching the test files. Usually if I am working on a patch and have responded to comments, I compress the patch+updates into a single commit (git rebase -i) before creating a diff to upload to Phabricator.

Are there Matrix builtins that you wish to have decorated with the FMF? e.g. look at CGBuiltin.cpp

mibintc added a reviewer: kpn.Apr 20 2021, 7:07 AM
kpn added a comment.Apr 20 2021, 11:53 AM

I don't know the matrix implementation so I can't swear this hits every place needed, but the uses of CGFPOptionsRAII in this patch look correct at least.

mibintc accepted this revision.Apr 20 2021, 12:27 PM
This revision is now accepted and ready to land.Apr 20 2021, 12:27 PM

Use the correct clang command.

fhahn added a comment.Apr 21 2021, 1:21 AM

I don't know the matrix implementation so I can't swear this hits every place needed, but the uses of CGFPOptionsRAII in this patch look correct at least.

Other parts of the extension include __builtin_matrix_transpose, indexing into a matrix and casting, but I don't think the FMFs are needed there. One thing that would be good to also test would be the compound operators, (-=, +=, *=). @effective-light it would be great if you could add a test for those, then LGTM from my side. If you need someone to commit the change on your behalf, please let us know and share the name + email to use for the commit authorship.

Add a test for compound operations

effective-light added a comment.EditedApr 21 2021, 11:14 AM

I don't know the matrix implementation so I can't swear this hits every place needed, but the uses of CGFPOptionsRAII in this patch look correct at least.

Other parts of the extension include __builtin_matrix_transpose, indexing into a matrix and casting, but I don't think the FMFs are needed there. One thing that would be good to also test would be the compound operators, (-=, +=, *=). @effective-light it would be great if you could add a test for those, then LGTM from my side. If you need someone to commit the change on your behalf, please let us know and share the name + email to use for the commit authorship.

Ya, you can commit it under name: Hamza Mahfooz, email: someguy@effective-light.com, thanks.

fhahn accepted this revision.Apr 22 2021, 1:15 AM

LGTM, thanks!

I'll commit the patch shortly.

This revision was automatically updated to reflect the committed changes.
fhahn added a comment.May 25 2021, 2:50 AM

@effective-light just FYI, if you are interested in improving fast-math flags handling during matrix lowering on the LLVM side, there's https://bugs.llvm.org/show_bug.cgi?id=49738