Skip to content

Commit ab62fa5

Browse files
committed
Merging r371048:
------------------------------------------------------------------------ r371048 | jonpa | 2019-09-05 12:20:05 +0200 (Thu, 05 Sep 2019) | 7 lines [SystemZ] Recognize INLINEASM_BR in backend Handle the remaining cases also by handling asm goto in SystemZInstrInfo::getBranchInfo(). Review: Ulrich Weigand https://reviews.llvm.org/D67151 ------------------------------------------------------------------------ llvm-svn: 371057
1 parent d8975f4 commit ab62fa5

File tree

5 files changed

+34
-20
lines changed

5 files changed

+34
-20
lines changed

llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -462,13 +462,13 @@ bool SystemZInstrInfo::analyzeBranch(MachineBasicBlock &MBB,
462462
break;
463463

464464
// A terminator that isn't a branch can't easily be handled by this
465-
// analysis. Asm goto is not understood / optimized.
466-
if (!I->isBranch() || I->getOpcode() == SystemZ::INLINEASM_BR)
465+
// analysis.
466+
if (!I->isBranch())
467467
return true;
468468

469469
// Can't handle indirect branches.
470470
SystemZII::Branch Branch(getBranchInfo(*I));
471-
if (!Branch.Target->isMBB())
471+
if (!Branch.hasMBBTarget())
472472
return true;
473473

474474
// Punt on compound branches.
@@ -478,7 +478,7 @@ bool SystemZInstrInfo::analyzeBranch(MachineBasicBlock &MBB,
478478
if (Branch.CCMask == SystemZ::CCMASK_ANY) {
479479
// Handle unconditional branches.
480480
if (!AllowModify) {
481-
TBB = Branch.Target->getMBB();
481+
TBB = Branch.getMBBTarget();
482482
continue;
483483
}
484484

@@ -490,23 +490,23 @@ bool SystemZInstrInfo::analyzeBranch(MachineBasicBlock &MBB,
490490
FBB = nullptr;
491491

492492
// Delete the JMP if it's equivalent to a fall-through.
493-
if (MBB.isLayoutSuccessor(Branch.Target->getMBB())) {
493+
if (MBB.isLayoutSuccessor(Branch.getMBBTarget())) {
494494
TBB = nullptr;
495495
I->eraseFromParent();
496496
I = MBB.end();
497497
continue;
498498
}
499499

500500
// TBB is used to indicate the unconditinal destination.
501-
TBB = Branch.Target->getMBB();
501+
TBB = Branch.getMBBTarget();
502502
continue;
503503
}
504504

505505
// Working from the bottom, handle the first conditional branch.
506506
if (Cond.empty()) {
507507
// FIXME: add X86-style branch swap
508508
FBB = TBB;
509-
TBB = Branch.Target->getMBB();
509+
TBB = Branch.getMBBTarget();
510510
Cond.push_back(MachineOperand::CreateImm(Branch.CCValid));
511511
Cond.push_back(MachineOperand::CreateImm(Branch.CCMask));
512512
continue;
@@ -517,7 +517,7 @@ bool SystemZInstrInfo::analyzeBranch(MachineBasicBlock &MBB,
517517

518518
// Only handle the case where all conditional branches branch to the same
519519
// destination.
520-
if (TBB != Branch.Target->getMBB())
520+
if (TBB != Branch.getMBBTarget())
521521
return true;
522522

523523
// If the conditions are the same, we can leave them alone.
@@ -547,7 +547,7 @@ unsigned SystemZInstrInfo::removeBranch(MachineBasicBlock &MBB,
547547
continue;
548548
if (!I->isBranch())
549549
break;
550-
if (!getBranchInfo(*I).Target->isMBB())
550+
if (!getBranchInfo(*I).hasMBBTarget())
551551
break;
552552
// Remove the branch.
553553
I->eraseFromParent();
@@ -1545,6 +1545,10 @@ SystemZInstrInfo::getBranchInfo(const MachineInstr &MI) const {
15451545
return SystemZII::Branch(SystemZII::BranchCLG, SystemZ::CCMASK_ICMP,
15461546
MI.getOperand(2).getImm(), &MI.getOperand(3));
15471547

1548+
case SystemZ::INLINEASM_BR:
1549+
// Don't try to analyze asm goto, so pass nullptr as branch target argument.
1550+
return SystemZII::Branch(SystemZII::AsmGoto, 0, 0, nullptr);
1551+
15481552
default:
15491553
llvm_unreachable("Unrecognized branch opcode");
15501554
}

llvm/lib/Target/SystemZ/SystemZInstrInfo.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,18 @@ enum BranchType {
100100

101101
// An instruction that decrements a 64-bit register and branches if
102102
// the result is nonzero.
103-
BranchCTG
103+
BranchCTG,
104+
105+
// An instruction representing an asm goto statement.
106+
AsmGoto
104107
};
105108

106109
// Information about a branch instruction.
107-
struct Branch {
110+
class Branch {
111+
// The target of the branch. In case of INLINEASM_BR, this is nullptr.
112+
const MachineOperand *Target;
113+
114+
public:
108115
// The type of the branch.
109116
BranchType Type;
110117

@@ -114,12 +121,15 @@ struct Branch {
114121
// CCMASK_<N> is set if the branch should be taken when CC == N.
115122
unsigned CCMask;
116123

117-
// The target of the branch.
118-
const MachineOperand *Target;
119-
120124
Branch(BranchType type, unsigned ccValid, unsigned ccMask,
121125
const MachineOperand *target)
122-
: Type(type), CCValid(ccValid), CCMask(ccMask), Target(target) {}
126+
: Target(target), Type(type), CCValid(ccValid), CCMask(ccMask) {}
127+
128+
bool isIndirect() { return Target != nullptr && Target->isReg(); }
129+
bool hasMBBTarget() { return Target != nullptr && Target->isMBB(); }
130+
MachineBasicBlock *getMBBTarget() {
131+
return hasMBBTarget() ? Target->getMBB() : nullptr;
132+
}
123133
};
124134

125135
// Kinds of fused compares in compare-and-* instructions. Together with type

llvm/lib/Target/SystemZ/SystemZLongBranch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ TerminatorInfo SystemZLongBranch::describeTerminator(MachineInstr &MI) {
257257
}
258258
Terminator.Branch = &MI;
259259
Terminator.TargetBlock =
260-
TII->getBranchInfo(MI).Target->getMBB()->getNumber();
260+
TII->getBranchInfo(MI).getMBBTarget()->getNumber();
261261
}
262262
return Terminator;
263263
}

llvm/lib/Target/SystemZ/SystemZMachineScheduler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ void SystemZPostRASchedStrategy::enterMBB(MachineBasicBlock *NextMBB) {
108108
I != SinglePredMBB->end(); I++) {
109109
LLVM_DEBUG(dbgs() << "** Emitting incoming branch: "; I->dump(););
110110
bool TakenBranch = (I->isBranch() &&
111-
(TII->getBranchInfo(*I).Target->isReg() || // Relative branch
112-
TII->getBranchInfo(*I).Target->getMBB() == MBB));
111+
(TII->getBranchInfo(*I).isIndirect() ||
112+
TII->getBranchInfo(*I).getMBBTarget() == MBB));
113113
HazardRec->emitInstruction(&*I, TakenBranch);
114114
if (TakenBranch)
115115
break;

llvm/test/CodeGen/SystemZ/asm-20.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
; Test that asm goto can be compiled.
22
;
3-
; RUN: llc < %s -mtriple=s390x-linux-gnu
3+
; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z14
44

55
define i32 @c() {
66
entry:
7-
callbr void asm sideeffect "", "X"(i8* blockaddress(@c, %d))
7+
callbr void asm sideeffect "j d", "X"(i8* blockaddress(@c, %d))
88
to label %asm.fallthrough [label %d]
99

1010
asm.fallthrough: ; preds = %entry

0 commit comments

Comments
 (0)