[LLVMdev] [cfe-dev] Disable Short-Circuit Evaluation?

David A. Greene greened at obbligato.org
Mon Oct 10 07:29:48 PDT 2011


Justin Holewinski <justin.holewinski at gmail.com> writes:

> int globalIndexY2 = get_group_id(1)*186 + 6*get_local_id(1) + 2 + 1;
> bool valid2       = validX && globalIndexY2 >= 4 && globalIndexY2 < 3910;
>
> Clang, even at -O0, is performing short-circuit evaluation of these
> expressions, resulting in a fair number of branch instructions being
> generated.

It has to.  This is the semantics of C.  Short-circuiting is used to
defend against all sorts of undefined behavior in real code.

>  For most targets, this is a beneficial optimizations.

For all targets.  If the code doesn't work, it's pretty useless.  :)

>  However, for my target (PTX), it would be most beneficial to actually
> evaluate the entire expression and remove the unneeded branches.  Is
> this possible with current Clang/LLVM?

So for PTX what you want is if-conversion.  I believe there is a pass
that does this in the ARM codegen.  Of course the PTX backend will have
to support mask bits.  I don't know if it does currently.

                                -Dave




More information about the llvm-dev mailing list