nir: rewrite fp range analysis as a fp class analysis

Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.

Separating positive and negative zero also has advantages when
signed zero correctness is required.

Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
This commit is contained in:
Georg Lehmann 2026-02-08 23:03:16 +01:00 committed by Marge Bot
parent 32b5719a9f
commit 5a298f3560
2 changed files with 873 additions and 916 deletions

File diff suppressed because it is too large Load diff

View file

@ -68,6 +68,40 @@ nir_fp_analysis_state nir_create_fp_analysis_state(nir_function_impl *impl);
void nir_invalidate_fp_analysis_state(nir_fp_analysis_state *state);
void nir_free_fp_analysis_state(nir_fp_analysis_state *state);
enum fp_class_bit {
FP_CLASS_NEG_INF = BITFIELD_BIT(0),
FP_CLASS_LT_NEG_ONE = BITFIELD_BIT(1),
FP_CLASS_NEG_ONE = BITFIELD_BIT(2),
FP_CLASS_LT_ZERO_GT_NEG_ONE = BITFIELD_BIT(3),
FP_CLASS_NEG_ZERO = BITFIELD_BIT(4),
FP_CLASS_POS_ZERO = BITFIELD_BIT(5),
FP_CLASS_GT_ZERO_LT_POS_ONE = BITFIELD_BIT(6),
FP_CLASS_POS_ONE = BITFIELD_BIT(7),
FP_CLASS_GT_POS_ONE = BITFIELD_BIT(8),
FP_CLASS_POS_INF = BITFIELD_BIT(9),
FP_CLASS_NAN = BITFIELD_BIT(10),
/**
* A floating-point value that can have non integer (fractional) values.
* Does not replace any of the values above.
*/
FP_CLASS_NON_INTEGRAL = BITFIELD_BIT(11),
};
#define FP_CLASS_UNKNOWN BITFIELD_MASK(12)
#define FP_CLASS_ANY_ZERO (FP_CLASS_NEG_ZERO | FP_CLASS_POS_ZERO)
#define FP_CLASS_ANY_INF (FP_CLASS_NEG_INF | FP_CLASS_POS_INF)
#define FP_CLASS_ANY_NEG_FINITE (FP_CLASS_LT_ZERO_GT_NEG_ONE | FP_CLASS_NEG_ONE | FP_CLASS_LT_NEG_ONE)
#define FP_CLASS_ANY_NEG (FP_CLASS_ANY_NEG_FINITE | FP_CLASS_NEG_INF)
#define FP_CLASS_ANY_POS_FINITE (FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_POS_ONE | FP_CLASS_GT_POS_ONE)
#define FP_CLASS_ANY_POS (FP_CLASS_ANY_POS_FINITE | FP_CLASS_POS_INF)
#define FP_CLASS_ANY_FINITE (FP_CLASS_ANY_NEG_FINITE | FP_CLASS_ANY_ZERO | FP_CLASS_ANY_POS_FINITE)
#define FP_CLASS_ANY_NUMBER (FP_CLASS_ANY_FINITE | FP_CLASS_ANY_INF)
typedef uint16_t fp_class_mask;
fp_class_mask nir_analyze_fp_class(nir_fp_analysis_state *state, const nir_def *def);
struct fp_result_range
nir_analyze_fp_range(nir_fp_analysis_state *state, const nir_def *def);