Skip to content

Commit fdcf246

Browse files
committed
[PowerPC] Do not rely on MachineSink threshold to optimize CR spilling
spill_p0_setb.ll and knowCRBitSpill.ll rely on a probability threshold in MachineSink to pull down CRSET/CRUNSET. It's worth to do so anyway and let register allocation decide otherwise. Additionally, make the interface accept a const MI.
1 parent 9889de8 commit fdcf246

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

llvm/lib/Target/PowerPC/PPCInstrInfo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,13 @@ Register PPCInstrInfo::isLoadFromStackSlot(const MachineInstr &MI,
10721072
return 0;
10731073
}
10741074

1075+
/// Sink down CodeGen-only, cheap instructions to allow further
1076+
/// optimizations which are only applied intra-block.
1077+
bool PPCInstrInfo::shouldBreakCriticalEdgeToSink(MachineInstr &MI) const {
1078+
// These can turn into immediates, see PPCRegisterInfo::lowerCRBitRestore.
1079+
return MI.getOpcode() == PPC::CRSET || MI.getOpcode() == PPC::CRUNSET;
1080+
}
1081+
10751082
// For opcodes with the ReMaterializable flag set, this function is called to
10761083
// verify the instruction is really rematable.
10771084
bool PPCInstrInfo::isReallyTriviallyReMaterializable(

llvm/lib/Target/PowerPC/PPCInstrInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ class PPCInstrInfo : public PPCGenInstrInfo {
424424
unsigned &SubIdx) const override;
425425
Register isLoadFromStackSlot(const MachineInstr &MI,
426426
int &FrameIndex) const override;
427+
bool shouldBreakCriticalEdgeToSink(MachineInstr &MI) const override;
427428
bool isReallyTriviallyReMaterializable(const MachineInstr &MI) const override;
428429
Register isStoreToStackSlot(const MachineInstr &MI,
429430
int &FrameIndex) const override;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# RUN: llc -run-pass=machine-sink -mtriple=powerpc64-unknown-linux-gnu -o - %s | FileCheck %s
2+
3+
---
4+
name: sink-crset-crunset
5+
body: |
6+
; CHECK-LABEL: bb.0.entry
7+
bb.0.entry:
8+
successors: %bb.1(0x40000000), %bb.2(0x40000000)
9+
liveins: $r3
10+
; CHECK-NOT: CRSET
11+
; CHECK-NOT: CRUNSET
12+
%cond:crrc = CMPLWI killed renamable $r3, 0
13+
%a:crbitrc = CRSET
14+
%b:crbitrc = CRUNSET
15+
BCC 76, killed %cond, %bb.2
16+
; CHECK-LABEL: bb.1
17+
bb.1:
18+
; CHECK-DAG: %a:crbitrc = CRSET
19+
; CHECK-DAG: %b:crbitrc = CRUNSET
20+
; CHECK-DAG: %and:crbitrc = CRAND killed %a, %b
21+
%and:crbitrc = CRAND killed %a, %b
22+
; CHECK-LABEL: bb.2
23+
bb.2:
24+
; CHECK: BLR
25+
BLR implicit $lr, implicit $rm
26+
27+
...

llvm/test/CodeGen/PowerPC/spill_p9_setb.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@
1616

1717
define void @p9_setb_spill() {
1818
; CHECK-P9-LABEL: p9_setb_spill:
19-
; CHECK-P9: # %bb.1: # %if.then
19+
; CHECK-P9: .LBB0_2: # %if.then
2020
; CHECK-P9-DAG: crnot 4*cr[[CREG:.*]]+lt, eq
2121
; CHECK-P9-DAG: setb [[REG1:.*]], cr[[CREG]]
2222
; CHECK-P9-DAG: stw [[REG1]]
2323
; CHECK-P9: blr
24-
; CHECK-P9: .LBB0_4: # %if.then1
24+
; CHECK-P9: .LBB0_5: # %if.then1
2525
;
2626
; CHECK-P8-LABEL: p9_setb_spill:
27-
; CHECK-P8: # %bb.1: # %if.then
27+
; CHECK-P8: .LBB0_2: # %if.then
2828
; CHECK-P8-DAG: crnot 4*cr[[CREG2:.*]]+lt, eq
2929
; CHECK-P8-DAG: mfocrf [[REG2:.*]],
3030
; CHECK-P8-DAG: rlwinm [[REG2]], [[REG2]]
3131
; CHECK-P8-DAG: stw [[REG2]]
3232
; CHECK-P8: blr
33-
; CHECK-P8: .LBB0_4: # %if.then1
33+
; CHECK-P8: .LBB0_5: # %if.then1
3434
entry:
3535
br i1 undef, label %if.end, label %if.then
3636

0 commit comments

Comments
 (0)