Skip to content

Commit 5ca4153

Browse files
committed
[AArch64] xor -1 can be mvn, so make it free
1 parent 6cb942c commit 5ca4153

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,16 +443,18 @@ InstructionCost AArch64TTIImpl::getIntImmCostInst(unsigned Opcode, unsigned Idx,
443443
case Instruction::Store:
444444
ImmIdx = 0;
445445
break;
446+
case Instruction::Xor:
447+
if (Imm.isAllOnes())
448+
return TTI::TCC_Free; // xor a, -1 can be folded to MVN
449+
[[fallthrough]];
446450
case Instruction::Add:
447451
case Instruction::Sub:
448452
case Instruction::Mul:
449453
case Instruction::UDiv:
450454
case Instruction::SDiv:
451455
case Instruction::URem:
452456
case Instruction::SRem:
453-
case Instruction::And:
454457
case Instruction::Or:
455-
case Instruction::Xor:
456458
case Instruction::ICmp:
457459
ImmIdx = 1;
458460
break;
@@ -475,6 +477,11 @@ InstructionCost AArch64TTIImpl::getIntImmCostInst(unsigned Opcode, unsigned Idx,
475477
case Instruction::Ret:
476478
case Instruction::Load:
477479
break;
480+
case Instruction::And:
481+
if (Imm == 255 || Imm == 65535)
482+
return TTI::TCC_Free;
483+
ImmIdx = 1;
484+
break;
478485
}
479486

480487
if (Idx == ImmIdx) {

0 commit comments

Comments
 (0)