aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/CodeGenPrepare.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2017-08-01 17:24:54 +0000
committerSanjay Patel <spatel@rotateright.com>2017-08-01 17:24:54 +0000
commit4dbdd470a8da9a44cbe124a6a56174537f7dca3f (patch)
tree8a06403dfd7987555a4d9694860d43f5a15b9069 /llvm/lib/CodeGen/CodeGenPrepare.cpp
parent22e00f09a0eb7c4669347fa6f13283ef5d55668b (diff)
downloadllvm-4dbdd470a8da9a44cbe124a6a56174537f7dca3f.zip
llvm-4dbdd470a8da9a44cbe124a6a56174537f7dca3f.tar.gz
llvm-4dbdd470a8da9a44cbe124a6a56174537f7dca3f.tar.bz2
[CGP] use narrower types in memcmp expansion when possible
This only affects very small memcmp on x86 for now, but it will become more important if we allow vector-sized load and compares. llvm-svn: 309711
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index debfdc1..df900d6 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -2271,8 +2271,12 @@ static bool expandMemCmp(CallInst *CI, const TargetTransformInfo *TTI,
return false;
}
- // Early exit from expansion if size greater than max bytes to load.
+ // Scale the max size down if the target can load more bytes than we need.
uint64_t SizeVal = SizeCast->getZExtValue();
+ if (MaxLoadSize > SizeVal)
+ MaxLoadSize = 1 << SizeCast->getValue().logBase2();
+
+ // Calculate how many load pairs are needed for the constant size.
unsigned NumLoads = 0;
unsigned RemainingSize = SizeVal;
unsigned LoadSize = MaxLoadSize;
@@ -2282,6 +2286,7 @@ static bool expandMemCmp(CallInst *CI, const TargetTransformInfo *TTI,
LoadSize = LoadSize / 2;
}
+ // Don't expand if this will require more loads than desired by the target.
if (NumLoads > TLI->getMaxExpandSizeMemcmp(CI->getFunction()->optForSize())) {
NumMemCmpGreaterThanMax++;
return false;