-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[RISCV] Check the VT for R and cR inline asm constraints is 2*xlen. #137749
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-backend-risc-v Author: Craig Topper (topperc) ChangesFixes #137726. Full diff: https://github.com/llvm/llvm-project/pull/137749.diff 2 Files Affected:
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 722dcbbc6dd53..d205c25e73056 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -22532,7 +22532,10 @@ RISCVTargetLowering::getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
}
break;
case 'R':
- return std::make_pair(0U, &RISCV::GPRPairNoX0RegClass);
+ if (((VT == MVT::i64 || VT == MVT::f64) && !Subtarget.is64Bit()) ||
+ (VT == MVT::i128 && Subtarget.is64Bit()))
+ return std::make_pair(0U, &RISCV::GPRPairNoX0RegClass);
+ break;
default:
break;
}
@@ -22574,7 +22577,9 @@ RISCVTargetLowering::getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
if (!VT.isVector())
return std::make_pair(0U, &RISCV::GPRCRegClass);
} else if (Constraint == "cR") {
- return std::make_pair(0U, &RISCV::GPRPairCRegClass);
+ if (((VT == MVT::i64 || VT == MVT::f64) && !Subtarget.is64Bit()) ||
+ (VT == MVT::i128 && Subtarget.is64Bit()))
+ return std::make_pair(0U, &RISCV::GPRPairCRegClass);
} else if (Constraint == "cf") {
if (VT == MVT::f16) {
if (Subtarget.hasStdExtZfhmin())
diff --git a/llvm/test/CodeGen/RISCV/inline-asm-invalid.ll b/llvm/test/CodeGen/RISCV/inline-asm-invalid.ll
index deffa177c5e6b..8d90cd1d9c510 100644
--- a/llvm/test/CodeGen/RISCV/inline-asm-invalid.ll
+++ b/llvm/test/CodeGen/RISCV/inline-asm-invalid.ll
@@ -1,5 +1,5 @@
-; RUN: not llc -mtriple=riscv32 < %s 2>&1 | FileCheck %s
-; RUN: not llc -mtriple=riscv64 < %s 2>&1 | FileCheck %s
+; RUN: not llc -mtriple=riscv32 < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK32
+; RUN: not llc -mtriple=riscv64 < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK64
define void @constraint_I() {
; CHECK: error: value out of range for constraint 'I'
@@ -62,3 +62,51 @@ define void @constraint_cr_scalable_vec() nounwind {
tail call void asm "add a0, a0, $0", "^cr"(<vscale x 4 x i32> zeroinitializer)
ret void
}
+
+define void @constraint_R_i32() nounwind {
+; CHECK32: error: couldn't allocate input reg for constraint 'R'
+ tail call void asm "add a0, a0, $0", "R"(i32 zeroinitializer)
+ ret void
+}
+
+define void @constraint_R_i64() nounwind {
+; CHECK64: error: couldn't allocate input reg for constraint 'R'
+ tail call void asm "add a0, a0, $0", "R"(i64 zeroinitializer)
+ ret void
+}
+
+define void @constraint_R_i128() nounwind {
+; CHECK32: error: couldn't allocate input reg for constraint 'R'
+ tail call void asm "add a0, a0, $0", "R"(i128 zeroinitializer)
+ ret void
+}
+
+define void @constraint_R_i256() nounwind {
+; CHECK: error: couldn't allocate input reg for constraint 'R'
+ tail call void asm "add a0, a0, $0", "R"(i256 zeroinitializer)
+ ret void
+}
+
+define void @constraint_cR_i32() nounwind {
+; CHECK32: error: couldn't allocate input reg for constraint 'cR'
+ tail call void asm "add a0, a0, $0", "^cR"(i32 zeroinitializer)
+ ret void
+}
+
+define void @constraint_cR_i64() nounwind {
+; CHECK64: error: couldn't allocate input reg for constraint 'cR'
+ tail call void asm "add a0, a0, $0", "^cR"(i64 zeroinitializer)
+ ret void
+}
+
+define void @constraint_cR_i128() nounwind {
+; CHECK32: error: couldn't allocate input reg for constraint 'cR'
+ tail call void asm "add a0, a0, $0", "^cR"(i128 zeroinitializer)
+ ret void
+}
+
+define void @constraint_cR_i256() nounwind {
+; CHECK: error: couldn't allocate input reg for constraint 'cR'
+ tail call void asm "add a0, a0, $0", "^cR"(i256 zeroinitializer)
+ ret void
+}
|
wangpc-pp
approved these changes
Apr 29, 2025
lenary
approved these changes
Apr 29, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
GeorgeARM
pushed a commit
to GeorgeARM/llvm-project
that referenced
this pull request
May 7, 2025
Ankur-0429
pushed a commit
to Ankur-0429/llvm-project
that referenced
this pull request
May 9, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #137726.