Handle scalar CLZ/CTZ calls with zero argument correctly
Ensures scalar CLZ/CTZ intrinsic calls handle the zero argument case according to target-specific behavior.
This commit improves the handling of scalar __builtin_clzg and __builtin_ctzg calls when the argument is zero. Previously, the intrinsic expansion sometimes ignored the second argument (the expected value at zero), leading to incorrect results on certain targets or with specific compiler transformations. The fix introduces a check to compare the provided zero-value with the target’s actual behavior, ensuring the correct result is emitted, particularly for targets like GCN and x86, and for bit-integer types.
In Details
This commit addresses issues in expand_clz_ctz related to scalar CLZ/CTZ intrinsic calls where the second argument (the value at zero) was not correctly handled or was ignored. This occurred in various scenarios including offload compilation, target-clones with -mlzcnt, _BitInt lowerings, and loop iteration analysis. The change implements a check to compare the intrinsic's C?Z_DEFINED_VALUE_AT_ZERO behavior with the provided second argument. If they differ, it ensures the instruction is executed only for non-zero inputs, or the correct value is selected, aligning with target-speci…
- 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.
- SSA
- Static Single Assignment. An intermediate representation where every variable is assigned exactly once, simplifying many dataflow analyses and optimizations.
- intrinsic
- A function that is directly supported by the compiler, often mapping to a specific machine instruction or a highly optimized code sequence.