[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
diff --git a/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp b/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
index 19e4448..fdb998e 100644
--- a/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
@@ -835,8 +835,17 @@
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 @@
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;