-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[PowerPC] need to set CallFrameSize for the pass PPCReduceCRLogicals when insert a new block #151017
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
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-backend-powerpc Author: zhijian lin (diggerlin) ChangesIn the https://reviews.llvm.org/D156113 [CodeGen] Store call frame size in MachineBasicBlock, When a basic block has been split in the middle of a call sequence. the call frame size may not be zero, it need to set the setCallFrameSize for the new MachineBasicBlock. but in the function Full diff: https://github.com/llvm/llvm-project/pull/151017.diff 2 Files Affected:
diff --git a/llvm/lib/Target/PowerPC/PPCReduceCRLogicals.cpp b/llvm/lib/Target/PowerPC/PPCReduceCRLogicals.cpp
index 0ffd35dfa279c..f83b2fb8e65a2 100644
--- a/llvm/lib/Target/PowerPC/PPCReduceCRLogicals.cpp
+++ b/llvm/lib/Target/PowerPC/PPCReduceCRLogicals.cpp
@@ -248,6 +248,11 @@ static bool splitMBB(BlockSplitInfo &BSI) {
}
addIncomingValuesToPHIs(NewBRTarget, ThisMBB, NewMBB, MRI);
+ // Set the call frame size on ThisMBB to the new basic blocks.
+ // See https://reviews.llvm.org/D156113.
+ unsigned CallFrameSize = TII->getCallFrameSizeAt(ThisMBB->back());
+ NewMBB->setCallFrameSize(CallFrameSize);
+
LLVM_DEBUG(dbgs() << "After splitting, ThisMBB:\n"; ThisMBB->dump());
LLVM_DEBUG(dbgs() << "NewMBB:\n"; NewMBB->dump());
LLVM_DEBUG(dbgs() << "New branch-to block:\n"; NewBRTarget->dump());
diff --git a/llvm/test/CodeGen/PowerPC/ppc_reduce_cr_logicals.ll b/llvm/test/CodeGen/PowerPC/ppc_reduce_cr_logicals.ll
new file mode 100644
index 0000000000000..7502991a58cc4
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/ppc_reduce_cr_logicals.ll
@@ -0,0 +1,75 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-gnu-linux < %s | FileCheck %s -check-prefix=CHECK
+
+define ptr @xe_migrate_copy(i1 %tobool, i1 %tobool6) {
+; CHECK-LABEL: xe_migrate_copy:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: mfcr 12
+; CHECK-NEXT: stw 12, 8(1)
+; CHECK-NEXT: mflr 0
+; CHECK-NEXT: stdu 1, -176(1)
+; CHECK-NEXT: std 0, 192(1)
+; CHECK-NEXT: .cfi_def_cfa_offset 176
+; CHECK-NEXT: .cfi_offset lr, 16
+; CHECK-NEXT: .cfi_offset r27, -40
+; CHECK-NEXT: .cfi_offset r28, -32
+; CHECK-NEXT: .cfi_offset r29, -24
+; CHECK-NEXT: .cfi_offset r30, -16
+; CHECK-NEXT: .cfi_offset cr2, 8
+; CHECK-NEXT: std 27, 136(1) # 8-byte Folded Spill
+; CHECK-NEXT: andi. 4, 4, 1
+; CHECK-NEXT: crmove 8, 1
+; CHECK-NEXT: andi. 3, 3, 1
+; CHECK-NEXT: std 28, 144(1) # 8-byte Folded Spill
+; CHECK-NEXT: crmove 9, 1
+; CHECK-NEXT: std 29, 152(1) # 8-byte Folded Spill
+; CHECK-NEXT: std 30, 160(1) # 8-byte Folded Spill
+; CHECK-NEXT: lwz 30, 132(1)
+; CHECK-NEXT: ld 28, 8(0)
+; CHECK-NEXT: ld 29, 16(0)
+; CHECK-NEXT: ld 27, 0(0)
+; CHECK-NEXT: std 2, 40(1)
+; CHECK-NEXT: b .LBB0_3
+; CHECK-NEXT: .LBB0_1: # %if.then36
+; CHECK-NEXT: #
+; CHECK-NEXT: li 6, 1
+; CHECK-NEXT: .LBB0_2: # %if.then36
+; CHECK-NEXT: #
+; CHECK-NEXT: mtctr 27
+; CHECK-NEXT: li 4, 0
+; CHECK-NEXT: li 5, 0
+; CHECK-NEXT: li 7, 0
+; CHECK-NEXT: li 8, 0
+; CHECK-NEXT: mr 9, 30
+; CHECK-NEXT: li 10, 0
+; CHECK-NEXT: mr 2, 28
+; CHECK-NEXT: mr 11, 29
+; CHECK-NEXT: bctrl
+; CHECK-NEXT: ld 2, 40(1)
+; CHECK-NEXT: .LBB0_3: # %if.then36
+; CHECK-NEXT: #
+; CHECK-NEXT: lwz 3, 0(0)
+; CHECK-NEXT: cmplwi 3, 0
+; CHECK-NEXT: li 3, 0
+; CHECK-NEXT: crandc 20, 8, 2
+; CHECK-NEXT: std 3, 112(1)
+; CHECK-NEXT: bc 12, 20, .LBB0_1
+; CHECK-NEXT: # %bb.4: # %if.then36
+; CHECK-NEXT: #
+; CHECK-NEXT: crand 20, 2, 9
+; CHECK-NEXT: li 6, 0
+; CHECK-NEXT: bc 4, 20, .LBB0_2
+; CHECK-NEXT: b .LBB0_1
+entry:
+ %src_L0 = alloca i64, align 8
+ br label %if.then36
+
+if.then36: ; preds = %if.then36, %entry
+ %0 = load i32, ptr null, align 4
+ %tobool37.not = icmp eq i32 %0, 0
+ %tobool.tobool6 = select i1 %tobool37.not, i1 %tobool, i1 %tobool6
+ %1 = load i64, ptr %src_L0, align 8
+ %conv55 = trunc i64 %1 to i32
+ %call57 = call i32 null(ptr null, ptr null, i64 0, i1 %tobool.tobool6, i64 0, i1 false, i32 %conv55, i64 0, i1 false)
+ br label %if.then36
+}
|
unsigned CallFrameSize = TII->getCallFrameSizeAt(ThisMBB->back()); | ||
NewMBB->setCallFrameSize(CallFrameSize); |
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.
nit: can we just inline this to remove the tmp variable?
@@ -0,0 +1,75 @@ | |||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | |||
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-gnu-linux < %s | FileCheck %s -check-prefix=CHECK |
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.
just wondering what this lit test produces if we don't re-calculate the frame size? Does it crash?
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.
add run line to test 32bit BE?
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.
just wondering what this lit test produces if we don't re-calculate the frame size? Does it crash?
yes, if we don't re-calculate the frame size it crash in this test case.
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.
LGTM.
Thx
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-gnu-linux < %s | FileCheck %s -check-prefix=CHECK | ||
; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-gnu-linux < %s | FileCheck %s -check-prefix=CHECKBE | ||
|
||
define ptr @xe_migrate_copy(i1 %tobool, i1 %tobool6) { |
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.
define ptr @xe_migrate_copy(i1 %tobool, i1 %tobool6) { | |
define ptr @xe_migrate_copy(i1 %tobool, i1 %tobool6) nounwind { |
@@ -0,0 +1,124 @@ | |||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | |||
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-gnu-linux < %s | FileCheck %s -check-prefix=CHECK |
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.
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-gnu-linux < %s | FileCheck %s -check-prefix=CHECK | |
; RUN: llc -mtriple=powerpc64-unknown-gnu-linux < %s | FileCheck %s -check-prefix=CHECK |
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.
Why do you feel we shouldn't test with -verify-machineinstrs
? Normally I ask people to add that....
br label %if.then36 | ||
|
||
if.then36: ; preds = %if.then36, %entry | ||
%0 = load i32, ptr null, align 4 |
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.
Avoid the UB null load
%tobool.tobool6 = select i1 %tobool37.not, i1 %tobool, i1 %tobool6 | ||
%1 = load i64, ptr %src_L0, align 8 | ||
%conv55 = trunc i64 %1 to i32 | ||
%call57 = call i32 null(ptr null, ptr null, i64 0, i1 %tobool.tobool6, i64 0, i1 false, i32 %conv55, i64 0, i1 false) |
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.
Avoid UB call to null
%0 = load i32, ptr null, align 4 | ||
%tobool37.not = icmp eq i32 %0, 0 | ||
%tobool.tobool6 = select i1 %tobool37.not, i1 %tobool, i1 %tobool6 | ||
%1 = load i64, ptr %src_L0, align 8 |
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.
Use named values in tests
the test case llvm/test/CodeGen/PowerPC/ppc_reduce_cr_logicals.ll is generated by the llvm-reduce from #144594 (comment). the test case is crashed without the patch. |
81376a1
to
30258cb
Compare
In the [CodeGen] Store call frame size in MachineBasicBlock, it mentions When a basic block has been split in the middle of a call sequence. the call frame size may not be zero, it need to set the setCallFrameSize for the new MachineBasicBlock. but in the function
splitMBB(BlockSplitInfo &BSI)
in the llvm/lib/Target/PowerPC/PPCReduceCRLogicals.cpp , it do not setCallFrameSzie for the new MachineBasicBlockNewMBB
, we will setCallFrameSzie in the patch.the patch fix the crash mention in #144594 (comment)