From 312b2e1b99a6a847c6cf2db00891866f778b89bd Mon Sep 17 00:00:00 2001 From: Juneyoung Lee Date: Wed, 24 Feb 2021 16:03:51 +0900 Subject: [PATCH] [TTI] Consider select form of and/or i1 as having arithmetic cost This is a patch that updates the cost of `select i1 a, b, false` to be equivalent to that of `and i1 a, b` as well as the cost of `select i1 a, true, b` equivalent to `or i1 a, b`. Until now, these selects were folded into and/or i1 by InstCombine, but the transformation is poison-unsafe. This is a step towards removing the unsafe transformation. D93065 has relevant transformations linked. These selects should be translated into the assemblies as and/or i1 do in the same manner. The cost should be equivalent. Reviewed By: spatel Differential Revision: https://reviews.llvm.org/D97360 --- .../llvm/Analysis/TargetTransformInfoImpl.h | 20 +++ test/Analysis/CostModel/AArch64/logicalop.ll | 51 +++++++ test/Analysis/CostModel/AMDGPU/logicalop.ll | 50 +++++++ test/Analysis/CostModel/ARM/logicalop.ll | 140 ++++++++++++++++++ test/Analysis/CostModel/PowerPC/logicalop.ll | 46 ++++++ test/Analysis/CostModel/RISCV/logicalop.ll | 58 ++++++++ test/Analysis/CostModel/SystemZ/logicalop.ll | 50 +++++++ test/Analysis/CostModel/X86/logicalop.ll | 61 ++++++++ 8 files changed, 476 insertions(+) create mode 100644 test/Analysis/CostModel/AArch64/logicalop.ll create mode 100644 test/Analysis/CostModel/AMDGPU/logicalop.ll create mode 100644 test/Analysis/CostModel/ARM/logicalop.ll create mode 100644 test/Analysis/CostModel/PowerPC/logicalop.ll create mode 100644 test/Analysis/CostModel/RISCV/logicalop.ll create mode 100644 test/Analysis/CostModel/SystemZ/logicalop.ll create mode 100644 test/Analysis/CostModel/X86/logicalop.ll diff --git a/include/llvm/Analysis/TargetTransformInfoImpl.h b/include/llvm/Analysis/TargetTransformInfoImpl.h index 83b65760cef..688547c5a5e 100644 --- a/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -22,8 +22,11 @@ #include "llvm/IR/GetElementPtrTypeIterator.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Operator.h" +#include "llvm/IR/PatternMatch.h" #include "llvm/IR/Type.h" +using namespace llvm::PatternMatch; + namespace llvm { /// Base class for use as a mix-in that aids implementing @@ -990,6 +993,23 @@ public: CostKind, I); } case Instruction::Select: { + const Value *Op0, *Op1; + if (match(U, m_LogicalAnd(m_Value(Op0), m_Value(Op1))) || + match(U, m_LogicalOr(m_Value(Op0), m_Value(Op1)))) { + // select x, y, false --> x & y + // select x, true, y --> x | y + TTI::OperandValueProperties Op1VP = TTI::OP_None; + TTI::OperandValueProperties Op2VP = TTI::OP_None; + TTI::OperandValueKind Op1VK = TTI::getOperandInfo(Op0, Op1VP); + TTI::OperandValueKind Op2VK = TTI::getOperandInfo(Op1, Op2VP); + assert(Op0->getType()->getScalarSizeInBits() == 1 && + Op1->getType()->getScalarSizeInBits() == 1); + + SmallVector Operands{Op0, Op1}; + return TargetTTI->getArithmeticInstrCost( + match(U, m_LogicalOr()) ? Instruction::Or : Instruction::And, Ty, + CostKind, Op1VK, Op2VK, Op1VP, Op2VP, Operands, I); + } Type *CondTy = U->getOperand(0)->getType(); return TargetTTI->getCmpSelInstrCost(Opcode, U->getType(), CondTy, CmpInst::BAD_ICMP_PREDICATE, diff --git a/test/Analysis/CostModel/AArch64/logicalop.ll b/test/Analysis/CostModel/AArch64/logicalop.ll new file mode 100644 index 00000000000..e148aad6f55 --- /dev/null +++ b/test/Analysis/CostModel/AArch64/logicalop.ll @@ -0,0 +1,51 @@ +; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py +; RUN: opt < %s -cost-model -analyze -mtriple=arm64-apple-ios -mcpu=cyclone | FileCheck %s --check-prefix=CHECK-THROUGHPUT +; RUN: opt < %s -cost-model -analyze -cost-kind=code-size -mtriple=aarch64-- | FileCheck %s --check-prefix=CHECK-SIZE +target datalayout = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:32:64-v128:32:128-a0:0:32-n32-S32" + +define void @op() { + ; Logical and/or - select's cost must be equivalent to that of binop +; CHECK-THROUGHPUT-LABEL: 'op' +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select i1 undef, i1 undef, i1 false +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and i1 undef, undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select i1 undef, i1 true, i1 undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or i1 undef, undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void +; +; CHECK-SIZE-LABEL: 'op' +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select i1 undef, i1 undef, i1 false +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and i1 undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select i1 undef, i1 true, i1 undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or i1 undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; + %sand = select i1 undef, i1 undef, i1 false + %band = and i1 undef, undef + %sor = select i1 undef, i1 true, i1 undef + %bor = or i1 undef, undef + + ret void +} + +define void @vecop() { +; CHECK-THROUGHPUT-LABEL: 'vecop' +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> zeroinitializer +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and <4 x i1> undef, undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or <4 x i1> undef, undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void +; +; CHECK-SIZE-LABEL: 'vecop' +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> zeroinitializer +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and <4 x i1> undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or <4 x i1> undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; + %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> + %band = and <4 x i1> undef, undef + %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef + %bor = or <4 x i1> undef, undef + + ret void +} diff --git a/test/Analysis/CostModel/AMDGPU/logicalop.ll b/test/Analysis/CostModel/AMDGPU/logicalop.ll new file mode 100644 index 00000000000..21e23d73cdd --- /dev/null +++ b/test/Analysis/CostModel/AMDGPU/logicalop.ll @@ -0,0 +1,50 @@ +; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py +; RUN: opt -cost-model -analyze -mtriple=amdgcn-unknown-amdhsa < %s | FileCheck %s --check-prefix=CHECK-THROUGHPUT +; RUN: opt -cost-model -analyze -cost-kind=code-size -mtriple=amdgcn-unknown-amdhsa < %s | FileCheck %s --check-prefix=CHECK-SIZE + +define amdgpu_kernel void @op() { + ; Logical and/or - select's cost must be equivalent to that of binop +; CHECK-THROUGHPUT-LABEL: 'op' +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select i1 undef, i1 undef, i1 false +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and i1 undef, undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select i1 undef, i1 true, i1 undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or i1 undef, undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret void +; +; CHECK-SIZE-LABEL: 'op' +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select i1 undef, i1 undef, i1 false +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and i1 undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select i1 undef, i1 true, i1 undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or i1 undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; + %sand = select i1 undef, i1 undef, i1 false + %band = and i1 undef, undef + %sor = select i1 undef, i1 true, i1 undef + %bor = or i1 undef, undef + + ret void +} + +define void @vecop() { +; CHECK-THROUGHPUT-LABEL: 'vecop' +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> zeroinitializer +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %band = and <4 x i1> undef, undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %bor = or <4 x i1> undef, undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret void +; +; CHECK-SIZE-LABEL: 'vecop' +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> zeroinitializer +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %band = and <4 x i1> undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %bor = or <4 x i1> undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; + %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> + %band = and <4 x i1> undef, undef + %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef + %bor = or <4 x i1> undef, undef + + ret void +} diff --git a/test/Analysis/CostModel/ARM/logicalop.ll b/test/Analysis/CostModel/ARM/logicalop.ll new file mode 100644 index 00000000000..ef12258d482 --- /dev/null +++ b/test/Analysis/CostModel/ARM/logicalop.ll @@ -0,0 +1,140 @@ +; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py +; RUN: opt < %s -cost-model -analyze -mtriple=thumbv8.1m.main-none-eabi -mattr=+mve.fp | FileCheck %s --check-prefix=CHECK-MVE-RECIP +; RUN: opt < %s -cost-model -analyze -mtriple=thumbv7-apple-ios6.0.0 -mcpu=swift | FileCheck %s --check-prefix=CHECK-NEON-RECIP +; RUN: opt < %s -cost-model -analyze -mtriple=thumbv8m.base | FileCheck %s --check-prefix=CHECK-THUMB1-RECIP +; RUN: opt < %s -cost-model -analyze -mtriple=thumbv8m.main | FileCheck %s --check-prefix=CHECK-THUMB2-RECIP +; RUN: opt < %s -cost-model -analyze -cost-kind=code-size -mtriple=thumbv8.1m.main-none-eabi -mattr=+mve.fp | FileCheck %s --check-prefix=CHECK-MVE-SIZE +; RUN: opt < %s -cost-model -analyze -cost-kind=code-size -mtriple=thumbv7-apple-ios6.0.0 -mcpu=swift | FileCheck %s --check-prefix=CHECK-NEON-SIZE +; RUN: opt < %s -cost-model -analyze -cost-kind=code-size -mtriple=thumbv8m.base | FileCheck %s --check-prefix=CHECK-THUMB1-SIZE +; RUN: opt < %s -cost-model -analyze -cost-kind=code-size -mtriple=thumbv8m.main | FileCheck %s --check-prefix=CHECK-THUMB2-SIZE + +define void @op() { + ; Logical and/or - select's cost must be equivalent to that of binop +; CHECK-MVE-RECIP-LABEL: 'op' +; CHECK-MVE-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select i1 undef, i1 undef, i1 false +; CHECK-MVE-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and i1 undef, undef +; CHECK-MVE-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select i1 undef, i1 true, i1 undef +; CHECK-MVE-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or i1 undef, undef +; CHECK-MVE-RECIP-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void +; +; CHECK-NEON-RECIP-LABEL: 'op' +; CHECK-NEON-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select i1 undef, i1 undef, i1 false +; CHECK-NEON-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and i1 undef, undef +; CHECK-NEON-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select i1 undef, i1 true, i1 undef +; CHECK-NEON-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or i1 undef, undef +; CHECK-NEON-RECIP-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void +; +; CHECK-THUMB1-RECIP-LABEL: 'op' +; CHECK-THUMB1-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select i1 undef, i1 undef, i1 false +; CHECK-THUMB1-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and i1 undef, undef +; CHECK-THUMB1-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select i1 undef, i1 true, i1 undef +; CHECK-THUMB1-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or i1 undef, undef +; CHECK-THUMB1-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; +; CHECK-THUMB2-RECIP-LABEL: 'op' +; CHECK-THUMB2-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select i1 undef, i1 undef, i1 false +; CHECK-THUMB2-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and i1 undef, undef +; CHECK-THUMB2-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select i1 undef, i1 true, i1 undef +; CHECK-THUMB2-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or i1 undef, undef +; CHECK-THUMB2-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; +; CHECK-MVE-SIZE-LABEL: 'op' +; CHECK-MVE-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %sand = select i1 undef, i1 undef, i1 false +; CHECK-MVE-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %band = and i1 undef, undef +; CHECK-MVE-SIZE-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %sor = select i1 undef, i1 true, i1 undef +; CHECK-MVE-SIZE-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %bor = or i1 undef, undef +; CHECK-MVE-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; +; CHECK-NEON-SIZE-LABEL: 'op' +; CHECK-NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %sand = select i1 undef, i1 undef, i1 false +; CHECK-NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %band = and i1 undef, undef +; CHECK-NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %sor = select i1 undef, i1 true, i1 undef +; CHECK-NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %bor = or i1 undef, undef +; CHECK-NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; +; CHECK-THUMB1-SIZE-LABEL: 'op' +; CHECK-THUMB1-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %sand = select i1 undef, i1 undef, i1 false +; CHECK-THUMB1-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %band = and i1 undef, undef +; CHECK-THUMB1-SIZE-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %sor = select i1 undef, i1 true, i1 undef +; CHECK-THUMB1-SIZE-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %bor = or i1 undef, undef +; CHECK-THUMB1-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; +; CHECK-THUMB2-SIZE-LABEL: 'op' +; CHECK-THUMB2-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %sand = select i1 undef, i1 undef, i1 false +; CHECK-THUMB2-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %band = and i1 undef, undef +; CHECK-THUMB2-SIZE-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %sor = select i1 undef, i1 true, i1 undef +; CHECK-THUMB2-SIZE-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %bor = or i1 undef, undef +; CHECK-THUMB2-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; + %sand = select i1 undef, i1 undef, i1 false + %band = and i1 undef, undef + %sor = select i1 undef, i1 true, i1 undef + %bor = or i1 undef, undef + + ret void +} + +define void @vecop() { +; CHECK-MVE-RECIP-LABEL: 'vecop' +; CHECK-MVE-RECIP-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> zeroinitializer +; CHECK-MVE-RECIP-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %band = and <4 x i1> undef, undef +; CHECK-MVE-RECIP-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef +; CHECK-MVE-RECIP-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %bor = or <4 x i1> undef, undef +; CHECK-MVE-RECIP-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void +; +; CHECK-NEON-RECIP-LABEL: 'vecop' +; CHECK-NEON-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> zeroinitializer +; CHECK-NEON-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and <4 x i1> undef, undef +; CHECK-NEON-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef +; CHECK-NEON-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or <4 x i1> undef, undef +; CHECK-NEON-RECIP-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void +; +; CHECK-THUMB1-RECIP-LABEL: 'vecop' +; CHECK-THUMB1-RECIP-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> zeroinitializer +; CHECK-THUMB1-RECIP-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %band = and <4 x i1> undef, undef +; CHECK-THUMB1-RECIP-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef +; CHECK-THUMB1-RECIP-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %bor = or <4 x i1> undef, undef +; CHECK-THUMB1-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; +; CHECK-THUMB2-RECIP-LABEL: 'vecop' +; CHECK-THUMB2-RECIP-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> zeroinitializer +; CHECK-THUMB2-RECIP-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %band = and <4 x i1> undef, undef +; CHECK-THUMB2-RECIP-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef +; CHECK-THUMB2-RECIP-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %bor = or <4 x i1> undef, undef +; CHECK-THUMB2-RECIP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; +; CHECK-MVE-SIZE-LABEL: 'vecop' +; CHECK-MVE-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> zeroinitializer +; CHECK-MVE-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and <4 x i1> undef, undef +; CHECK-MVE-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef +; CHECK-MVE-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or <4 x i1> undef, undef +; CHECK-MVE-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; +; CHECK-NEON-SIZE-LABEL: 'vecop' +; CHECK-NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> zeroinitializer +; CHECK-NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and <4 x i1> undef, undef +; CHECK-NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef +; CHECK-NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or <4 x i1> undef, undef +; CHECK-NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; +; CHECK-THUMB1-SIZE-LABEL: 'vecop' +; CHECK-THUMB1-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> zeroinitializer +; CHECK-THUMB1-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %band = and <4 x i1> undef, undef +; CHECK-THUMB1-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef +; CHECK-THUMB1-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %bor = or <4 x i1> undef, undef +; CHECK-THUMB1-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; +; CHECK-THUMB2-SIZE-LABEL: 'vecop' +; CHECK-THUMB2-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> zeroinitializer +; CHECK-THUMB2-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %band = and <4 x i1> undef, undef +; CHECK-THUMB2-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef +; CHECK-THUMB2-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %bor = or <4 x i1> undef, undef +; CHECK-THUMB2-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; + %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> + %band = and <4 x i1> undef, undef + %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef + %bor = or <4 x i1> undef, undef + + ret void +} diff --git a/test/Analysis/CostModel/PowerPC/logicalop.ll b/test/Analysis/CostModel/PowerPC/logicalop.ll new file mode 100644 index 00000000000..2f7f01bff3a --- /dev/null +++ b/test/Analysis/CostModel/PowerPC/logicalop.ll @@ -0,0 +1,46 @@ +; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py +; RUN: opt < %s -cost-model -analyze -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr7 -mattr=+vsx | FileCheck %s --check-prefix=CHECK-THROUGHPUT +; RUN: opt < %s -cost-model -analyze -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr9 -mattr=+vsx | FileCheck %s --check-prefix=CHECK-THROUGHPUT + +; RUN: opt < %s -cost-model -analyze -cost-kind=code-size -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr7 -mattr=+vsx | FileCheck %s --check-prefix=CHECK-SIZE +; RUN: opt < %s -cost-model -analyze -cost-kind=code-size -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr9 -mattr=+vsx | FileCheck %s --check-prefix=CHECK-SIZE + +define void @op() { + ; Logical and/or - select's cost must be equivalent to that of binop +; CHECK-THROUGHPUT-LABEL: 'op' +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select i1 undef, i1 undef, i1 false +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and i1 undef, undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select i1 undef, i1 true, i1 undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or i1 undef, undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void +; +; CHECK-SIZE-LABEL: 'op' +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select i1 undef, i1 undef, i1 false +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and i1 undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select i1 undef, i1 true, i1 undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or i1 undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; + %sand = select i1 undef, i1 undef, i1 false + %band = and i1 undef, undef + %sor = select i1 undef, i1 true, i1 undef + %bor = or i1 undef, undef + + ret void +} + +define void @vecop() { +; CHECK-SIZE-LABEL: 'vecop' +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> zeroinitializer +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and <4 x i1> undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or <4 x i1> undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; + %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> + %band = and <4 x i1> undef, undef + %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef + %bor = or <4 x i1> undef, undef + + ret void +} diff --git a/test/Analysis/CostModel/RISCV/logicalop.ll b/test/Analysis/CostModel/RISCV/logicalop.ll new file mode 100644 index 00000000000..3d42303b0da --- /dev/null +++ b/test/Analysis/CostModel/RISCV/logicalop.ll @@ -0,0 +1,58 @@ +; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py +; RUN: opt -mtriple=riscv32 -cost-model -analyze < %s \ +; RUN: | FileCheck %s --check-prefix=CHECK-THROUGHPUT +; RUN: opt -mtriple=riscv64 -cost-model -analyze < %s \ +; RUN: | FileCheck %s --check-prefix=CHECK-THROUGHPUT + +; RUN: opt -mtriple=riscv32 -cost-model -analyze -cost-kind=code-size < %s \ +; RUN: | FileCheck %s --check-prefix=CHECK-SIZE +; RUN: opt -mtriple=riscv64 -cost-model -analyze -cost-kind=code-size < %s \ +; RUN: | FileCheck %s --check-prefix=CHECK-SIZE + + +define void @op() { + ; Logical and/or - select's cost must be equivalent to that of binop +; CHECK-THROUGHPUT-LABEL: 'op' +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select i1 undef, i1 undef, i1 false +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and i1 undef, undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select i1 undef, i1 true, i1 undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or i1 undef, undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; +; CHECK-SIZE-LABEL: 'op' +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select i1 undef, i1 undef, i1 false +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and i1 undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select i1 undef, i1 true, i1 undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or i1 undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; + %sand = select i1 undef, i1 undef, i1 false + %band = and i1 undef, undef + %sor = select i1 undef, i1 true, i1 undef + %bor = or i1 undef, undef + + ret void +} + +define void @vecop() { +; CHECK-THROUGHPUT-LABEL: 'vecop' +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> zeroinitializer +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %band = and <4 x i1> undef, undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %bor = or <4 x i1> undef, undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; +; CHECK-SIZE-LABEL: 'vecop' +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> zeroinitializer +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and <4 x i1> undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or <4 x i1> undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; + %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> + %band = and <4 x i1> undef, undef + %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef + %bor = or <4 x i1> undef, undef + + ret void +} diff --git a/test/Analysis/CostModel/SystemZ/logicalop.ll b/test/Analysis/CostModel/SystemZ/logicalop.ll new file mode 100644 index 00000000000..a6734a0f4ab --- /dev/null +++ b/test/Analysis/CostModel/SystemZ/logicalop.ll @@ -0,0 +1,50 @@ +; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py +; RUN: opt < %s -cost-model -analyze -mtriple=systemz-unknown -mcpu=z13 | FileCheck %s --check-prefix=CHECK-THROUGHPUT +; RUN: opt < %s -cost-model -analyze -cost-kind=code-size -mtriple=systemz-unknown -mcpu=z13 | FileCheck %s --check-prefix=CHECK-SIZE + +define void @op() { + ; Logical and/or - select's cost must be equivalent to that of binop +; CHECK-THROUGHPUT-LABEL: 'op' +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select i1 undef, i1 undef, i1 false +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and i1 undef, undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select i1 undef, i1 true, i1 undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or i1 undef, undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; +; CHECK-SIZE-LABEL: 'op' +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select i1 undef, i1 undef, i1 false +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and i1 undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select i1 undef, i1 true, i1 undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or i1 undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; + %sand = select i1 undef, i1 undef, i1 false + %band = and i1 undef, undef + %sor = select i1 undef, i1 true, i1 undef + %bor = or i1 undef, undef + + ret void +} + +define void @vecop() { +; CHECK-THROUGHPUT-LABEL: 'vecop' +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> zeroinitializer +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and <4 x i1> undef, undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or <4 x i1> undef, undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; +; CHECK-SIZE-LABEL: 'vecop' +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> zeroinitializer +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and <4 x i1> undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or <4 x i1> undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; + %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> + %band = and <4 x i1> undef, undef + %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef + %bor = or <4 x i1> undef, undef + + ret void +} diff --git a/test/Analysis/CostModel/X86/logicalop.ll b/test/Analysis/CostModel/X86/logicalop.ll new file mode 100644 index 00000000000..bcaca7106aa --- /dev/null +++ b/test/Analysis/CostModel/X86/logicalop.ll @@ -0,0 +1,61 @@ +; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py +; RUN: opt < %s -cost-model -analyze -mtriple=x86_64-unknown-linux-gnu -mattr=+sse2 | FileCheck %s --check-prefix=CHECK-THROUGHPUT +; RUN: opt < %s -cost-model -analyze -mtriple=x86_64-unknown-linux-gnu -mattr=+sse4.1 | FileCheck %s --check-prefix=CHECK-THROUGHPUT +; RUN: opt < %s -cost-model -analyze -mtriple=x86_64-unknown-linux-gnu -mattr=+avx | FileCheck %s --check-prefix=CHECK-THROUGHPUT +; RUN: opt < %s -cost-model -analyze -mtriple=x86_64-unknown-linux-gnu -mattr=+avx2 | FileCheck %s --check-prefix=CHECK-THROUGHPUT +; RUN: opt < %s -cost-model -analyze -mtriple=x86_64-unknown-linux-gnu -mattr=+avx512f,+avx512vl | FileCheck %s --check-prefix=CHECK-THROUGHPUT +; RUN: opt < %s -cost-model -analyze -mtriple=x86_64-unknown-linux-gnu -mattr=+avx512bw,+avx512vl | FileCheck %s --check-prefix=CHECK-THROUGHPUT + +; RUN: opt < %s -cost-model -analyze -cost-kind=code-size -mtriple=x86_64-unknown-linux-gnu -mattr=+sse2 | FileCheck %s --check-prefix=CHECK-SIZE +; RUN: opt < %s -cost-model -analyze -cost-kind=code-size -mtriple=x86_64-unknown-linux-gnu -mattr=+sse4.1 | FileCheck %s --check-prefix=CHECK-SIZE +; RUN: opt < %s -cost-model -analyze -cost-kind=code-size -mtriple=x86_64-unknown-linux-gnu -mattr=+avx | FileCheck %s --check-prefix=CHECK-SIZE +; RUN: opt < %s -cost-model -analyze -cost-kind=code-size -mtriple=x86_64-unknown-linux-gnu -mattr=+avx2 | FileCheck %s --check-prefix=CHECK-SIZE +; RUN: opt < %s -cost-model -analyze -cost-kind=code-size -mtriple=x86_64-unknown-linux-gnu -mattr=+avx512f,+avx512vl | FileCheck %s --check-prefix=CHECK-SIZE +; RUN: opt < %s -cost-model -analyze -cost-kind=code-size -mtriple=x86_64-unknown-linux-gnu -mattr=+avx512bw,+avx512vl | FileCheck %s --check-prefix=CHECK-SIZE + +define void @op() { + ; Logical and/or - select's cost must be equivalent to that of binop +; CHECK-THROUGHPUT-LABEL: 'op' +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select i1 undef, i1 undef, i1 false +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and i1 undef, undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select i1 undef, i1 true, i1 undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or i1 undef, undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void +; +; CHECK-SIZE-LABEL: 'op' +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select i1 undef, i1 undef, i1 false +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and i1 undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select i1 undef, i1 true, i1 undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or i1 undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; + %sand = select i1 undef, i1 undef, i1 false + %band = and i1 undef, undef + %sor = select i1 undef, i1 true, i1 undef + %bor = or i1 undef, undef + + ret void +} + +define void @vecop() { +; CHECK-THROUGHPUT-LABEL: 'vecop' +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> zeroinitializer +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and <4 x i1> undef, undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or <4 x i1> undef, undef +; CHECK-THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void +; +; CHECK-SIZE-LABEL: 'vecop' +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> zeroinitializer +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %band = and <4 x i1> undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bor = or <4 x i1> undef, undef +; CHECK-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; + %sand = select <4 x i1> undef, <4 x i1> undef, <4 x i1> + %band = and <4 x i1> undef, undef + %sor = select <4 x i1> undef, <4 x i1> , <4 x i1> undef + %bor = or <4 x i1> undef, undef + + ret void +}