[ValueTracking] incomplete KnownFPClass bitmask for fadd
In fadd_impl (used by computeKnownFPClass), the analysis correctly identifies cases where an fadd instruction mathematically cannot underflow. Specifically, if both operands share the same sign (e.g., both non-negative) and at least one operand is known to be a normal number, the result must be at least that normal number.
However, the current implementation only applies Known.knownNot(fcZero). It omits the subnormal classes, leaving fcPosSubnormal (or fcNegSubnormal for the negative case) in the known class mask.
Because the subnormal flag is not cleared, opt assumes expressions like fabsf(x) + 0.1f would still potentially produce subnormal values, prevents some optimizations like dead-code elimination in the simplified case below:
#include <math.h>
void process_audio_features(float *features, int n) {
for (int i = 0; i < n; i++) {
// 1. fabsf(x) makes it >= 0.0
// 2. Adding a positive normal constant (0.1f) guarantees
// the result is strictly >= 0.1f (Positive Normal or +Inf)
float signal = fabsf(features[i]) + 0.1f;
// LLVM does not assert this isn't a subnormal,
if (fpclassify(signal) == FP_SUBNORMAL) {
signal = 0.0f; // Defensive flush
}
features[i] = signal;
}
}
The if statement within the loop could be safely removed because the value can never be subnormal, but current LLVM leaves it as is: https://godbolt.org/z/d9qnYnb7j
I could patch for that. Please assign it to me.