Skip to content

[MIPS] Add FeatureMSA to i6400 and i6500 cores #134985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

mgoudar
Copy link
Contributor

@mgoudar mgoudar commented Apr 9, 2025

  • Enable 'FeatureMSA' for MIPS i6400 and i6500 cpu.
  • Enable -mmsa option if mcpu is set to either i6400 or i6500
  • added clang driver test to validate msa feature
  • added llvm codegen test to validate msa instructions for cpu i6500 and i6400

MIPS i6400 and i6500 cores implements and enables MSA (MIPS SIMD ARCHITECTURE) by default.

i6400 and i6500 cores support MIPS SIMD Architecture (MSA) instructions
@mgoudar mgoudar force-pushed the pr/add-mips-msa-feature-to-i6500 branch from b6722de to 36a78bb Compare April 9, 2025 10:22
Copy link
Member

@mshockwave mshockwave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI has reported an error:

Exit Code: 2

Command Output (stderr):
--
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/build/bin/llc -mtriple=mips-elf -mcpu=i6500 < /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/llvm/test/CodeGen/Mips/msa/i6500.ll |    /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/build/bin/FileCheck /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/llvm/test/CodeGen/Mips/msa/i6500.ll --check-prefix=MIPS32 # RUN: at line 3
+ /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/build/bin/llc -mtriple=mips-elf -mcpu=i6500
+ /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/build/bin/FileCheck /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/llvm/test/CodeGen/Mips/msa/i6500.ll --check-prefix=MIPS32
Cannot handle this ValVT.
UNREACHABLE executed at /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/llvm/lib/Target/Mips/MipsISelLowering.cpp:3119!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/build/bin/llc -mtriple=mips-elf -mcpu=i6500
1.	Running pass 'Function Pass Manager' on module '<stdin>'.
2.	Running pass 'MIPS DAG->DAG Pattern Instruction Selection' on function '@llvm_mips_dlsa_test'
 #0 0x00005d08c95dee68 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/llvm/lib/Support/Unix/Signals.inc:804:13
 #1 0x00005d08c95dc99e llvm::sys::RunSignalHandlers() /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/llvm/lib/Support/Signals.cpp:106:18
 #2 0x00005d08c95df4f1 SignalHandler(int, siginfo_t*, void*) (/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/build/bin/llc+0x74b54f1)
 #3 0x00007e830e867520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007e830e8bb9fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007e830e867476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007e830e84d7f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00005d08c9549910 llvm::install_out_of_memory_new_handler() /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/llvm/lib/Support/ErrorHandling.cpp:195:0
 #8 0x00005d08c74ef031 CC_MipsO32(unsigned int, llvm::MVT, llvm::MVT, llvm::CCValAssign::LocInfo, llvm::ISD::ArgFlagsTy, llvm::CCState&, llvm::ArrayRef<unsigned short>) /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/llvm/lib/Target/Mips/MipsISelLowering.cpp:3099:7
 #9 0x00005d08c74e3284 CC_MipsO32_FP /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/build/lib/Target/Mips/MipsGenCallingConv.inc:381:9
#10 0x00005d08c74e3284 CC_Mips_FixedArg(unsigned int, llvm::MVT, llvm::MVT, llvm::CCValAssign::LocInfo, llvm::ISD::ArgFlagsTy, llvm::CCState&) /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/build/lib/Target/Mips/MipsGenCallingConv.inc:581:10
#11 0x00005d08c8496026 llvm::CCState::AnalyzeFormalArguments(llvm::SmallVectorImpl<llvm::ISD::InputArg> const&, bool (*)(unsigned int, llvm::MVT, llvm::MVT, llvm::CCValAssign::LocInfo, llvm::ISD::ArgFlagsTy, llvm::CCState&)) /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/llvm/lib/CodeGen/CallingConvLower.cpp:92:9
#12 0x00005d08c74e9d80 getStackSize /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/llvm/include/llvm/CodeGen/CallingConvLower.h:245:42
#13 0x00005d08c74e9d80 llvm::MipsTargetLowering::LowerFormalArguments(llvm::SDValue, unsigned int, bool, llvm::SmallVectorImpl<llvm::ISD::InputArg> const&, llvm::SDLoc const&, llvm::SelectionDAG&, llvm::SmallVectorImpl<llvm::SDValue>&) const /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/llvm/lib/Target/Mips/MipsISelLowering.cpp:3798:35

Copy link
Member

@mshockwave mshockwave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a non-blocking suggestion: it'll be nice if you test individual CPU's features like https://github.com/llvm/llvm-project/blob/main/clang/test/Driver/riscv-cpus.c

@@ -0,0 +1,69 @@
; Test the MSA intrinsics that are encoded with the SPECIAL instruction format.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use update_llc_test_checks.py to maintain this test?

Copy link
Contributor Author

@mgoudar mgoudar Apr 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have written driver test mips-cpus.c instead of codegen as you suggested.
as mips-cpus.c test, we need to enable MSA feature via -mmsa flag. I think we need to enable this as part of i6500 cpu flag by default via driver. please suggest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have enabled MSA feature from driver also when -mcpu i6500/i6400 is specified. Also I have added codegen test to verify MSA instructions when i650/i6400 cpu is specified. please review

