[llvm] [ARM] getOppositeCondition should match AArch64 (NFC) (PR #151550)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 31 09:10:14 PDT 2025


https://github.com/AZero13 created https://github.com/llvm/llvm-project/pull/151550

This also means we don't need a jump table very time we find the opposite condition.

>From b7ef9db789d4bf59234f2ddc852f0b230bad5fb5 Mon Sep 17 00:00:00 2001
From: AZero13 <gfunni234 at gmail.com>
Date: Thu, 31 Jul 2025 12:09:39 -0400
Subject: [PATCH] [ARM] getOppositeCondition should match AArch64

---
 llvm/lib/Target/ARM/Utils/ARMBaseInfo.h | 20 +++-----------------
 1 file changed, 3 insertions(+), 17 deletions(-)

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



More information about the llvm-commits mailing list