Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LoongArch] Don't merge FrameIndex accesses into [F]{LD,ST}X
Otherwise eliminateFrameIndex cannot figure out how to fixup the stack offset with its stateless logic, because there wouldn't be an immediate slot for it to trivially write to, and it may not be easy to transform the surrounding code to make it work. This fixes a fairly common crash when compiling moderately complex code with Clang. Differential Revision: https://reviews.llvm.org/D135251
- Loading branch information
1 parent
f204229
commit 31327c2
Showing
7 changed files
with
128 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
; RUN: llc --mtriple=loongarch64 --mattr=+f < %s | FileCheck %s | ||
|
||
;; This should not crash the code generator, but the indexed loads/stores | ||
;; should still be present (the important part is that [f]{ld,st}x shouldn't | ||
;; take an $sp argument). | ||
|
||
define i8 @test_load_i(i64 %i) { | ||
; CHECK-LABEL: test_load_i: | ||
; CHECK: # %bb.0: | ||
; CHECK-NEXT: addi.d $sp, $sp, -16 | ||
; CHECK-NEXT: .cfi_def_cfa_offset 16 | ||
; CHECK-NEXT: addi.d $a1, $sp, 8 | ||
; CHECK-NEXT: ldx.b $a0, $a0, $a1 | ||
; CHECK-NEXT: addi.d $sp, $sp, 16 | ||
; CHECK-NEXT: ret | ||
%1 = alloca ptr | ||
%2 = getelementptr inbounds i8, ptr %1, i64 %i | ||
%3 = load i8, ptr %2 | ||
ret i8 %3 | ||
} | ||
|
||
define float @test_load_f(i64 %i) { | ||
; CHECK-LABEL: test_load_f: | ||
; CHECK: # %bb.0: | ||
; CHECK-NEXT: addi.d $sp, $sp, -16 | ||
; CHECK-NEXT: .cfi_def_cfa_offset 16 | ||
; CHECK-NEXT: slli.d $a0, $a0, 2 | ||
; CHECK-NEXT: addi.d $a1, $sp, 8 | ||
; CHECK-NEXT: fldx.s $fa0, $a0, $a1 | ||
; CHECK-NEXT: addi.d $sp, $sp, 16 | ||
; CHECK-NEXT: ret | ||
%1 = alloca ptr | ||
%2 = getelementptr inbounds float, ptr %1, i64 %i | ||
%3 = load float, ptr %2 | ||
ret float %3 | ||
} | ||
|
||
define void @test_store_i(i64 %i, i8 %v) { | ||
; CHECK-LABEL: test_store_i: | ||
; CHECK: # %bb.0: | ||
; CHECK-NEXT: addi.d $sp, $sp, -16 | ||
; CHECK-NEXT: .cfi_def_cfa_offset 16 | ||
; CHECK-NEXT: addi.d $a2, $sp, 8 | ||
; CHECK-NEXT: stx.b $a1, $a0, $a2 | ||
; CHECK-NEXT: addi.d $sp, $sp, 16 | ||
; CHECK-NEXT: ret | ||
%1 = alloca ptr | ||
%2 = getelementptr inbounds i8, ptr %1, i64 %i | ||
store i8 %v, ptr %2, align 1 | ||
ret void | ||
} | ||
|
||
define void @test_store_f(i64 %i, float %v) { | ||
; CHECK-LABEL: test_store_f: | ||
; CHECK: # %bb.0: | ||
; CHECK-NEXT: addi.d $sp, $sp, -16 | ||
; CHECK-NEXT: .cfi_def_cfa_offset 16 | ||
; CHECK-NEXT: slli.d $a0, $a0, 2 | ||
; CHECK-NEXT: addi.d $a1, $sp, 8 | ||
; CHECK-NEXT: fstx.s $fa0, $a0, $a1 | ||
; CHECK-NEXT: addi.d $sp, $sp, 16 | ||
; CHECK-NEXT: ret | ||
%1 = alloca ptr | ||
%2 = getelementptr inbounds float, ptr %1, i64 %i | ||
store float %v, ptr %2, align 4 | ||
ret void | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
; RUN: llc --mtriple=loongarch32 < %s | ||
; RUN: llc --mtriple=loongarch64 < %s | ||
|
||
;; This should not crash the code generator. | ||
|
||
@.str.2 = external dso_local unnamed_addr constant [69 x i8], align 1 | ||
|
||
define dso_local void @main() { | ||
entry: | ||
%n0 = alloca [2 x [3 x i32]], align 4 | ||
%0 = load i32, ptr poison, align 4 | ||
%idxprom15 = sext i32 %0 to i64 | ||
%arrayidx16 = getelementptr inbounds [2 x [3 x i32]], ptr %n0, i64 0, i64 %idxprom15 | ||
%arrayidx17 = getelementptr inbounds [3 x i32], ptr %arrayidx16, i64 0, i64 0 | ||
%1 = load i32, ptr %arrayidx17, align 4 | ||
call void (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef signext %1) | ||
ret void | ||
} | ||
|
||
declare void @printf(ptr, ...) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
; RUN: llc --mtriple=loongarch32 < %s | ||
; RUN: llc --mtriple=loongarch64 < %s | ||
|
||
;; This should not crash the code generator. | ||
|
||
define void @_ZN12_GLOBAL__N_111DumpVisitorclIN4llvm16itanium_demangle8FoldExprEEEvPKT_() { | ||
entry: | ||
%ref.tmp6.i.i = alloca [4 x i8], align 1 | ||
br label %for.cond.i.i | ||
|
||
for.cond.i.i: ; preds = %for.body.i.i, %entry | ||
%__begin0.0.add.i.i = add nuw nsw i64 poison, 1 | ||
br label %for.body.i.i | ||
|
||
for.body.i.i: ; preds = %for.cond.i.i | ||
%__begin0.0.ptr.i.i = getelementptr inbounds i8, ptr %ref.tmp6.i.i, i64 %__begin0.0.add.i.i | ||
%0 = load i8, ptr %__begin0.0.ptr.i.i, align 1 | ||
%tobool18.not.i.i = icmp eq i8 %0, 0 | ||
br i1 %tobool18.not.i.i, label %for.cond.i.i, label %exit | ||
|
||
exit: ; preds = %for.body.i.i | ||
unreachable | ||
} |