This is an archive of the discontinued LLVM Phabricator instance.

[flang] Add -fppc-native-vector-element-order option to control the element order in PowerPC vector types
ClosedPublic

Authored by kkwli0 on Jul 20 2023, 8:49 AM.

Details

Summary

This patch is to add a compiler option to control the element order in PowerPC vector types. For example,
on a little-endian platform, we may need to express the vector in the non-native element order. The vec_vcf intrinsic is updated for handling different vector element orders and new LIT tests are added.

Co-authored-by: Mark Danial <Mark.Danial@ibm.com>
Co-authored-by: @DanielCChen

Diff Detail

Event Timeline

kkwli0 created this revision.Jul 20 2023, 8:49 AM
kkwli0 requested review of this revision.Jul 20 2023, 8:49 AM
awarzynski added a comment.EditedJul 21 2023, 2:43 AM

Thanks for working on this! I think that this needs a bit more work - please see my inline comment.

Edit: I've also uploaded https://reviews.llvm.org/D155931 to clarify. I hope that this helps.

Please also add a test to https://github.com/llvm/llvm-project/blob/b70e6e9681925ad06d9899462b9e43250be53f64/flang/test/Driver/frontend-forwarding.f90#L1

clang/include/clang/Driver/Options.td
5432

Why doesn't such option already exist in Flang? Just curious - feels like something quite generic rather than Fortran specific.

flang/lib/Frontend/CompilerInvocation.cpp
573

Please avoid "pushing" directly to llvmArgs. This variable is specfically for -mllvm and for debugging and experimental features. If that's the route that you want to take, then this change is not needed and you can just use -mllvm -fppc-native-vector-element-order=false" rather than introducing a new Flag.

957–960

Unrelated change.

kkwli0 added inline comments.Jul 21 2023, 8:52 AM
flang/lib/Frontend/CompilerInvocation.cpp
573

The goal we want to achieve is to have a compiler option to control the element order. We would expect users to have flang-new -fppc-native-vector-element-order ... instead of specifying the flang-new -mllvm -fppc-native-vector-element-order=false .... Any suggestion is welcome.

awarzynski added inline comments.Jul 21 2023, 9:12 AM
flang/lib/Frontend/CompilerInvocation.cpp
573

The goal we want to achieve is to have a compiler option to control the element order.

Thanks for clarifying! Clearly -mllvm is not what you are after.

Any suggestion is welcome.

You need to identify the correct way to wire this up. It will depend on whether this is a codegen, lowering, or lang options. There are probably other categories to consider, but for those 3 you can check the following for inspiration:

You may need to introduce some new category. Ultimately, you will need to introduce some state somewhere and use your new flag to control it. llvm::cl option does not qualify :)

I hope that this helps. Let me know if you have any questions.

flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp
23–26

Driver options are defined in Options.td.

kkwli0 marked 3 inline comments as done.Jul 26 2023, 3:24 PM
kkwli0 added inline comments.
clang/include/clang/Driver/Options.td
5432

We couldn't find one similar to functionality.

flang/lib/Frontend/CompilerInvocation.cpp
957–960

Will remove the change.

flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp
23–26

Got it.

kkwli0 updated this revision to Diff 544540.Jul 26 2023, 3:28 PM
kkwli0 marked 3 inline comments as done.
kkwli0 edited the summary of this revision. (Show Details)

Thanks for the review. We took your suggestion and implement this option as one of LoweringOptions.

DanielCChen added inline comments.Jul 27 2023, 7:48 AM
flang/test/Driver/driver-help-hidden.f90
68

Do we need to test -fno-ppc-native-vector-element-order?

flang/test/Driver/driver-help.f90
64

Same comment as above.

182

Same comment as above.

kkwli0 updated this revision to Diff 544927.Jul 27 2023, 2:22 PM
kkwli0 marked 3 inline comments as done.
  • address review comments
    • update frontend forwarding test
    • update help file test
    • fix bug - accept -fppc-native-vector-element-order
  • rebase
flang/test/Driver/driver-help-hidden.f90
68

Will do.

flang/test/Driver/driver-help.f90
64

Will do

182

Will do

awarzynski accepted this revision.Jul 28 2023, 5:00 AM

@kkwli0 , thank you for addressing my comments. The driver logic looks good to me. I don't have the expertise to review the other parts, so would appreciate if one other reviewer approves before landing this.

clang/lib/Driver/ToolChains/Flang.cpp
143–146

You can use addAllArgs instead. See https://reviews.llvm.org/D156524.

flang/test/Lower/PowerPC/ppc-vec_cvf-elem-order.f90
2–3

IMHO, it really helps to have _all_ prefixes to be custom. This is basically a neat way of documenting _what_ is being tested (e.g. FIR vs LLVM). Also, I'd normally drop CHECK as that's just noise. This is a nit.

This revision is now accepted and ready to land.Jul 28 2023, 5:00 AM
kkwli0 updated this revision to Diff 545683.Jul 31 2023, 8:34 AM
kkwli0 marked 2 inline comments as done.

@awarzynski Thanks for reviewing the patch.

Update:

  • fixed pre-merge build failure
  • addressed review comments
  • rebase
clang/lib/Driver/ToolChains/Flang.cpp
143–146

Will do

flang/test/Lower/PowerPC/ppc-vec_cvf-elem-order.f90
2–3

Will do

nemanjai added inline comments.Jul 31 2023, 11:51 AM
clang/include/clang/Driver/Options.td
5419–5421

Just out of curiosity, what does this mean for clang? What would it mean for someone to invoke something like:

clang --target=powerpc64le-unknown-linux-gnu -fppc-native-vector-element-order ...
awarzynski added inline comments.Jul 31 2023, 12:04 PM
clang/include/clang/Driver/Options.td
5419–5421
nemanjai added inline comments.Aug 2 2023, 3:03 AM
clang/include/clang/Driver/Options.td
5419–5421

Sounds good. I didn't see that this is in a block that sets that flag.

Thanks. I will wait for a day to see if there are more comments.

Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2023, 2:11 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript