Skip to content

NIR: Partial redundancy elimination for compares

This series adds a new optimization pass that tries to replace code sequences like

if (x < y) {
    z = y - x;

with a sequence like

t = x - y;
if (t < 0) {
    z = -t;

On architectures where the subtract can generate the flags used by the if-statement, this saves an instruction. It's also possible that moving an instruction out of the if-statement will allow nir_opt_peephole_select to convert the whole thing to a bcsel.

Currently only floating point compares and adds are supported. Adding support for integer will be a challenge due to integer overflow. There are a couple possible solutions, but they may not apply to all architectures.

Merge request reports