Skip to content

Commit ce78ca6

Browse files
committed
Do the same for XCore, RISC_V, and M68k
1 parent 9181c31 commit ce78ca6

File tree

4 files changed

+14
-63
lines changed

4 files changed

+14
-63
lines changed

llvm/lib/Target/M68k/M68kInstrInfo.h

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -56,42 +56,9 @@ enum CondCode {
5656
// mb tag based
5757

5858
static inline M68k::CondCode GetOppositeBranchCondition(M68k::CondCode CC) {
59-
switch (CC) {
60-
default:
61-
llvm_unreachable("Illegal condition code!");
62-
case M68k::COND_T:
63-
return M68k::COND_F;
64-
case M68k::COND_F:
65-
return M68k::COND_T;
66-
case M68k::COND_HI:
67-
return M68k::COND_LS;
68-
case M68k::COND_LS:
69-
return M68k::COND_HI;
70-
case M68k::COND_CC:
71-
return M68k::COND_CS;
72-
case M68k::COND_CS:
73-
return M68k::COND_CC;
74-
case M68k::COND_NE:
75-
return M68k::COND_EQ;
76-
case M68k::COND_EQ:
77-
return M68k::COND_NE;
78-
case M68k::COND_VC:
79-
return M68k::COND_VS;
80-
case M68k::COND_VS:
81-
return M68k::COND_VC;
82-
case M68k::COND_PL:
83-
return M68k::COND_MI;
84-
case M68k::COND_MI:
85-
return M68k::COND_PL;
86-
case M68k::COND_GE:
87-
return M68k::COND_LT;
88-
case M68k::COND_LT:
89-
return M68k::COND_GE;
90-
case M68k::COND_GT:
91-
return M68k::COND_LE;
92-
case M68k::COND_LE:
93-
return M68k::COND_GT;
94-
}
59+
// To reverse a condition it's necessary to only invert the low bit:
60+
assert(CC != COND_INVALID && "COND_INVALID has no inverse!");
61+
return static_cast<CondCode>(static_cast<unsigned>(CC) ^ 0x1);
9562
}
9663

9764
static inline unsigned GetCondBranchFromCond(M68k::CondCode CC) {

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,25 +1128,6 @@ unsigned RISCVCC::getBrCond(RISCVCC::CondCode CC, unsigned SelectOpc) {
11281128
}
11291129
}
11301130

1131-
RISCVCC::CondCode RISCVCC::getOppositeBranchCondition(RISCVCC::CondCode CC) {
1132-
switch (CC) {
1133-
default:
1134-
llvm_unreachable("Unrecognized conditional branch");
1135-
case RISCVCC::COND_EQ:
1136-
return RISCVCC::COND_NE;
1137-
case RISCVCC::COND_NE:
1138-
return RISCVCC::COND_EQ;
1139-
case RISCVCC::COND_LT:
1140-
return RISCVCC::COND_GE;
1141-
case RISCVCC::COND_GE:
1142-
return RISCVCC::COND_LT;
1143-
case RISCVCC::COND_LTU:
1144-
return RISCVCC::COND_GEU;
1145-
case RISCVCC::COND_GEU:
1146-
return RISCVCC::COND_LTU;
1147-
}
1148-
}
1149-
11501131
bool RISCVInstrInfo::analyzeBranch(MachineBasicBlock &MBB,
11511132
MachineBasicBlock *&TBB,
11521133
MachineBasicBlock *&FBB,

llvm/lib/Target/RISCV/RISCVInstrInfo.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ enum CondCode {
4444
COND_INVALID
4545
};
4646

47-
CondCode getOppositeBranchCondition(CondCode);
47+
CondCode getOppositeBranchCondition(CondCode CC) {
48+
// To reverse a condition it's necessary to only invert the low bit:
49+
assert(CC != COND_INVALID && "COND_INVALID has no inverse!");
50+
return static_cast<CondCode>(static_cast<unsigned>(CC) ^ 0x1);
51+
}
52+
4853
unsigned getBrCond(CondCode CC, unsigned SelectOpc = 0);
4954

5055
} // end of namespace RISCVCC

llvm/lib/Target/XCore/XCoreInstrInfo.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,11 @@ static inline unsigned GetCondBranchFromCond(XCore::CondCode CC)
150150

151151
/// GetOppositeBranchCondition - Return the inverse of the specified
152152
/// condition, e.g. turning COND_E to COND_NE.
153-
static inline XCore::CondCode GetOppositeBranchCondition(XCore::CondCode CC)
154-
{
155-
switch (CC) {
156-
default: llvm_unreachable("Illegal condition code!");
157-
case XCore::COND_TRUE : return XCore::COND_FALSE;
158-
case XCore::COND_FALSE : return XCore::COND_TRUE;
159-
}
153+
static inline XCore::CondCode GetOppositeBranchCondition(XCore::CondCode CC) {
154+
// To reverse a condition it's necessary to only invert the low bit:
155+
assert(CC != XCore::COND_INVALID && "COND_INVALID has no inverse!");
156+
157+
return static_cast<CondCode>(static_cast<unsigned>(CC) ^ 0x1);
160158
}
161159

162160
/// analyzeBranch - Analyze the branching code at the end of MBB, returning

0 commit comments

Comments
 (0)