Problem with missing support for non-zero contant initializers.

Hi all.

I'm working on a LLVM based compiler for the D programming language by
Walter Bright.

D allows static arrays up to 16MB in size. I'm initializing global
static arrays with a constant initializer. But D requires that (per
default) static arrays are initialized with the default initializer
for the element type. For float this happens to be NaN, so I cannot
use a 'zeroinitializer'.

This is problematic as D code like:

Hi Tomas,

I did some simple timings on llc for arrays with different sizes and
it looks something like this:

elements / time
32k / 39 sek
16k / 9.5 sek
8k / 1.5 sek
4k / 0.3 sek
2k / 0.07 sek

Anton's reply gives you a work around for the moment, but I'd suggest
raising a bug on the above; there's clearly something in the
implementation that's not linear.

Cheers,

Ralph.

I'm working on a LLVM based compiler for the D programming language by
Walter Bright.

Nifty.

D allows static arrays up to 16MB in size. I'm initializing global
static arrays with a constant initializer. But D requires that (per
default) static arrays are initialized with the default initializer
for the element type. For float this happens to be NaN, so I cannot
use a 'zeroinitializer'.

Wow, this *is* bad. I think the solution to this is to add a new ConstantFillArray node. It would always have array type, would take a single Constant* value, and would give you the filled array with that constant. Please file a bug if you're interested.

-Chris

Chris Lattner wrote:

D allows static arrays up to 16MB in size. I'm initializing global
static arrays with a constant initializer. But D requires that (per
default) static arrays are initialized with the default initializer
for the element type. For float this happens to be NaN, so I cannot
use a 'zeroinitializer'.

Wow, this *is* bad. I think the solution to this is to add a new ConstantFillArray node. It would always have array type, would take a single Constant* value, and would give you the filled array with that constant. Please file a bug if you're interested.

I believe this is already bug 1324.

Nick

> D allows static arrays up to 16MB in size. I'm initializing global
> static arrays with a constant initializer. But D requires that (per
> default) static arrays are initialized with the default initializer
> for the element type. For float this happens to be NaN, so I cannot
> use a 'zeroinitializer'.

Wow, this *is* bad. I think the solution to this is to add a new
ConstantFillArray node. It would always have array type, would take a
single Constant* value, and would give you the filled array with that
constant. Please file a bug if you're interested.

In Ada, global variables should in general be default initialized to undef
(not zero) so this could also be useful for Ada.

Ciao,

Duncan.

Thanx for all the responses, I'm very glad that this issue is not ignored.

I have submitted a bugzilla ticket for it:
http://llvm.org/bugs/show_bug.cgi?id=1616

Regards,
Tomas

In that case, Ada should just use UndefValue, which should work today. :slight_smile:

-Chris

http://nondot.org/sabre
http://llvm.org

It is definitely related. I think that ConstantFillArray should replace ConstantAggregateZero (CAZ = CFA<0>). PR1324 is useful when you have structs or arrays that are not filled with the same value, for example the string in comment #1.

-Chris