Correctly handle table zero entries outside int range in forward propagation
Fixes forward propagation to correctly handle table zero entries for types larger than int, preventing incorrect results from CLZ/CTZ operations.
This change corrects an issue in forward propagation where table-based zero counts for types larger than int were being truncated. The simplify_count_zeroes function previously computed zero values using int semantics, leading to incorrect results when the actual table entry exceeded int’s range. The fix ensures that these entries are correctly selected after conversion to the table’s actual type, resolving miscalculations for CLZ/CTZ operations and improving accuracy for long long types.
In Details
This commit modifies simplify_count_zeroes in tree-ssa-forwprop.cc to address an issue with CLZ and CTZ table-based optimizations when table entries for zero inputs fall outside the int range. Previously, the zero-input value was computed in int, leading to truncation and incorrect results for wider types like long long. The fix defers the selection of the zero-input value until after conversion to the table's actual element type, ensuring correctness. This impacts the accuracy of CLZ/CTZ folds, especially in forward propagation and related optimization passes.
- CLZ
- Count Leading Zeros. An intrinsic function that returns the number of zero bits preceding the most significant one bit in a binary representation.
- CTZ
- Count Trailing Zeros. An intrinsic function that returns the number of zero bits following the least significant one bit in a binary representation.
- forward propagation
- An optimization technique where values computed in one part of the code are propagated forward to be reused in later parts, potentially simplifying or eliminating redundant computations.
- SSA
- Static Single Assignment. An intermediate representation where every variable is assigned exactly once, simplifying many dataflow analyses and optimizations.