@mgoudar
Copy link
Contributor Author

mgoudar commented Apr 10, 2025

CI has reported an error:

Exit Code: 2

Command Output (stderr):
--
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/build/bin/llc -mtriple=mips-elf -mcpu=i6500 < /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/llvm/test/CodeGen/Mips/msa/i6500.ll |    /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/build/bin/FileCheck /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/llvm/test/CodeGen/Mips/msa/i6500.ll --check-prefix=MIPS32 # RUN: at line 3
+ /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/build/bin/llc -mtriple=mips-elf -mcpu=i6500
+ /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/build/bin/FileCheck /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/llvm/test/CodeGen/Mips/msa/i6500.ll --check-prefix=MIPS32
Cannot handle this ValVT.
UNREACHABLE executed at /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/llvm/lib/Target/Mips/MipsISelLowering.cpp:3119!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/build/bin/llc -mtriple=mips-elf -mcpu=i6500
1.	Running pass 'Function Pass Manager' on module '<stdin>'.
2.	Running pass 'MIPS DAG->DAG Pattern Instruction Selection' on function '@llvm_mips_dlsa_test'
 #0 0x00005d08c95dee68 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/llvm/lib/Support/Unix/Signals.inc:804:13
 #1 0x00005d08c95dc99e llvm::sys::RunSignalHandlers() /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/llvm/lib/Support/Signals.cpp:106:18
 #2 0x00005d08c95df4f1 SignalHandler(int, siginfo_t*, void*) (/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/build/bin/llc+0x74b54f1)
 #3 0x00007e830e867520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007e830e8bb9fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007e830e867476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007e830e84d7f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00005d08c9549910 llvm::install_out_of_memory_new_handler() /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/llvm/lib/Support/ErrorHandling.cpp:195:0
 #8 0x00005d08c74ef031 CC_MipsO32(unsigned int, llvm::MVT, llvm::MVT, llvm::CCValAssign::LocInfo, llvm::ISD::ArgFlagsTy, llvm::CCState&, llvm::ArrayRef<unsigned short>) /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/llvm/lib/Target/Mips/MipsISelLowering.cpp:3099:7
 #9 0x00005d08c74e3284 CC_MipsO32_FP /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/build/lib/Target/Mips/MipsGenCallingConv.inc:381:9
#10 0x00005d08c74e3284 CC_Mips_FixedArg(unsigned int, llvm::MVT, llvm::MVT, llvm::CCValAssign::LocInfo, llvm::ISD::ArgFlagsTy, llvm::CCState&) /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/build/lib/Target/Mips/MipsGenCallingConv.inc:581:10
#11 0x00005d08c8496026 llvm::CCState::AnalyzeFormalArguments(llvm::SmallVectorImpl<llvm::ISD::InputArg> const&, bool (*)(unsigned int, llvm::MVT, llvm::MVT, llvm::CCValAssign::LocInfo, llvm::ISD::ArgFlagsTy, llvm::CCState&)) /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/llvm/lib/CodeGen/CallingConvLower.cpp:92:9
#12 0x00005d08c74e9d80 getStackSize /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/llvm/include/llvm/CodeGen/CallingConvLower.h:245:42
#13 0x00005d08c74e9d80 llvm::MipsTargetLowering::LowerFormalArguments(llvm::SDValue, unsigned int, bool, llvm::SmallVectorImpl<llvm::ISD::InputArg> const&, llvm::SDLoc const&, llvm::SelectionDAG&, llvm::SmallVectorImpl<llvm::SDValue>&) const /var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h94vh-1/llvm-project/github-pull-requests/llvm/lib/Target/Mips/MipsISelLowering.cpp:3798:35

yes. let me check it

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Apr 17, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 17, 2025

@llvm/pr-subscribers-clang

Author: Mallikarjuna Gouda (mgoudar)

Changes

Enable 'FeatureMSA' for MIPS i6400 and i6500 cpu.

MIPS i6400 and i6500 cores implements MSA (MIPS SIMD ARCHITECTURE) by default.


Full diff: https://github.com/llvm/llvm-project/pull/134985.diff

2 Files Affected:

  • (added) clang/test/Driver/mips-cpus.c (+9)
  • (modified) llvm/lib/Target/Mips/Mips.td (+2-2)
