-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LoongArch] Relax the restrictions of inlineasm operand modifier 'u' and 'w' #129864
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-llvm-ir @llvm/pr-subscribers-backend-loongarch Author: Lu Weining (SixWeining) Changes
Fixes #129863. Full diff: https://github.com/llvm/llvm-project/pull/129864.diff 2 Files Affected:
diff --git a/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp b/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
index 169f9568e5362..895a8e2646692 100644
--- a/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
@@ -90,20 +90,29 @@ bool LoongArchAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
return false;
}
break;
- case 'w': // Print LSX registers.
- if (MO.getReg().id() >= LoongArch::VR0 &&
- MO.getReg().id() <= LoongArch::VR31)
- break;
- // The modifier is 'w' but the operand is not an LSX register; Report an
- // unknown operand error.
- return true;
case 'u': // Print LASX registers.
- if (MO.getReg().id() >= LoongArch::XR0 &&
- MO.getReg().id() <= LoongArch::XR31)
- break;
- // The modifier is 'u' but the operand is not an LASX register; Report an
- // unknown operand error.
- return true;
+ case 'w': // Print LSX registers.
+ {
+ // If the operand is an LASX, LSX or floating point register, print the
+ // name of LASX or LSX register with the same index in that register
+ // class.
+ unsigned RegID = MO.getReg().id(), FirstReg;
+ if (RegID >= LoongArch::XR0 && RegID <= LoongArch::XR31)
+ FirstReg = LoongArch::XR0;
+ else if (RegID >= LoongArch::VR0 && RegID <= LoongArch::VR31)
+ FirstReg = LoongArch::VR0;
+ else if (RegID >= LoongArch::F0_64 && RegID <= LoongArch::F31_64)
+ FirstReg = LoongArch::F0_64;
+ else if (RegID >= LoongArch::F0 && RegID <= LoongArch::F31)
+ FirstReg = LoongArch::F0;
+ else
+ return true;
+ OS << '$'
+ << LoongArchInstPrinter::getRegisterName(
+ RegID - FirstReg +
+ (ExtraCode[0] == 'u' ? LoongArch::XR0 : LoongArch::VR0));
+ return false;
+ }
// TODO: handle other extra codes if any.
}
}
diff --git a/llvm/test/CodeGen/LoongArch/lasx/inline-asm-operand-modifier.ll b/llvm/test/CodeGen/LoongArch/lasx/inline-asm-operand-modifier.ll
index 201e34c8b5ae0..8b25a6525381b 100644
--- a/llvm/test/CodeGen/LoongArch/lasx/inline-asm-operand-modifier.ll
+++ b/llvm/test/CodeGen/LoongArch/lasx/inline-asm-operand-modifier.ll
@@ -12,3 +12,43 @@ entry:
%0 = tail call <4 x i64> asm sideeffect "xvldi ${0:u}, 1", "=f"()
ret void
}
+
+define void @test_u_2xi64() nounwind {
+; CHECK-LABEL: test_u_2xi64:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: #APP
+; CHECK-NEXT: xvldi $xr0, 1
+; CHECK-NEXT: #NO_APP
+; CHECK-NEXT: ret
+entry:
+ %0 = tail call <2 x i64> asm sideeffect "xvldi ${0:u}, 1", "=f"()
+ ret void
+}
+
+define void @test_w_4xi64() nounwind {
+; CHECK-LABEL: test_w_4xi64:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: #APP
+; CHECK-NEXT: vldi $vr0, 1
+; CHECK-NEXT: #NO_APP
+; CHECK-NEXT: ret
+entry:
+ %0 = tail call <4 x i64> asm sideeffect "vldi ${0:w}, 1", "=f"()
+ ret void
+}
+
+define void @m128i_to_m256i(ptr %out, ptr %in) nounwind {
+; CHECK-LABEL: m128i_to_m256i:
+; CHECK: # %bb.0:
+; CHECK-NEXT: vld $vr0, $a1, 0
+; CHECK-NEXT: xvrepli.b $xr1, 0
+; CHECK-NEXT: #APP
+; CHECK-NEXT: xvpermi.q $xr1, $xr0, 32
+; CHECK-NEXT: #NO_APP
+; CHECK-NEXT: xvst $xr1, $a0, 0
+; CHECK-NEXT: ret
+ %v = load <2 x i64>, ptr %in
+ %x = call <4 x i64> asm sideeffect "xvpermi.q ${0:u}, ${1:u}, 32", "=f,f,0"(<2 x i64> %v, <4 x i64> zeroinitializer)
+ store <4 x i64> %x, ptr %out
+ ret void
+}
|
…and 'w' - Allow 'u' and 'w' on LASX, LSX or floating point register operands. - Also add missing description in LangRef. Fixes llvm#129863.
90e4a50
to
32d170a
Compare
heiher
approved these changes
Mar 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
/cherry-pick bae6644 |
/pull-request #130009 |
swift-ci
pushed a commit
to swiftlang/llvm-project
that referenced
this pull request
Mar 12, 2025
…and 'w' (llvm#129864) - Allow 'u' and 'w' on LASX, LSX or floating point register operands. - Also add missing description in LangRef. Fixes llvm#129863. (cherry picked from commit bae6644)
jph-13
pushed a commit
to jph-13/llvm-project
that referenced
this pull request
Mar 21, 2025
…and 'w' (llvm#129864) - Allow 'u' and 'w' on LASX, LSX or floating point register operands. - Also add missing description in LangRef. Fixes llvm#129863.
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 #129863.