Repository navigation
[LoongArch] Support i128 operands for LSX inline assembly - #211464
Merged
Merged
Conversation
Allow `i128` values to be used with the `f` inline assembly constraint when targeting LSX. Although `i128` is not a legal LSX value type, it naturally maps to a single 128-bit LSX vector register for inline assembly. This enables instructions such as `vadd.q` to operate directly on `__int128` operands without requiring explicit vector types.
|
@llvm/pr-subscribers-backend-loongarch Author: hev (heiher) ChangesAllow Although 3 Files Affected:
diff --git a/clang/test/CodeGen/LoongArch/lsx/inline-asm-operand-types.c b/clang/test/CodeGen/LoongArch/lsx/inline-asm-operand-types.c
new file mode 100644
index 0000000000000..6fdf1a8eac255
--- /dev/null
+++ b/clang/test/CodeGen/LoongArch/lsx/inline-asm-operand-types.c
@@ -0,0 +1,15 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
+// RUN: %clang_cc1 -triple loongarch64 -emit-llvm -O2 %s -o - | FileCheck %s
+
+// CHECK-LABEL: define dso_local void @test_i128
+// CHECK-SAME: (ptr nofree noundef readonly captures(none) [[A:%.*]], ptr nofree noundef readonly captures(none) [[B:%.*]], ptr nofree noundef writeonly captures(none) initializes((0, 16)) [[R:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[TMP0:%.*]] = load i128, ptr [[A]], align 16, !tbaa [[TBAA6:![0-9]+]]
+// CHECK-NEXT: [[TMP1:%.*]] = load i128, ptr [[B]], align 16, !tbaa [[TBAA6]]
+// CHECK-NEXT: [[TMP2:%.*]] = tail call i128 asm sideeffect "vadd.q ${0:w}, ${1:w}, ${2:w}", "=f,f,f"(i128 [[TMP0]], i128 [[TMP1]]) #[[ATTR1:[0-9]+]], !srcloc [[META8:![0-9]+]]
+// CHECK-NEXT: store i128 [[TMP2]], ptr [[R]], align 16, !tbaa [[TBAA6]]
+// CHECK-NEXT: ret void
+//
+void test_i128(__int128 *a, __int128 *b, __int128 *r) {
+ asm volatile ("vadd.q %w0, %w1, %w2" : "=f" (*r) : "f" (*a), "f" (*b));
+}
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
index 4c5bb28a5e42f..409e23f292c93 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -11332,6 +11332,8 @@ LoongArchTargetLowering::getRegForInlineAsmConstraint(
if (Subtarget.hasExtLSX() &&
TRI->isTypeLegalForClass(LoongArch::LSX128RegClass, VT))
return std::make_pair(0U, &LoongArch::LSX128RegClass);
+ if (Subtarget.hasExtLSX() && VT == MVT::i128)
+ return std::make_pair(0U, &LoongArch::LSX128RegClass);
if (Subtarget.hasExtLASX() &&
TRI->isTypeLegalForClass(LoongArch::LASX256RegClass, VT))
return std::make_pair(0U, &LoongArch::LASX256RegClass);
diff --git a/llvm/test/CodeGen/LoongArch/lsx/inline-asm-operand-types.ll b/llvm/test/CodeGen/LoongArch/lsx/inline-asm-operand-types.ll
new file mode 100644
index 0000000000000..77081f0aaad7c
--- /dev/null
+++ b/llvm/test/CodeGen/LoongArch/lsx/inline-asm-operand-types.ll
@@ -0,0 +1,21 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
+; RUN: llc --mtriple=loongarch32 -mattr=+32s,+lsx < %s | FileCheck %s
+; RUN: llc --mtriple=loongarch64 -mattr=+lsx < %s | FileCheck %s
+
+define void @i128(ptr %a, ptr %b, ptr %r) nounwind {
+; CHECK-LABEL: i128:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: vld $vr0, $a1, 0
+; CHECK-NEXT: vld $vr1, $a0, 0
+; CHECK-NEXT: #APP
+; CHECK-NEXT: vadd.q $vr2, $vr1, $vr0
+; CHECK-NEXT: #NO_APP
+; CHECK-NEXT: vst $vr2, $a2, 0
+; CHECK-NEXT: ret
+entry:
+ %0 = load i128, ptr %a, align 16
+ %1 = load i128, ptr %b, align 16
+ %2 = tail call i128 asm sideeffect "vadd.q ${0:w}, ${1:w}, ${2:w}", "=&f,f,f"(i128 %0, i128 %1)
+ store i128 %2, ptr %r, align 16
+ ret void
+}
|
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/229/builds/3337 Here is the relevant piece of the build log for the reference |
tru
pushed a commit
to llvmbot/llvm-project
that referenced
this pull request
Jul 24, 2026
Allow `i128` values to be used with the `f` inline assembly constraint when targeting LSX. Although `i128` is not a legal LSX value type, it naturally maps to a single 128-bit LSX vector register for inline assembly. This enables instructions such as `vadd.q` to operate directly on `__int128` operands without requiring explicit vector types. (cherry picked from commit cad3c95)
midhuncodes7
pushed a commit
to midhuncodes7/llvm-project
that referenced
this pull request
Jul 28, 2026
Allow `i128` values to be used with the `f` inline assembly constraint when targeting LSX. Although `i128` is not a legal LSX value type, it naturally maps to a single 128-bit LSX vector register for inline assembly. This enables instructions such as `vadd.q` to operate directly on `__int128` operands without requiring explicit vector types.
asudarsa-qti
pushed a commit
to asudarsa-qti/llvm-project
that referenced
this pull request
Jul 29, 2026
Allow `i128` values to be used with the `f` inline assembly constraint when targeting LSX. Although `i128` is not a legal LSX value type, it naturally maps to a single 128-bit LSX vector register for inline assembly. This enables instructions such as `vadd.q` to operate directly on `__int128` operands without requiring explicit vector types.
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Aug 28, 2026
loongarch: support passing `u128`/`i128` to inline assembly Tracking issue: rust-lang#133416 LLVM support: llvm/llvm-project#211464 cc @taiki-e
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Aug 28, 2026
loongarch: support passing `u128`/`i128` to inline assembly Tracking issue: rust-lang#133416 LLVM support: llvm/llvm-project#211464 cc @taiki-e
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Aug 28, 2026
loongarch: support passing `u128`/`i128` to inline assembly Tracking issue: rust-lang#133416 LLVM support: llvm/llvm-project#211464 cc @taiki-e
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Aug 28, 2026
loongarch: support passing `u128`/`i128` to inline assembly Tracking issue: rust-lang#133416 LLVM support: llvm/llvm-project#211464 cc @taiki-e
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Aug 28, 2026
loongarch: support passing `u128`/`i128` to inline assembly Tracking issue: rust-lang#133416 LLVM support: llvm/llvm-project#211464 cc @taiki-e
Zalathar
added a commit
to Zalathar/rust
that referenced
this pull request
Aug 29, 2026
loongarch: support passing `u128`/`i128` to inline assembly Tracking issue: rust-lang#133416 LLVM support: llvm/llvm-project#211464 cc @taiki-e
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Aug 29, 2026
loongarch: support passing `u128`/`i128` to inline assembly Tracking issue: rust-lang#133416 LLVM support: llvm/llvm-project#211464 cc @taiki-e
rust-bors Bot
pushed a commit
to rust-lang/rust
that referenced
this pull request
Aug 29, 2026
Rollup merge of #161865 - heiher:inline-asm-i128, r=folkertdev loongarch: support passing `u128`/`i128` to inline assembly Tracking issue: #133416 LLVM support: llvm/llvm-project#211464 cc @taiki-e
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
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.
Allow
i128values to be used with thefinline assembly constraint when targeting LSX.Although
i128is not a legal LSX value type, it naturally maps to a single 128-bit LSX vector register for inline assembly. This enables instructions such asvadd.qto operate directly on__int128operands without requiring explicit vector types.