[llvm] bd606af - [ARM] Only update the successor edges for immediate predecessors of PrologueMBB
John Brawn via llvm-commits
llvm-commits at lists.llvm.org
Tue May 3 04:42:17 PDT 2022
Author: Zhiyao Ma
Date: 2022-05-03T12:36:35+01:00
New Revision: bd606afe26f258d081fbe025b20a71b277c1edde
URL: https://github.com/llvm/llvm-project/commit/bd606afe26f258d081fbe025b20a71b277c1edde
DIFF: https://github.com/llvm/llvm-project/commit/bd606afe26f258d081fbe025b20a71b277c1edde.diff
LOG: [ARM] Only update the successor edges for immediate predecessors of PrologueMBB
When adjusting the function prologue for segmented stacks, only update
the successor edges of the immediate predecessors of the original
prologue.
Differential Revision: https://reviews.llvm.org/D122959
Added:
Modified:
llvm/lib/Target/ARM/ARMFrameLowering.cpp
llvm/test/CodeGen/ARM/segmented-stacks.ll
llvm/test/CodeGen/Thumb/segmented-stacks.ll
llvm/test/CodeGen/Thumb2/segmented-stacks.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/ARM/ARMFrameLowering.cpp b/llvm/lib/Target/ARM/ARMFrameLowering.cpp
index c2cc3024aca9e..b2765b2370ff7 100644
--- a/llvm/lib/Target/ARM/ARMFrameLowering.cpp
+++ b/llvm/lib/Target/ARM/ARMFrameLowering.cpp
@@ -2562,8 +2562,9 @@ void ARMFrameLowering::adjustForSegmentedStacks(
// Make sure the LiveIns are still sorted and unique.
MBB->sortUniqueLiveIns();
// Replace the edges to PrologueMBB by edges to the sequences
- // we are about to add.
- MBB->ReplaceUsesOfBlockWith(&PrologueMBB, AddedBlocks[0]);
+ // we are about to add, but only update for immediate predecessors.
+ if (MBB->isSuccessor(&PrologueMBB))
+ MBB->ReplaceUsesOfBlockWith(&PrologueMBB, AddedBlocks[0]);
}
// The required stack size that is aligned to ARM constant criterion.
diff --git a/llvm/test/CodeGen/ARM/segmented-stacks.ll b/llvm/test/CodeGen/ARM/segmented-stacks.ll
index 10ce0657e573c..38617122cbd31 100644
--- a/llvm/test/CodeGen/ARM/segmented-stacks.ll
+++ b/llvm/test/CodeGen/ARM/segmented-stacks.ll
@@ -280,4 +280,24 @@ define i32 @test_sibling_call_empty_frame(i32 %x) #0 {
}
+
+declare void @panic() unnamed_addr
+
+; We used to crash while compiling the following function.
+; ARM-linux-LABEL: build_should_not_segfault:
+; ARM-android-LABEL: build_should_not_segfault:
+define void @build_should_not_segfault(i8 %x) unnamed_addr #0 {
+start:
+ %_0 = icmp ult i8 %x, 16
+ %or.cond = select i1 undef, i1 true, i1 %_0
+ br i1 %or.cond, label %bb1, label %bb2
+
+bb1:
+ ret void
+
+bb2:
+ call void @panic()
+ unreachable
+}
+
attributes #0 = { "split-stack" }
diff --git a/llvm/test/CodeGen/Thumb/segmented-stacks.ll b/llvm/test/CodeGen/Thumb/segmented-stacks.ll
index 6ad8cf9f20d2d..daebafe2b482e 100644
--- a/llvm/test/CodeGen/Thumb/segmented-stacks.ll
+++ b/llvm/test/CodeGen/Thumb/segmented-stacks.ll
@@ -275,4 +275,24 @@ define void @test_nostack() #0 {
; Thumb-linux-NOT: bl __morestack
}
+
+declare void @panic() unnamed_addr
+
+; We used to crash while compiling the following function.
+; Thumb-linux-LABEL: build_should_not_segfault:
+; Thumb-android-LABEL: build_should_not_segfault:
+define void @build_should_not_segfault(i8 %x) unnamed_addr #0 {
+start:
+ %_0 = icmp ult i8 %x, 16
+ %or.cond = select i1 undef, i1 true, i1 %_0
+ br i1 %or.cond, label %bb1, label %bb2
+
+bb1:
+ ret void
+
+bb2:
+ call void @panic()
+ unreachable
+}
+
attributes #0 = { "split-stack" }
diff --git a/llvm/test/CodeGen/Thumb2/segmented-stacks.ll b/llvm/test/CodeGen/Thumb2/segmented-stacks.ll
index 0f34e9c98e893..70892073dea6e 100644
--- a/llvm/test/CodeGen/Thumb2/segmented-stacks.ll
+++ b/llvm/test/CodeGen/Thumb2/segmented-stacks.ll
@@ -171,4 +171,24 @@ define fastcc void @test_fastcc_large() #0 {
; ARM-NEXT: .long 40192
}
+
+declare void @panic() unnamed_addr
+
+; We used to crash while compiling the following function.
+; THUMB-LABEL: build_should_not_segfault:
+; ARM-LABEL: build_should_not_segfault:
+define void @build_should_not_segfault(i8 %x) unnamed_addr #0 {
+start:
+ %_0 = icmp ult i8 %x, 16
+ %or.cond = select i1 undef, i1 true, i1 %_0
+ br i1 %or.cond, label %bb1, label %bb2
+
+bb1:
+ ret void
+
+bb2:
+ call void @panic()
+ unreachable
+}
+
attributes #0 = { "split-stack" }
More information about the llvm-commits
mailing list