[llvm] [AArch64] Use ccmn to compare negative imm constants (PR #95825)

David Green via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 18 23:29:29 PDT 2024


================
@@ -4667,17 +4667,21 @@ MachineInstr *AArch64InstructionSelector::emitConditionalComparison(
     Register LHS, Register RHS, CmpInst::Predicate CC,
     AArch64CC::CondCode Predicate, AArch64CC::CondCode OutCC,
     MachineIRBuilder &MIB) const {
-  // TODO: emit CMN as an optimization.
   auto &MRI = *MIB.getMRI();
   LLT OpTy = MRI.getType(LHS);
   unsigned CCmpOpc;
   std::optional<ValueAndVReg> C;
   if (CmpInst::isIntPredicate(CC)) {
     assert(OpTy.getSizeInBits() == 32 || OpTy.getSizeInBits() == 64);
     C = getIConstantVRegValWithLookThrough(RHS, MRI);
-    if (C && C->Value.ult(32))
-      CCmpOpc = OpTy.getSizeInBits() == 32 ? AArch64::CCMPWi : AArch64::CCMPXi;
-    else
+    if (C && (C->Value.slt(32) && C->Value.sgt(-32))) {
+      if (C->Value.ult(32))
----------------
davemgreen wrote:

This needn't be a nested `if`.

https://github.com/llvm/llvm-project/pull/95825


More information about the llvm-commits mailing list