summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorJonas Paulsson <paulsson@linux.vnet.ibm.com>2018-11-28 08:08:05 +0000
committerJonas Paulsson <paulsson@linux.vnet.ibm.com>2018-11-28 08:08:05 +0000
commit011a503f25cdbfff68bc28c8ac11f7df346674ef (patch)
tree8268f1b725707d14a70fe6ea4b402a6d76a96f21 /llvm/lib
parent5da8e432b9f1824e9be807e4e606f02351a5d8c3 (diff)
downloadbcm5719-llvm-011a503f25cdbfff68bc28c8ac11f7df346674ef.tar.gz
bcm5719-llvm-011a503f25cdbfff68bc28c8ac11f7df346674ef.zip
[SystemZ::TTI] Improved cost values for comparison against memory.
Single instructions exist for i8 and i16 comparisons of memory against a small immediate. This patch makes sure that if the load in these cases has a single user (the ICmp), it gets a 0 cost (folded), and also that the ICmp gets a cost of 1. Review: Ulrich Weigand https://reviews.llvm.org/D54897 llvm-svn: 347733
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp b/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
index 19e4448d199..fdb998e9c45 100644
--- a/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
@@ -835,8 +835,17 @@ int SystemZTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
switch (Opcode) {
case Instruction::ICmp: {
unsigned Cost = 1;
- if (ValTy->isIntegerTy() && ValTy->getScalarSizeInBits() <= 16)
+ if (ValTy->isIntegerTy() && ValTy->getScalarSizeInBits() <= 16) {
+ if (I != nullptr) {
+ // Single instruction for comparison of memory with a small immediate.
+ if (const LoadInst* Ld = dyn_cast<LoadInst>(I->getOperand(0))) {
+ const Instruction *FoldedValue = nullptr;
+ if (isFoldableLoad(Ld, FoldedValue))
+ return Cost;
+ }
+ }
Cost += 2; // extend both operands
+ }
return Cost;
}
case Instruction::Select:
@@ -932,6 +941,12 @@ isFoldableLoad(const LoadInst *Ld, const Instruction *&FoldedValue) {
if (SExtBits || ZExtBits)
return false;
+ // Comparison between memory and immediate.
+ if (UserI->getOpcode() == Instruction::ICmp)
+ if (ConstantInt *CI = dyn_cast<ConstantInt>(UserI->getOperand(1)))
+ if (isUInt<16>(CI->getZExtValue()))
+ return true;
+
unsigned LoadOrTruncBits = (TruncBits ? TruncBits : LoadedBits);
return (LoadOrTruncBits == 32 || LoadOrTruncBits == 64);
break;
OpenPOWER on IntegriCloud