[pkg-d-commits] [ldc] 47/149: Skip some obsolete muls and divs for arrays with element size = 1
Matthias Klumpp
mak at moszumanska.debian.org
Sun Apr 23 22:36:56 UTC 2017
This is an automated email from the git hooks/post-receive script.
mak pushed a commit to annotated tag v1.2.0
in repository ldc.
commit de26dd674758ba9de23e6de5b6fe739ff6e8d43c
Author: Martin <noone at nowhere.com>
Date: Sat Jan 21 13:24:14 2017 +0100
Skip some obsolete muls and divs for arrays with element size = 1
---
gen/arrays.cpp | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/gen/arrays.cpp b/gen/arrays.cpp
index 4e9a12c..8203b72 100644
--- a/gen/arrays.cpp
+++ b/gen/arrays.cpp
@@ -248,6 +248,12 @@ void DtoArrayAssign(Loc &loc, DValue *lhs, DValue *rhs, int op,
LLValue *lhsPtr = DtoBitCast(realLhsPtr, getVoidPtrType());
LLValue *lhsLength = DtoArrayLen(lhs);
+ auto computeSize = [](LLValue *length, size_t elementSize) {
+ return elementSize == 1
+ ? length
+ : gIR->ir->CreateMul(length, DtoConstSize_t(elementSize));
+ };
+
// Be careful to handle void arrays correctly when modifying this (see tests
// for DMD issue 7493).
// TODO: This should use AssignExp::memset.
@@ -264,14 +270,13 @@ void DtoArrayAssign(Loc &loc, DValue *lhs, DValue *rhs, int op,
if (!needsDestruction && !needsPostblit) {
// fast version
- LLValue *elemSize =
- DtoConstSize_t(getTypeAllocSize(DtoMemType(elemType)));
- LLValue *lhsSize = gIR->ir->CreateMul(elemSize, lhsLength);
+ const size_t elementSize = getTypeAllocSize(DtoMemType(elemType));
+ LLValue *lhsSize = computeSize(lhsLength, elementSize);
if (rhs->isNull()) {
DtoMemSetZero(lhsPtr, lhsSize);
} else {
- LLValue *rhsSize = gIR->ir->CreateMul(elemSize, rhsLength);
+ LLValue *rhsSize = computeSize(rhsLength, elementSize);
const bool knownInBounds =
isConstructing || (t->ty == Tsarray && t2->ty == Tsarray);
copySlice(loc, lhsPtr, lhsSize, rhsPtr, rhsSize, knownInBounds);
@@ -302,13 +307,19 @@ void DtoArrayAssign(Loc &loc, DValue *lhs, DValue *rhs, int op,
if (!needsDestruction && !needsPostblit) {
// fast version
- LLValue *elemSize = DtoConstSize_t(
- getTypeAllocSize(realLhsPtr->getType()->getContainedType(0)));
- LLValue *lhsSize = gIR->ir->CreateMul(elemSize, lhsLength);
+ const size_t lhsElementSize =
+ getTypeAllocSize(realLhsPtr->getType()->getContainedType(0));
LLType *rhsType = DtoMemType(t2);
- LLValue *rhsSize = DtoConstSize_t(getTypeAllocSize(rhsType));
- LLValue *actualPtr = DtoBitCast(lhsPtr, rhsType->getPointerTo());
- LLValue *actualLength = gIR->ir->CreateExactUDiv(lhsSize, rhsSize);
+ const size_t rhsSize = getTypeAllocSize(rhsType);
+ LLValue *actualPtr = DtoBitCast(realLhsPtr, rhsType->getPointerTo());
+ LLValue *actualLength = lhsLength;
+ if (rhsSize != lhsElementSize) {
+ LLValue *lhsSize = computeSize(lhsLength, lhsElementSize);
+ actualLength =
+ rhsSize == 1
+ ? lhsSize
+ : gIR->ir->CreateExactUDiv(lhsSize, DtoConstSize_t(rhsSize));
+ }
DtoArrayInit(loc, actualPtr, actualLength, rhs);
} else {
LLFunction *fn = getRuntimeFunction(loc, gIR->module,
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git
More information about the pkg-d-commits
mailing list