aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp10
-rw-r--r--llvm/test/Analysis/CostModel/AArch64/cmp.ll4
2 files changed, 12 insertions, 2 deletions
diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
index 7077e9f..c22e254 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -2812,6 +2812,16 @@ InstructionCost AArch64TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
return LT.first * 4; // fcvtl + fcvtl + fcmp + xtn
}
+ // Treat the icmp in icmp(and, 0) as free, as we can make use of ands.
+ // FIXME: This can apply to more conditions and add/sub if it can be shown to
+ // be profitable.
+ if (ValTy->isIntegerTy() && ISD == ISD::SETCC && I &&
+ ICmpInst::isEquality(VecPred) &&
+ TLI->isTypeLegal(TLI->getValueType(DL, ValTy)) &&
+ match(I->getOperand(1), m_Zero()) &&
+ match(I->getOperand(0), m_And(m_Value(), m_Value())))
+ return 0;
+
// The base case handles scalable vectors fine for now, since it treats the
// cost as 1 * legalization cost.
return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind, I);
diff --git a/llvm/test/Analysis/CostModel/AArch64/cmp.ll b/llvm/test/Analysis/CostModel/AArch64/cmp.ll
index d257243..d595f5e 100644
--- a/llvm/test/Analysis/CostModel/AArch64/cmp.ll
+++ b/llvm/test/Analysis/CostModel/AArch64/cmp.ll
@@ -64,9 +64,9 @@ define void @andcmp() {
; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %a16 = and i16 undef, undef
; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %c16 = icmp ne i16 %a16, 0
; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %a32 = and i32 undef, undef
-; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %c32 = icmp eq i32 %a32, 0
+; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %c32 = icmp eq i32 %a32, 0
; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %a64 = and i64 undef, undef
-; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %c64 = icmp ne i64 %a64, 0
+; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %c64 = icmp ne i64 %a64, 0
; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %a128 = and i128 undef, undef
; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %c128 = icmp eq i128 %a128, 0
; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %av16i8 = and <16 x i8> undef, undef