-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LoongArch] Precommit a test for smul with overflow (NFC) #73212
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-loongarch Author: hev (heiher) ChangesFull diff: https://github.com/llvm/llvm-project/pull/73212.diff 1 Files Affected:
diff --git a/llvm/test/CodeGen/LoongArch/smul-with-overflow.ll b/llvm/test/CodeGen/LoongArch/smul-with-overflow.ll
new file mode 100644
index 000000000000000..4a12c575b4b5d0d
--- /dev/null
+++ b/llvm/test/CodeGen/LoongArch/smul-with-overflow.ll
@@ -0,0 +1,118 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=loongarch32 < %s | FileCheck %s --check-prefix=LA32
+; RUN: llc -mtriple=loongarch64 < %s | FileCheck %s --check-prefix=LA64
+
+define zeroext i1 @smuloi64(i64 %v1, i64 %v2, ptr %res) {
+; LA32-LABEL: smuloi64:
+; LA32: # %bb.0:
+; LA32-NEXT: addi.w $sp, $sp, -16
+; LA32-NEXT: .cfi_def_cfa_offset 16
+; LA32-NEXT: st.w $ra, $sp, 12 # 4-byte Folded Spill
+; LA32-NEXT: st.w $fp, $sp, 8 # 4-byte Folded Spill
+; LA32-NEXT: .cfi_offset 1, -4
+; LA32-NEXT: .cfi_offset 22, -8
+; LA32-NEXT: move $fp, $a4
+; LA32-NEXT: st.w $zero, $sp, 4
+; LA32-NEXT: addi.w $a4, $sp, 4
+; LA32-NEXT: bl %plt(__mulodi4)
+; LA32-NEXT: st.w $a1, $fp, 4
+; LA32-NEXT: st.w $a0, $fp, 0
+; LA32-NEXT: ld.w $a0, $sp, 4
+; LA32-NEXT: sltu $a0, $zero, $a0
+; LA32-NEXT: ld.w $fp, $sp, 8 # 4-byte Folded Reload
+; LA32-NEXT: ld.w $ra, $sp, 12 # 4-byte Folded Reload
+; LA32-NEXT: addi.w $sp, $sp, 16
+; LA32-NEXT: ret
+;
+; LA64-LABEL: smuloi64:
+; LA64: # %bb.0:
+; LA64-NEXT: mul.d $a3, $a0, $a1
+; LA64-NEXT: st.d $a3, $a2, 0
+; LA64-NEXT: mulh.d $a0, $a0, $a1
+; LA64-NEXT: srai.d $a1, $a3, 63
+; LA64-NEXT: xor $a0, $a0, $a1
+; LA64-NEXT: sltu $a0, $zero, $a0
+; LA64-NEXT: ret
+ %t = call {i64, i1} @llvm.smul.with.overflow.i64(i64 %v1, i64 %v2)
+ %val = extractvalue {i64, i1} %t, 0
+ %obit = extractvalue {i64, i1} %t, 1
+ store i64 %val, ptr %res
+ ret i1 %obit
+}
+
+define zeroext i1 @smuloi128(i128 %v1, i128 %v2, ptr %res) {
+; LA32-LABEL: smuloi128:
+; LA32: # %bb.0:
+; LA32-NEXT: addi.w $sp, $sp, -64
+; LA32-NEXT: .cfi_def_cfa_offset 64
+; LA32-NEXT: st.w $ra, $sp, 60 # 4-byte Folded Spill
+; LA32-NEXT: st.w $fp, $sp, 56 # 4-byte Folded Spill
+; LA32-NEXT: .cfi_offset 1, -4
+; LA32-NEXT: .cfi_offset 22, -8
+; LA32-NEXT: move $fp, $a2
+; LA32-NEXT: st.w $zero, $sp, 52
+; LA32-NEXT: ld.w $a2, $a1, 12
+; LA32-NEXT: st.w $a2, $sp, 12
+; LA32-NEXT: ld.w $a2, $a1, 8
+; LA32-NEXT: st.w $a2, $sp, 8
+; LA32-NEXT: ld.w $a2, $a1, 4
+; LA32-NEXT: st.w $a2, $sp, 4
+; LA32-NEXT: ld.w $a1, $a1, 0
+; LA32-NEXT: st.w $a1, $sp, 0
+; LA32-NEXT: ld.w $a1, $a0, 12
+; LA32-NEXT: st.w $a1, $sp, 28
+; LA32-NEXT: ld.w $a1, $a0, 8
+; LA32-NEXT: st.w $a1, $sp, 24
+; LA32-NEXT: ld.w $a1, $a0, 4
+; LA32-NEXT: st.w $a1, $sp, 20
+; LA32-NEXT: ld.w $a0, $a0, 0
+; LA32-NEXT: st.w $a0, $sp, 16
+; LA32-NEXT: addi.w $a0, $sp, 32
+; LA32-NEXT: addi.w $a1, $sp, 16
+; LA32-NEXT: addi.w $a2, $sp, 0
+; LA32-NEXT: addi.w $a3, $sp, 52
+; LA32-NEXT: bl %plt(__muloti4)
+; LA32-NEXT: ld.w $a0, $sp, 44
+; LA32-NEXT: st.w $a0, $fp, 12
+; LA32-NEXT: ld.w $a0, $sp, 40
+; LA32-NEXT: st.w $a0, $fp, 8
+; LA32-NEXT: ld.w $a0, $sp, 36
+; LA32-NEXT: st.w $a0, $fp, 4
+; LA32-NEXT: ld.w $a0, $sp, 32
+; LA32-NEXT: st.w $a0, $fp, 0
+; LA32-NEXT: ld.w $a0, $sp, 52
+; LA32-NEXT: sltu $a0, $zero, $a0
+; LA32-NEXT: ld.w $fp, $sp, 56 # 4-byte Folded Reload
+; LA32-NEXT: ld.w $ra, $sp, 60 # 4-byte Folded Reload
+; LA32-NEXT: addi.w $sp, $sp, 64
+; LA32-NEXT: ret
+;
+; LA64-LABEL: smuloi128:
+; LA64: # %bb.0:
+; LA64-NEXT: addi.d $sp, $sp, -32
+; LA64-NEXT: .cfi_def_cfa_offset 32
+; LA64-NEXT: st.d $ra, $sp, 24 # 8-byte Folded Spill
+; LA64-NEXT: st.d $fp, $sp, 16 # 8-byte Folded Spill
+; LA64-NEXT: .cfi_offset 1, -8
+; LA64-NEXT: .cfi_offset 22, -16
+; LA64-NEXT: move $fp, $a4
+; LA64-NEXT: st.d $zero, $sp, 8
+; LA64-NEXT: addi.d $a4, $sp, 8
+; LA64-NEXT: bl %plt(__muloti4)
+; LA64-NEXT: st.d $a1, $fp, 8
+; LA64-NEXT: st.d $a0, $fp, 0
+; LA64-NEXT: ld.d $a0, $sp, 8
+; LA64-NEXT: sltu $a0, $zero, $a0
+; LA64-NEXT: ld.d $fp, $sp, 16 # 8-byte Folded Reload
+; LA64-NEXT: ld.d $ra, $sp, 24 # 8-byte Folded Reload
+; LA64-NEXT: addi.d $sp, $sp, 32
+; LA64-NEXT: ret
+ %t = call {i128, i1} @llvm.smul.with.overflow.i128(i128 %v1, i128 %v2)
+ %val = extractvalue {i128, i1} %t, 0
+ %obit = extractvalue {i128, i1} %t, 1
+ store i128 %val, ptr %res
+ ret i1 %obit
+}
+
+declare {i64, i1} @llvm.smul.with.overflow.i64(i64, i64) nounwind readnone
+declare {i128, i1} @llvm.smul.with.overflow.i128(i128, i128) nounwind readnone
|
SixWeining
approved these changes
Nov 23, 2023
leecheechen
pushed a commit
to leecheechen/llvm-project
that referenced
this pull request
Jun 9, 2025
(cherry picked from commit 7414c0d) Change-Id: I20a719b4732893b9ef268e0b643fdecab7f1712d
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.
No description provided.