[LLVMdev] Handling Masked Vector Operations

dag at cray.com dag at cray.com
Thu May 2 12:31:19 PDT 2013


Dan Gohman <dan433584 at gmail.com> writes:

> The selects with undef do indeed do what you intend here. They return
> vectors where the elements corresponding to true bits in the mask have
> defined values, and the other elements have undef values. Undef can
> indeed exist on a per-element basis, and LLVM is quite careful to
> implement this [0].

Ok, that's what I would expect.

> The real problem with this approach is that there's nothing guarding
> those undef elements from the div. If the undef elements happen to be
> 0, you'll divide by zero, which is undefined behavior. For a divide,
> it's either necessary to define the behavior of divide-by-zero (not
> what LLVM does today), or mask the divide itself.

The intent is to match the select/select/div/select as one masked divide
instruction.  I totally understand what you're saying and I know there
is no guarantee that we will even see that construct way down in isel.
But it seems to be the best we've got right now.

Using safe values for false items is...er...safer.  :)  We'll probably
do that and hope we can avoid the overhead at isel time.

                            -David



More information about the llvm-dev mailing list