diff --git a/clang/test/Driver/mips-cpus.c b/clang/test/Driver/mips-cpus.c
new file mode 100644
index 0000000000000..effb5ef60166a
--- /dev/null
+++ b/clang/test/Driver/mips-cpus.c
@@ -0,0 +1,9 @@
+// Check target CPUs are correctly passed.
+
+// RUN: %clang --target=mips64 -### -c %s 2>&1 -mcpu=i6400 -mmsa | FileCheck -check-prefix=MCPU-I6400 %s
+// MCPU-I6400: "-target-cpu" "i6400"
+// MCPU-I6400-SAME: "-target-feature" "+msa"
+
+// RUN: %clang --target=mips64 -### -c %s 2>&1 -mcpu=i6500 -mmsa | FileCheck -check-prefix=MCPU-I6500 %s
+// MCPU-I6500: "-target-cpu" "i6500"
+// MCPU-I6500-SAME: "-target-feature" "+msa"
diff --git a/llvm/lib/Target/Mips/Mips.td b/llvm/lib/Target/Mips/Mips.td
index 43a5ae8133d83..ca3df1fd94144 100644
--- a/llvm/lib/Target/Mips/Mips.td
+++ b/llvm/lib/Target/Mips/Mips.td
@@ -242,11 +242,11 @@ def ImplP5600 : SubtargetFeature<"p5600", "ProcImpl",
 // same CPU architecture.
 def ImplI6400
     : SubtargetFeature<"i6400", "ProcImpl", "MipsSubtarget::CPU::I6400",
-                       "MIPS I6400 Processor", [FeatureMips64r6]>;
+                       "MIPS I6400 Processor", [FeatureMips64r6, FeatureMSA]>;
 
 def ImplI6500
     : SubtargetFeature<"i6500", "ProcImpl", "MipsSubtarget::CPU::I6500",
-                       "MIPS I6500 Processor", [FeatureMips64r6]>;
+                       "MIPS I6500 Processor", [FeatureMips64r6, FeatureMSA]>;
 
 class Proc<string Name, list<SubtargetFeature> Features>
  : ProcessorModel<Name, MipsGenericModel, Features>;

@llvmbot
Copy link
Member

llvmbot commented Apr 17, 2025

@llvm/pr-subscribers-clang-driver

Author: Mallikarjuna Gouda (mgoudar)

Changes

Enable 'FeatureMSA' for MIPS i6400 and i6500 cpu.

MIPS i6400 and i6500 cores implements MSA (MIPS SIMD ARCHITECTURE) by default.


Full diff: https://github.com/llvm/llvm-project/pull/134985.diff

2 Files Affected:

  • (added) clang/test/Driver/mips-cpus.c (+9)
  • (modified) llvm/lib/Target/Mips/Mips.td (+2-2)
diff --git a/clang/test/Driver/mips-cpus.c b/clang/test/Driver/mips-cpus.c
new file mode 100644
index 0000000000000..effb5ef60166a
--- /dev/null
+++ b/clang/test/Driver/mips-cpus.c
@@ -0,0 +1,9 @@
+// Check target CPUs are correctly passed.
+
+// RUN: %clang --target=mips64 -### -c %s 2>&1 -mcpu=i6400 -mmsa | FileCheck -check-prefix=MCPU-I6400 %s
+// MCPU-I6400: "-target-cpu" "i6400"
+// MCPU-I6400-SAME: "-target-feature" "+msa"
+
+// RUN: %clang --target=mips64 -### -c %s 2>&1 -mcpu=i6500 -mmsa | FileCheck -check-prefix=MCPU-I6500 %s
+// MCPU-I6500: "-target-cpu" "i6500"
+// MCPU-I6500-SAME: "-target-feature" "+msa"
diff --git a/llvm/lib/Target/Mips/Mips.td b/llvm/lib/Target/Mips/Mips.td
index 43a5ae8133d83..ca3df1fd94144 100644
--- a/llvm/lib/Target/Mips/Mips.td
+++ b/llvm/lib/Target/Mips/Mips.td
@@ -242,11 +242,11 @@ def ImplP5600 : SubtargetFeature<"p5600", "ProcImpl",
 // same CPU architecture.
 def ImplI6400
     : SubtargetFeature<"i6400", "ProcImpl", "MipsSubtarget::CPU::I6400",
-                       "MIPS I6400 Processor", [FeatureMips64r6]>;
+                       "MIPS I6400 Processor", [FeatureMips64r6, FeatureMSA]>;
 
 def ImplI6500
     : SubtargetFeature<"i6500", "ProcImpl", "MipsSubtarget::CPU::I6500",
-                       "MIPS I6500 Processor", [FeatureMips64r6]>;
+                       "MIPS I6500 Processor", [FeatureMips64r6, FeatureMSA]>;
 
 class Proc<string Name, list<SubtargetFeature> Features>
  : ProcessorModel<Name, MipsGenericModel, Features>;

@mgoudar mgoudar requested a review from mshockwave April 17, 2025 14:12
// Check target CPUs are correctly passed.

// RUN: %clang --target=mips64 -### -c %s 2>&1 -mcpu=i6400 -mmsa | FileCheck -check-prefix=MCPU-I6400 %s
// MCPU-I6400: "-target-cpu" "i6400"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually we will check all the features implied by this CPU. Not sure if this is practical in your case though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified test to verify abicalls feature as well. I see that mips-features.c test available to verify other features based on the options

mgoudar added 4 commits April 23, 2025 01:40
MIPS cpus support MSA by default. So enable this feature
for cpus i6400 and i6500.

Also test msa feature in mips-cpus.c driver test case
… i6500""

This reverts commit dad1337.

keeping MSA enabled by default for cpu i6400 and i6500
@mgoudar mgoudar requested a review from mshockwave April 23, 2025 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants