summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp')
-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