Skip to content

Always convert i2b into ine (and eliminate i2b opcode)

Ian Romanick requested to merge idr/mesa:review/always-lower-i2b into main

I noticed these old patterns in opt_algebraic:

    # Boolean simplifications
   (('i2b16(is_used_by_if)', a), ('ine16', a, 0)),
   (('i2b32(is_used_by_if)', a), ('ine32', a, 0)),
   (('i2b1(is_used_by_if)', a), ('ine', a, 0)),

And I though, "Hm... I wonder what neat optimized thing we emit for i2b when it's not used by an if?" I turns out, the Intel compiler just compares the integer for inequality with zero. D'oh! I looked at another backend and another and another. As far as I can tell, the only backend that does anything special for i2b is the Broadcom backend.

The optimization done in the Broadcom compiler for i2b could also be done for x != 0 too, and there's a patch for that. That patch was dropped after discussion in !16801 (closed).

There are quite a few places, especially in opt_algebraic, where x != 0 is treated specially, but there is virtually nothing for i2b. Rather than duplicate all of that effort, just canonicalize i2b to x != 0 everywhere. If there is something special that can be done for x != 0 that is never used as a condition, it's still very easy to detect that case.

Edited by Ian Romanick

Merge request reports

Loading