Mesa (main): nir/idiv_const: improve idiv(n, INT_MIN)
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Aug 9 11:39:13 UTC 2021
Module: Mesa
Branch: main
Commit: 96168301f92aa4e503a22ae83c29c8e08ea285c5
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=96168301f92aa4e503a22ae83c29c8e08ea285c5
Author: Rhys Perry <pendingchaos02 at gmail.com>
Date: Wed Jul 21 17:15:51 2021 +0100
nir/idiv_const: improve idiv(n, INT_MIN)
This lowering is smaller and -INT64_MIN is probably UB (signed overflow).
No fossil-db changes.
Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12039>
---
src/compiler/nir/nir_opt_idiv_const.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/compiler/nir/nir_opt_idiv_const.c b/src/compiler/nir/nir_opt_idiv_const.c
index 44daa793435..f94efc55991 100644
--- a/src/compiler/nir/nir_opt_idiv_const.c
+++ b/src/compiler/nir/nir_opt_idiv_const.c
@@ -65,6 +65,10 @@ build_umod(nir_builder *b, nir_ssa_def *n, uint64_t d)
static nir_ssa_def *
build_idiv(nir_builder *b, nir_ssa_def *n, int64_t d)
{
+ int64_t int_min = u_intN_min(n->bit_size);
+ if (d == int_min)
+ return nir_b2i(b, nir_ieq_imm(b, n, int_min), n->bit_size);
+
uint64_t abs_d = d < 0 ? -d : d;
if (d == 0) {
More information about the mesa-commit
mailing list