Skip to content

[LoongArch] Support i128 operands for LSX inline assembly - #211464

Merged
heiher merged 1 commit into
mainfrom
users/hev/inline-asm-lsx-i128
Jul 24, 2026
Merged

heiher merged 1 commit into
mainfrom
users/hev/inline-asm-lsx-i128

Conversation

@heiher

@heiher heiher commented Jul 23, 2026

Copy link
Copy Markdown
Member

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.

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.
@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-backend-loongarch

Author: hev (heiher)

Changes

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.


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

3 Files Affected:

  • (added) clang/test/CodeGen/LoongArch/lsx/inline-asm-operand-types.c (+15)
  • (modified) llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp (+2)
  • (added) llvm/test/CodeGen/LoongArch/lsx/inline-asm-operand-types.ll (+21)
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
+}

@heiher
heiher requested a review from wangleiat July 23, 2026 09:04

@wangleiat wangleiat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@heiher
heiher merged commit cad3c95 into main Jul 24, 2026
14 checks passed
@heiher
heiher deleted the users/hev/inline-asm-lsx-i128 branch July 24, 2026 02:23
@llvm-ci

llvm-ci commented Jul 24, 2026

Copy link
Copy Markdown

LLVM Buildbot has detected a new failure on builder llvm-clang-ubuntu-x-aarch64-pac-ret running on as-builder-11 while building clang,llvm at step 12 "build-default-test-suite".

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
Step 12 (build-default-test-suite) failure: cmake (failure)
...
1.743 [5636/130/502] Building C object SingleSource/Regression/C/CMakeFiles/Regression-C-2003-05-14-initialize-string.dir/2003-05-14-initialize-string.c.o
1.747 [5635/130/503] Building C object SingleSource/Regression/C/CMakeFiles/Regression-C-2003-05-21-BitfieldHandling.dir/2003-05-21-BitfieldHandling.c.o
1.750 [5634/130/504] Building C object SingleSource/UnitTests/HashRecognize/CMakeFiles/no-hr-crc8.be.data16.dir/crc8.be.data16.c.o
1.751 [5633/130/505] Building C object SingleSource/UnitTests/HashRecognize/CMakeFiles/no-hr-crc8.le.data16.dir/crc8.le.data16.c.o
1.754 [5632/130/506] Building C object SingleSource/UnitTests/HashRecognize/CMakeFiles/no-hr-crc32.le.dir/crc32.le.c.o
1.756 [5631/130/507] Building C object SingleSource/UnitTests/HashRecognize/CMakeFiles/no-hr-crc8.le.dir/crc8.le.c.o
1.798 [5630/130/508] Linking C executable SingleSource/UnitTests/HashRecognize/no-hr-crc16.be.nodata
1.804 [5629/130/509] Linking C executable SingleSource/UnitTests/HashRecognize/no-hr-crc16.be.data8
1.805 [5628/130/510] Linking C executable SingleSource/UnitTests/HashRecognize/crc16.be
1.816 [5627/130/511] Linking C executable SingleSource/UnitTests/HashRecognize/no-hr-crc16.le.data8
FAILED: SingleSource/UnitTests/HashRecognize/no-hr-crc16.le.data8 
: && /home/buildbot/worker/x-aarch64-pac-ret/build/llvm-test-suite/tools/timeit --summary SingleSource/UnitTests/HashRecognize/no-hr-crc16.le.data8.link.time /home/buildbot/worker/x-aarch64-pac-ret/build/bin/clang -march=armv8l+pauth -mbranch-protection=pac-ret -O2    -O3 -DNDEBUG -march=armv8l+pauth -O2 -Wl,--emit-relocs       -Xlinker --dependency-file=SingleSource/UnitTests/HashRecognize/CMakeFiles/no-hr-crc16.le.data8.dir/link.d SingleSource/UnitTests/HashRecognize/CMakeFiles/no-hr-crc16.le.data8.dir/crc16.le.data8.c.o -o SingleSource/UnitTests/HashRecognize/no-hr-crc16.le.data8   && cd /home/buildbot/worker/x-aarch64-pac-ret/build/llvm-test-suite/SingleSource/UnitTests/HashRecognize && /usr/bin/cmake -E copy /home/buildbot/worker/x-aarch64-pac-ret/llvm-test-suite/SingleSource/UnitTests/HashRecognize/crc16.le.data8.reference_output /home/buildbot/worker/x-aarch64-pac-ret/build/llvm-test-suite/SingleSource/UnitTests/HashRecognize/crc16.le.data8.reference_output
Error copying file "/home/buildbot/worker/x-aarch64-pac-ret/llvm-test-suite/SingleSource/UnitTests/HashRecognize/crc16.le.data8.reference_output" to "/home/buildbot/worker/x-aarch64-pac-ret/build/llvm-test-suite/SingleSource/UnitTests/HashRecognize/crc16.le.data8.reference_output".
1.817 [5627/129/512] Linking C executable SingleSource/UnitTests/HashRecognize/crc16.le.data8
1.817 [5627/128/513] Linking C executable SingleSource/UnitTests/HashRecognize/crc16.le.nodata
1.823 [5627/127/514] Linking C executable SingleSource/UnitTests/HashRecognize/crc16.be.nodata
1.825 [5627/126/515] Linking C executable SingleSource/UnitTests/HashRecognize/crc16.be.data32
1.841 [5627/125/516] Building CXX object SingleSource/Benchmarks/Shootout-C++/CMakeFiles/Shootout-C++-ackermann.dir/ackermann.cpp.o
1.843 [5627/124/517] Linking C executable SingleSource/UnitTests/HashRecognize/no-hr-crc16.be
1.849 [5627/123/518] Linking C executable SingleSource/Benchmarks/Linpack/linpack-pc
1.850 [5627/122/519] Linking C executable SingleSource/UnitTests/HashRecognize/crc8.be
1.850 [5627/121/520] Linking C executable SingleSource/UnitTests/HashRecognize/crc16.le
1.853 [5627/120/521] Linking C executable SingleSource/UnitTests/HashRecognize/no-hr-crc16.le.nodata
1.854 [5627/119/522] Linking C executable SingleSource/UnitTests/HashRecognize/crc8.be.data16
1.855 [5627/118/523] Linking C executable SingleSource/UnitTests/HashRecognize/crc32.be
1.855 [5627/117/524] Linking C executable SingleSource/UnitTests/HashRecognize/crc32.le
1.861 [5627/116/525] Linking C executable SingleSource/UnitTests/HashRecognize/no-hr-crc16.le.data32
1.863 [5627/115/526] Linking C executable SingleSource/UnitTests/HashRecognize/crc8.le.data16
1.863 [5627/114/527] Linking C executable SingleSource/UnitTests/HashRecognize/crc16.be.data8
1.864 [5627/113/528] Linking C executable SingleSource/UnitTests/HashRecognize/no-hr-crc32.be
1.865 [5627/112/529] Linking C executable SingleSource/UnitTests/HashRecognize/no-hr-crc16.le
1.868 [5627/111/530] Building C object SingleSource/Regression/C/CMakeFiles/Regression-C-2003-05-21-UnionBitfields.dir/2003-05-21-UnionBitfields.c.o
1.870 [5627/110/531] Building C object SingleSource/Regression/C/CMakeFiles/Regression-C-2003-05-21-UnionTest.dir/2003-05-21-UnionTest.c.o
1.872 [5627/109/532] Building C object SingleSource/Regression/C/CMakeFiles/Regression-C-2003-05-22-LocalTypeTest.dir/2003-05-22-LocalTypeTest.c.o
1.873 [5627/108/533] Linking C executable SingleSource/UnitTests/Vector/NEON/Vector-NEON-simple
1.878 [5627/107/534] Linking C executable SingleSource/UnitTests/HashRecognize/crc16.le.data32
1.881 [5627/106/535] Linking C executable SingleSource/UnitTests/HashRecognize/no-hr-crc16.be.data32
1.881 [5627/105/536] Building C object SingleSource/Regression/C/CMakeFiles/Regression-C-2003-06-16-InvalidInitializer.dir/2003-06-16-InvalidInitializer.c.o
1.883 [5627/104/537] Linking C executable SingleSource/UnitTests/HashRecognize/crc8.le
1.884 [5627/103/538] Linking C executable SingleSource/UnitTests/HashRecognize/no-hr-crc8.be
1.888 [5627/102/539] Building CXX object SingleSource/Benchmarks/Shootout-C++/CMakeFiles/Shootout-C++-lists1.dir/lists1.cpp.o
1.889 [5627/101/540] Linking C executable SingleSource/Regression/C/Regression-C-2003-05-21-BitfieldHandling
1.889 [5627/100/541] Building C object SingleSource/Regression/C/CMakeFiles/Regression-C-2003-05-22-VarSizeArray.dir/2003-05-22-VarSizeArray.c.o
1.890 [5627/99/542] Building CXX object SingleSource/UnitTests/C++11/CMakeFiles/stdthreadbug.dir/stdthreadbug.cpp.o
1.890 [5627/98/543] Linking C executable SingleSource/Regression/C/Regression-C-2003-05-14-initialize-string
1.891 [5627/97/544] Linking C executable SingleSource/UnitTests/HashRecognize/no-hr-crc8.be.data16
1.891 [5627/96/545] Linking C executable SingleSource/UnitTests/HashRecognize/no-hr-crc8.le
1.892 [5627/95/546] Building CXX object SingleSource/Benchmarks/Shootout-C++/CMakeFiles/Shootout-C++-nestedloop.dir/nestedloop.cpp.o
1.892 [5627/94/547] Linking CXX executable SingleSource/Benchmarks/Shootout-C++/EH/Shootout-C++-except

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants