Use memset to initialize arrays with constant byte value.

This extends the existing code for null values.
This commit is contained in:
kai 2013-08-18 21:58:07 +02:00
parent 62683c4efe
commit 80a65e34f3

View file

@ -118,14 +118,18 @@ void DtoArrayInit(Loc& loc, DValue* array, DValue* value, int op)
LLValue* ptr = DtoArrayPtr(array);
Type* arrayelemty = array->getType()->nextOf()->toBasetype();
// lets first optimize all zero initializations down to a memset.
// lets first optimize all zero/constant i8 initializations down to a memset.
// this simplifies codegen later on as llvm null's have no address!
LLValue *val = value->getRVal();
if (isaConstant(val) && isaConstant(val)->isNullValue())
if (isaConstant(val) && (isaConstant(val)->isNullValue()
|| val->getType() == LLType::getInt8Ty(gIR->context())))
{
size_t X = getTypePaddedSize(val->getType());
LLValue* nbytes = gIR->ir->CreateMul(dim, DtoConstSize_t(X), ".nbytes");
DtoMemSetZero(ptr, nbytes);
if (isaConstant(val)->isNullValue())
DtoMemSetZero(ptr, nbytes);
else
DtoMemSet(ptr, val, nbytes);
return;
}