-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[X86][ARM][RISCV][XCore][M68K] Invert the low bit to get the inverse predicate (NFC) #151748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-backend-m68k @llvm/pr-subscribers-backend-arm Author: AZero13 (AZero13) ChangesBoth ARM and x86 defined their predicate in such a way to allow bit twiddling to get inverse predicates Full diff: https://github.com/llvm/llvm-project/pull/151748.diff 3 Files Affected:
diff --git a/llvm/lib/Target/ARM/Utils/ARMBaseInfo.h b/llvm/lib/Target/ARM/Utils/ARMBaseInfo.h
index dc4f811e075c6..ebf4eaa122481 100644
--- a/llvm/lib/Target/ARM/Utils/ARMBaseInfo.h
+++ b/llvm/lib/Target/ARM/Utils/ARMBaseInfo.h
@@ -46,23 +46,9 @@ enum CondCodes { // Meaning (integer) Meaning (floating-point)
};
inline static CondCodes getOppositeCondition(CondCodes CC) {
- switch (CC) {
- default: llvm_unreachable("Unknown condition code");
- case EQ: return NE;
- case NE: return EQ;
- case HS: return LO;
- case LO: return HS;
- case MI: return PL;
- case PL: return MI;
- case VS: return VC;
- case VC: return VS;
- case HI: return LS;
- case LS: return HI;
- case GE: return LT;
- case LT: return GE;
- case GT: return LE;
- case LE: return GT;
- }
+ // To reverse a condition it's necessary to only invert the low bit:
+
+ return static_cast<CondCodes>(static_cast<unsigned>(CC) ^ 0x1);
}
/// getSwappedCondition - assume the flags are set by MI(a,b), return
diff --git a/llvm/lib/Target/X86/X86InstrInfo.cpp b/llvm/lib/Target/X86/X86InstrInfo.cpp
index abf365eedec39..833833678bb7a 100644
--- a/llvm/lib/Target/X86/X86InstrInfo.cpp
+++ b/llvm/lib/Target/X86/X86InstrInfo.cpp
@@ -3300,46 +3300,9 @@ unsigned X86::getNonNDVariant(unsigned Opc) {
/// Return the inverse of the specified condition,
/// e.g. turning COND_E to COND_NE.
X86::CondCode X86::GetOppositeBranchCondition(X86::CondCode CC) {
- switch (CC) {
- default:
- llvm_unreachable("Illegal condition code!");
- case X86::COND_E:
- return X86::COND_NE;
- case X86::COND_NE:
- return X86::COND_E;
- case X86::COND_L:
- return X86::COND_GE;
- case X86::COND_LE:
- return X86::COND_G;
- case X86::COND_G:
- return X86::COND_LE;
- case X86::COND_GE:
- return X86::COND_L;
- case X86::COND_B:
- return X86::COND_AE;
- case X86::COND_BE:
- return X86::COND_A;
- case X86::COND_A:
- return X86::COND_BE;
- case X86::COND_AE:
- return X86::COND_B;
- case X86::COND_S:
- return X86::COND_NS;
- case X86::COND_NS:
- return X86::COND_S;
- case X86::COND_P:
- return X86::COND_NP;
- case X86::COND_NP:
- return X86::COND_P;
- case X86::COND_O:
- return X86::COND_NO;
- case X86::COND_NO:
- return X86::COND_O;
- case X86::COND_NE_OR_P:
- return X86::COND_E_AND_NP;
- case X86::COND_E_AND_NP:
- return X86::COND_NE_OR_P;
- }
+ // To reverse a condition it's necessary to only invert the low bit:
+
+ return static_cast<CondCodes>(static_cast<unsigned>(CC) ^ 0x1);
}
/// Assuming the flags are set by MI(a,b), return the condition code if we
diff --git a/llvm/lib/Target/X86/X86InstrInfo.h b/llvm/lib/Target/X86/X86InstrInfo.h
index 9dc5f4b0e086e..125e1d9efe0c4 100644
--- a/llvm/lib/Target/X86/X86InstrInfo.h
+++ b/llvm/lib/Target/X86/X86InstrInfo.h
@@ -85,7 +85,11 @@ unsigned getNonNDVariant(unsigned Opc);
/// GetOppositeBranchCondition - Return the inverse of the specified cond,
/// e.g. turning COND_E to COND_NE.
-CondCode GetOppositeBranchCondition(CondCode CC);
+CondCode GetOppositeBranchCondition(CondCode CC) {
+ // To reverse a condition it's necessary to only invert the low bit:
+
+ return static_cast<CondCode>(static_cast<unsigned>(CC) ^ 0x1);
+}
/// Get the VPCMP immediate for the given condition.
unsigned getVPCMPImmForCond(ISD::CondCode CC);
|
Both ARM and x86 defined their predicate in such a way to allow bit twiddling to get inverse predicates
topperc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Don't change the scope of a patch after I approve it. |
|
@topperc Is this good then? |
topperc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/27/builds/14121 Here is the relevant piece of the build log for the reference |
This is caused by this PR. Did you actually test building M68k given you explicitly changed it? |
This happens to be true. It's completely undocumented that this is something that should be maintained for anyone coming to add new condition codes to the corresponding enum. At the very least you must document this. |
All these platforms defined their predicate in such a way to allow bit twiddling to get inverse predicates