-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[LoongArch] Fix incorrect logic in isLegalAddressingMode() #88694
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: wanglei (wangleiat) ChangesThis will adress issue: Full diff: https://github.com/llvm/llvm-project/pull/88694.diff 2 Files Affected:
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
index c13b10a320f836..285d5c2a63b2da 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -4876,20 +4876,19 @@ bool LoongArchTargetLowering::isLegalAddressingMode(const DataLayout &DL,
if (AM.BaseGV)
return false;
- // Require a 12 or 14 bit signed offset.
- if (!isInt<12>(AM.BaseOffs) || !isShiftedInt<14, 2>(AM.BaseOffs))
+ // Require a 12-bit signed offset or 14-bit signed offset left-shifted by 2
+ // with `UAL` feature.
+ if (!isInt<12>(AM.BaseOffs) &&
+ !(isShiftedInt<14, 2>(AM.BaseOffs) && Subtarget.hasUAL()))
return false;
switch (AM.Scale) {
case 0:
- // "i" is not allowed.
- if (!AM.HasBaseReg)
- return false;
- // Otherwise we have "r+i".
+ // "r+i" or just "i", depending on HasBaseReg.
break;
case 1:
// "r+r+i" is not allowed.
- if (AM.HasBaseReg && AM.BaseOffs != 0)
+ if (AM.HasBaseReg && AM.BaseOffs)
return false;
// Otherwise we have "r+r" or "r+i".
break;
@@ -4897,7 +4896,7 @@ bool LoongArchTargetLowering::isLegalAddressingMode(const DataLayout &DL,
// "2*r+r" or "2*r+i" is not allowed.
if (AM.HasBaseReg || AM.BaseOffs)
return false;
- // Otherwise we have "r+r".
+ // Allow "2*r" as "r+r".
break;
default:
return false;
diff --git a/llvm/test/CodeGen/LoongArch/gep-imm.ll b/llvm/test/CodeGen/LoongArch/gep-imm.ll
new file mode 100644
index 00000000000000..0eef7e4517f3d8
--- /dev/null
+++ b/llvm/test/CodeGen/LoongArch/gep-imm.ll
@@ -0,0 +1,48 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
+; RUN: llc --mtriple=loongarch64 < %s | FileCheck %s
+
+define void @test(ptr %sp, ptr %t, i32 %n) {
+; CHECK-LABEL: test:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: ld.d $a0, $a0, 0
+; CHECK-NEXT: move $a3, $zero
+; CHECK-NEXT: addi.w $a2, $a2, 0
+; CHECK-NEXT: addi.w $a4, $a3, 0
+; CHECK-NEXT: bge $a4, $a2, .LBB0_2
+; CHECK-NEXT: .p2align 4, , 16
+; CHECK-NEXT: .LBB0_1: # %while_body
+; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
+; CHECK-NEXT: addi.d $a4, $a3, 1
+; CHECK-NEXT: stptr.w $a4, $a0, 8000
+; CHECK-NEXT: stptr.w $a3, $a0, 8004
+; CHECK-NEXT: stptr.w $a4, $a1, 8000
+; CHECK-NEXT: stptr.w $a3, $a1, 8004
+; CHECK-NEXT: move $a3, $a4
+; CHECK-NEXT: addi.w $a4, $a3, 0
+; CHECK-NEXT: blt $a4, $a2, .LBB0_1
+; CHECK-NEXT: .LBB0_2: # %while_end
+; CHECK-NEXT: ret
+entry:
+ %s = load ptr, ptr %sp
+ br label %while_cond
+
+while_cond:
+ %phi = phi i32 [ 0, %entry ], [ %i, %while_body ]
+ %gep0 = getelementptr [65536 x i32], ptr %s, i64 0, i64 2000
+ %gep1 = getelementptr [65536 x i32], ptr %s, i64 0, i64 2001
+ %gep2 = getelementptr [65536 x i32], ptr %t, i64 0, i64 2000
+ %gep3 = getelementptr [65536 x i32], ptr %t, i64 0, i64 2001
+ %cmp = icmp slt i32 %phi, %n
+ br i1 %cmp, label %while_body, label %while_end
+
+while_body:
+ %i = add i32 %phi, 1
+ store i32 %i, ptr %gep0
+ store i32 %phi, ptr %gep1
+ store i32 %i, ptr %gep2
+ store i32 %phi, ptr %gep3
+ br label %while_cond
+
+while_end:
+ ret void
+}
|
wangleiat
added a commit
that referenced
this pull request
Apr 15, 2024
This will adress issue: ClangBuiltLinux/linux#2014
SixWeining
approved these changes
Apr 15, 2024
heiher
approved these changes
Apr 15, 2024
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.
Thanks.
bazuzi
pushed a commit
to bazuzi/llvm-project
that referenced
this pull request
Apr 15, 2024
bazuzi
pushed a commit
to bazuzi/llvm-project
that referenced
this pull request
Apr 15, 2024
This will adress issue: ClangBuiltLinux/linux#2014
aniplcc
pushed a commit
to aniplcc/llvm-project
that referenced
this pull request
Apr 15, 2024
aniplcc
pushed a commit
to aniplcc/llvm-project
that referenced
this pull request
Apr 15, 2024
This will adress issue: ClangBuiltLinux/linux#2014
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.
This will adress issue:
ClangBuiltLinux/linux#2014