From 3da23a9c7e6f34ea50c1ba415991c7ff1b443ef6 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 30 Jun 2021 18:16:55 -0400 Subject: [PATCH] nir: Fix constant folding for irhadd/urhadd This should be a subtract, not an add. The comment's proof is correct, but the (wrong) expression we actually use isn't what it's in the comment! Correct the discrepancy. The lowering in nir_opt_algebraic was correctly typed. Fixes: 272e927d0e9 ("nir/spirv: initial handling of OpenCL.std extension opcodes") Signed-off-by: Alyssa Rosenzweig Reviewed-by: Jason Ekstrand Reviewed-by: Karol Herbst Part-of: --- src/compiler/nir/nir_opcodes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/nir/nir_opcodes.py b/src/compiler/nir/nir_opcodes.py index 42bcfb66569..9202a2e5398 100644 --- a/src/compiler/nir/nir_opcodes.py +++ b/src/compiler/nir/nir_opcodes.py @@ -770,8 +770,8 @@ binop("uhadd", tuint, _2src_commutative, "(src0 & src1) + ((src0 ^ src1) >> 1)") # # (x + y + 1) >> 1 = (x | y) + (-(x ^ y) + 1) >> 1) # = (x | y) - ((x ^ y) >> 1) -binop("irhadd", tint, _2src_commutative, "(src0 | src1) + ((src0 ^ src1) >> 1)") -binop("urhadd", tuint, _2src_commutative, "(src0 | src1) + ((src0 ^ src1) >> 1)") +binop("irhadd", tint, _2src_commutative, "(src0 | src1) - ((src0 ^ src1) >> 1)") +binop("urhadd", tuint, _2src_commutative, "(src0 | src1) - ((src0 ^ src1) >> 1)") binop("umod", tuint, "", "src1 == 0 ? 0 : src0 % src1")