nir: Saturating integer arithmetic is not associative
authorIan Romanick <ian.d.romanick@intel.com>
Tue, 30 Apr 2019 15:00:32 +0000 (08:00 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Wed, 1 May 2019 16:07:47 +0000 (09:07 -0700)
In 8-bits,

    iadd_sat(iadd_sat(0x7f, 0x7f), -1) =
    iadd_sat(0x7f, -1) =
    0x7e

but,

    iadd_sat(0x7f, iadd_sat(0x7f, -1)) =
    iadd_sat(0x7f, 0x7e) =
    0x7f

Fixes: 272e927d0e9 ("nir/spirv: initial handling of OpenCL.std extension opcodes")
Reviewed-by: Karol Herbst <kherbst@redhat.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/nir/nir_opcodes.py

index d35d820aa5b3fb32bf53ba7088695f46ff1cc673..246d3d4038125d27be4c115347c0da3ca69e5f8a 100644 (file)
@@ -482,7 +482,7 @@ def binop_reduce(name, output_size, output_type, src_type, prereduce_expr,
 
 binop("fadd", tfloat, commutative + associative, "src0 + src1")
 binop("iadd", tint, commutative + associative, "src0 + src1")
-binop("iadd_sat", tint, commutative + associative, """
+binop("iadd_sat", tint, commutative, """
       src1 > 0 ?
          (src0 + src1 < src0 ? (1ull << (bit_size - 1)) - 1 : src0 + src1) :
          (src0 < src0 + src1 ? (1ull << (bit_size - 1))     : src0 + src1)