Retaining asserts' hints under --opt=disable-assertions?

21 views
Skip to first unread message

ecatc...@unit2games.com

unread,
Jan 14, 2021, 4:06:07 AM1/14/21
to Intel SPMD Program Compiler Users
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:

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.


Dmitry Babokin

unread,
Jan 14, 2021, 4:12:22 PM1/14/21
to ispc-...@googlegroups.com
Hi,

This issue has been sitting in my personal to-do list for quite long. We can do so many performance hints with asserts, likely and unlikely hints and it would be good not to have them as runtime checks.

I think right now we don't have a mechanism to have a workaround for that.

Could you please file an issue, so we don't miss it for the next release?

Dmitry.

--
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 ispc-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ispc-users/62df8d30-9b1f-441f-9f2b-4060fa51fa4fn%40googlegroups.com.

Edward Catchpole

unread,
Jan 15, 2021, 2:19:22 AM1/15/21
to Intel SPMD Program Compiler Users
Thank you Dmitry - I'll transfer this to an issue.
Reply all
Reply to author
Forward
0 new messages