Skip to content

Commit dcbf6de

Browse files
committed
[LoongArch] Return true from shouldConsiderGEPOffsetSplit
If not performing gep splits can prevent important optimizations, such as preventing the element indices / member offsets from being (partially) folded into load/store instruction immediates.
1 parent 759422c commit dcbf6de

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

llvm/lib/Target/LoongArch/LoongArchISelLowering.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ class LoongArchTargetLowering : public TargetLowering {
238238
bool isShuffleMaskLegal(ArrayRef<int> Mask, EVT VT) const override {
239239
return false;
240240
}
241+
bool shouldConsiderGEPOffsetSplit() const override { return true; }
241242

242243
private:
243244
/// Target-specific function used to lower LoongArch calling conventions.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if not "LoongArch" in config.root.targets:
2+
config.unsupported = True
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
; RUN: opt --mtriple=loongarch64 -S --passes='require<profile-summary>,function(codegenprepare)' %s | FileCheck %s
2+
3+
; Check that we have deterministic output
4+
define void @test(ptr %sp, ptr %t, i32 %n) {
5+
; CHECK-LABEL: @test(
6+
; CHECK-NEXT: entry:
7+
; CHECK-NEXT: %splitgep1 = getelementptr i8, ptr %t, i64 80000
8+
; CHECK-NEXT: %s = load ptr, ptr %sp
9+
; CHECK-NEXT: %splitgep = getelementptr i8, ptr %s, i64 80000
10+
entry:
11+
%s = load ptr, ptr %sp
12+
br label %while_cond
13+
14+
while_cond:
15+
%phi = phi i32 [ 0, %entry ], [ %i, %while_body ]
16+
%gep0 = getelementptr [65536 x i32], ptr %s, i64 0, i64 20000
17+
%gep1 = getelementptr [65536 x i32], ptr %s, i64 0, i64 20001
18+
%gep2 = getelementptr [65536 x i32], ptr %t, i64 0, i64 20000
19+
%gep3 = getelementptr [65536 x i32], ptr %t, i64 0, i64 20001
20+
%cmp = icmp slt i32 %phi, %n
21+
br i1 %cmp, label %while_body, label %while_end
22+
23+
while_body:
24+
%i = add i32 %phi, 1
25+
store i32 %i, ptr %gep0
26+
store i32 %phi, ptr %gep1
27+
store i32 %i, ptr %gep2
28+
store i32 %phi, ptr %gep3
29+
br label %while_cond
30+
31+
while_end:
32+
ret void
33+
}
34+

0 commit comments

Comments
 (0)