Skip to content

Commit d506a73

Browse files
committed
[X86][ARM] Invert the low bit to get the inverse predicate (NFC)
Both ARM and x86 defined their predicate in such a way to allow bit twiddling to get inverse predicates
1 parent 9e0dc4f commit d506a73

File tree

3 files changed

+8
-63
lines changed

3 files changed

+8
-63
lines changed

llvm/lib/Target/ARM/Utils/ARMBaseInfo.h

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,9 @@ enum CondCodes { // Meaning (integer) Meaning (floating-point)
4646
};
4747

4848
inline static CondCodes getOppositeCondition(CondCodes CC) {
49-
switch (CC) {
50-
default: llvm_unreachable("Unknown condition code");
51-
case EQ: return NE;
52-
case NE: return EQ;
53-
case HS: return LO;
54-
case LO: return HS;
55-
case MI: return PL;
56-
case PL: return MI;
57-
case VS: return VC;
58-
case VC: return VS;
59-
case HI: return LS;
60-
case LS: return HI;
61-
case GE: return LT;
62-
case LT: return GE;
63-
case GT: return LE;
64-
case LE: return GT;
65-
}
49+
// To reverse a condition it's necessary to only invert the low bit:
50+
51+
return static_cast<CondCodes>(static_cast<unsigned>(CC) ^ 0x1);
6652
}
6753

6854
/// getSwappedCondition - assume the flags are set by MI(a,b), return

llvm/lib/Target/X86/X86InstrInfo.cpp

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3297,51 +3297,6 @@ unsigned X86::getNonNDVariant(unsigned Opc) {
32973297
return getNewOpcFromTable(X86ND2NonNDTable, Opc);
32983298
}
32993299

3300-
/// Return the inverse of the specified condition,
3301-
/// e.g. turning COND_E to COND_NE.
3302-
X86::CondCode X86::GetOppositeBranchCondition(X86::CondCode CC) {
3303-
switch (CC) {
3304-
default:
3305-
llvm_unreachable("Illegal condition code!");
3306-
case X86::COND_E:
3307-
return X86::COND_NE;
3308-
case X86::COND_NE:
3309-
return X86::COND_E;
3310-
case X86::COND_L:
3311-
return X86::COND_GE;
3312-
case X86::COND_LE:
3313-
return X86::COND_G;
3314-
case X86::COND_G:
3315-
return X86::COND_LE;
3316-
case X86::COND_GE:
3317-
return X86::COND_L;
3318-
case X86::COND_B:
3319-
return X86::COND_AE;
3320-
case X86::COND_BE:
3321-
return X86::COND_A;
3322-
case X86::COND_A:
3323-
return X86::COND_BE;
3324-
case X86::COND_AE:
3325-
return X86::COND_B;
3326-
case X86::COND_S:
3327-
return X86::COND_NS;
3328-
case X86::COND_NS:
3329-
return X86::COND_S;
3330-
case X86::COND_P:
3331-
return X86::COND_NP;
3332-
case X86::COND_NP:
3333-
return X86::COND_P;
3334-
case X86::COND_O:
3335-
return X86::COND_NO;
3336-
case X86::COND_NO:
3337-
return X86::COND_O;
3338-
case X86::COND_NE_OR_P:
3339-
return X86::COND_E_AND_NP;
3340-
case X86::COND_E_AND_NP:
3341-
return X86::COND_NE_OR_P;
3342-
}
3343-
}
3344-
33453300
/// Assuming the flags are set by MI(a,b), return the condition code if we
33463301
/// modify the instructions such that flags are set by MI(b,a).
33473302
static X86::CondCode getSwappedCondition(X86::CondCode CC) {

llvm/lib/Target/X86/X86InstrInfo.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ unsigned getNonNDVariant(unsigned Opc);
8585

8686
/// GetOppositeBranchCondition - Return the inverse of the specified cond,
8787
/// e.g. turning COND_E to COND_NE.
88-
CondCode GetOppositeBranchCondition(CondCode CC);
88+
CondCode GetOppositeBranchCondition(CondCode CC) {
89+
// To reverse a condition it's necessary to only invert the low bit:
90+
91+
return static_cast<CondCode>(static_cast<unsigned>(CC) ^ 0x1);
92+
}
8993

9094
/// Get the VPCMP immediate for the given condition.
9195
unsigned getVPCMPImmForCond(ISD::CondCode CC);

0 commit comments

Comments
 (0)