Hi,

I use asserts to a) guarantee compliance (eg preconditions), and b) hint to 
the compiler about constraints it can take advantage of.

A contrived example:
https://godbolt.org/z/fb5x8s

unmasked uniform int Total(uniform int numbers[], uniform int count)
{
    assert(count==32);
    int total = 0;
    foreach(i = 0...count)
    {
        total += numbers[i];
    }
    return reduce_add(total);
}

The assert for count==32 allows the compiler to generate much leaner code 
for the loop. If I compile with --opt=disable-assertions for an optimized 
release build, the code gen becomes worse.

I think there are two parts to this:
1) It seems counter-intuitive that the constraints introduced by asserts 
are being removed. The reason I would disable asserts is to remove the 
runtime checks, failure path and associated string constants. It would be 
an unusual use-case to want to disable them in-order to allow non-compliant 
data to be used, thus requiring the less optimal code-gen.
2) Is there a reliable alternative to assert() that could apply hints to 
the compiler instead? I know that there are tricks where you can add 
mutating no-op statements like count=32; (https://godbolt.org/z/9411vc) but 
sometimes the constraint is trickier to express than that (eg enforce a 
pointer is not-null), or the data is const and can't be no-op mutated. For 
these, assert is quite convenient.


-- 
You received this message because you are subscribed to the Google Groups 
"Intel SPMD Program Compiler Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ispc-users/62df8d30-9b1f-441f-9f2b-4060fa51fa4fn%40googlegroups.com.

Reply via email to