ir3/nir: Add new NIR AlgebraicPass for lowering imul
authorEduardo Lima Mitev <elima@igalia.com>
Sun, 12 May 2019 22:23:58 +0000 (00:23 +0200)
committerEduardo Lima Mitev <elima@igalia.com>
Fri, 7 Jun 2019 06:45:05 +0000 (08:45 +0200)
commit340277ad719526cd4c02583a08151473cc0a6904
tree57f80b5b01f5ba8103e6124a5fccd509f1b2f137
parent3addd7c8d9da9fd050e91738110b6e0a22b9023c
ir3/nir: Add new NIR AlgebraicPass for lowering imul

Currently, ir3 backend compiler is lowering integer multiplication from:

dst = a * b

to:

dst = (al * bl) + (ah * bl << 16) + (al * bh << 16)

by emitting this code:

mull.u tmp0, a, b           ; mul low, i.e. al * bl
madsh.m16 tmp1, a, b, tmp0  ; mul-add shift high mix, i.e. ah * bl << 16
madsh.m16 dst, b, a, tmp1   ; i.e. al * bh << 16

which at that point has very low chances of being optimized.

This patch adds a new nir_algebraic.AlgebraicPass to performs this
lowering during NIR algebraic optimization passes, giving it a better
chance for optimizing the resulting code.

Reviewed-by: Eric Anholt <eric@anholt.net>
src/freedreno/ir3/ir3_nir.h
src/freedreno/ir3/ir3_nir_imul.py [new file with mode: 0644]
src/freedreno/ir3/meson.build