Skip to content

Commit 40b923a

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 7ffeab3 commit 40b923a

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
2+
# RUN: llc -run-pass=machine-sink -mtriple=powerpc64-unknown-linux-gnu -o - %s | FileCheck %s
3+
4+
---
5+
name: sink_crset_crunset
6+
body: |
7+
; CHECK-LABEL: name: sink_crset_crunset
8+
; CHECK: bb.0.entry:
9+
; CHECK-NEXT: successors: %bb.1(0x40000000), %bb.2(0x40000000)
10+
; CHECK-NEXT: liveins: $r3
11+
; CHECK-NEXT: {{ $}}
12+
; CHECK-NEXT: %cond:crrc = CMPLWI killed renamable $r3, 0
13+
; CHECK-NEXT: BCC 76, killed %cond, %bb.2
14+
; CHECK-NEXT: {{ $}}
15+
; CHECK-NEXT: bb.1:
16+
; CHECK-NEXT: successors: %bb.2(0x80000000)
17+
; CHECK-NEXT: {{ $}}
18+
; CHECK-NEXT: %a:crbitrc = CRSET
19+
; CHECK-NEXT: %b:crbitrc = CRUNSET
20+
; CHECK-NEXT: %and:crbitrc = CRAND killed %a, %b
21+
; CHECK-NEXT: {{ $}}
22+
; CHECK-NEXT: bb.2:
23+
; CHECK-NEXT: BLR implicit $lr, implicit $rm
24+
bb.0.entry:
25+
successors: %bb.1(0x40000000), %bb.2(0x40000000)
26+
liveins: $r3
27+
%cond:crrc = CMPLWI killed renamable $r3, 0
28+
%a:crbitrc = CRSET
29+
%b:crbitrc = CRUNSET
30+
BCC 76, killed %cond, %bb.2
31+
bb.1:
32+
%and:crbitrc = CRAND killed %a, %b
33+
bb.2:
34+
BLR implicit $lr, implicit $rm
35+
36+
...

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)