[llvm] [AArch64] xor -1 can be mvn, so make it free (PR #166014)

via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 1 12:06:26 PDT 2025


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

None

>From 00960f9bcdc2ee7121bdba5151fe223171144b88 Mon Sep 17 00:00:00 2001
From: AZero13 <gfunni234 at gmail.com>
Date: Sat, 1 Nov 2025 14:52:43 -0400
Subject: [PATCH] [AArch64] xor -1 can be mvn, so make it free

---
 llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
index fede586cf35bc..bd25a81f9025a 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -443,6 +443,10 @@ InstructionCost AArch64TTIImpl::getIntImmCostInst(unsigned Opcode, unsigned Idx,
   case Instruction::Store:
     ImmIdx = 0;
     break;
+  case Instruction::Xor:
+    if (Idx == 1 && (BitSize == 32 || BitSize == 64) && Imm.isAllOnes())
+      return TTI::TCC_Free; // xor a, -1 can be folded to MVN
+  [[fallthrough]];
   case Instruction::Add:
   case Instruction::Sub:
   case Instruction::Mul:
@@ -452,7 +456,6 @@ InstructionCost AArch64TTIImpl::getIntImmCostInst(unsigned Opcode, unsigned Idx,
   case Instruction::SRem:
   case Instruction::And:
   case Instruction::Or:
-  case Instruction::Xor:
   case Instruction::ICmp:
     ImmIdx = 1;
     break;



More information about the llvm-commits mailing list