Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,13 @@ Register PPCInstrInfo::isLoadFromStackSlot(const MachineInstr &MI,
return 0;
}

/// Sink down CodeGen-only, cheap instructions to allow further
/// optimizations which are only applied intra-block.
bool PPCInstrInfo::shouldBreakCriticalEdgeToSink(MachineInstr &MI) const {
// These can turn into immediates, see PPCRegisterInfo::lowerCRBitRestore.
return MI.getOpcode() == PPC::CRSET || MI.getOpcode() == PPC::CRUNSET;
}

// For opcodes with the ReMaterializable flag set, this function is called to
// verify the instruction is really rematable.
bool PPCInstrInfo::isReallyTriviallyReMaterializable(
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/PowerPC/PPCInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ class PPCInstrInfo : public PPCGenInstrInfo {
unsigned &SubIdx) const override;
Register isLoadFromStackSlot(const MachineInstr &MI,
int &FrameIndex) const override;
bool shouldBreakCriticalEdgeToSink(MachineInstr &MI) const override;
bool isReallyTriviallyReMaterializable(const MachineInstr &MI) const override;
Register isStoreToStackSlot(const MachineInstr &MI,
int &FrameIndex) const override;
Expand Down
36 changes: 36 additions & 0 deletions llvm/test/CodeGen/PowerPC/sink-crset-crunset.mir
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
# RUN: llc -run-pass=machine-sink -mtriple=powerpc64-unknown-linux-gnu -o - %s | FileCheck %s

---
name: sink_crset_crunset
body: |
; CHECK-LABEL: name: sink_crset_crunset
; CHECK: bb.0.entry:
; CHECK-NEXT: successors: %bb.1(0x40000000), %bb.2(0x40000000)
; CHECK-NEXT: liveins: $r3
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: %cond:crrc = CMPLWI killed renamable $r3, 0
; CHECK-NEXT: BCC 76, killed %cond, %bb.2
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: bb.1:
; CHECK-NEXT: successors: %bb.2(0x80000000)
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: %a:crbitrc = CRSET
; CHECK-NEXT: %b:crbitrc = CRUNSET
; CHECK-NEXT: %and:crbitrc = CRAND killed %a, %b
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: bb.2:
; CHECK-NEXT: BLR implicit $lr, implicit $rm
bb.0.entry:
successors: %bb.1(0x40000000), %bb.2(0x40000000)
liveins: $r3
%cond:crrc = CMPLWI killed renamable $r3, 0
%a:crbitrc = CRSET
%b:crbitrc = CRUNSET
BCC 76, killed %cond, %bb.2
bb.1:
%and:crbitrc = CRAND killed %a, %b
bb.2:
BLR implicit $lr, implicit $rm

...
8 changes: 4 additions & 4 deletions llvm/test/CodeGen/PowerPC/spill_p9_setb.ll
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@

define void @p9_setb_spill() {
; CHECK-P9-LABEL: p9_setb_spill:
; CHECK-P9: # %bb.1: # %if.then
; CHECK-P9: .LBB0_2: # %if.then
; CHECK-P9-DAG: crnot 4*cr[[CREG:.*]]+lt, eq
; CHECK-P9-DAG: setb [[REG1:.*]], cr[[CREG]]
; CHECK-P9-DAG: stw [[REG1]]
; CHECK-P9: blr
; CHECK-P9: .LBB0_4: # %if.then1
; CHECK-P9: .LBB0_5: # %if.then1
;
; CHECK-P8-LABEL: p9_setb_spill:
; CHECK-P8: # %bb.1: # %if.then
; CHECK-P8: .LBB0_2: # %if.then
; CHECK-P8-DAG: crnot 4*cr[[CREG2:.*]]+lt, eq
; CHECK-P8-DAG: mfocrf [[REG2:.*]],
; CHECK-P8-DAG: rlwinm [[REG2]], [[REG2]]
; CHECK-P8-DAG: stw [[REG2]]
; CHECK-P8: blr
; CHECK-P8: .LBB0_4: # %if.then1
; CHECK-P8: .LBB0_5: # %if.then1
entry:
br i1 undef, label %if.end, label %if.then

Expand Down