llvm-project
6ae5803f - [LoongArch] Fix incorrect reciprocal sqrt estimate semantics (#187621)

Commit
2 days ago
[LoongArch] Fix incorrect reciprocal sqrt estimate semantics (#187621) The current implementation of getSqrtEstimate() has incorrect semantics when using `FRSQRTE`. `FRSQRTE` computes an approximation to 1/sqrt(x), but the existing code multiplies the estimate by the operand when Reciprocal is true. This results in returning sqrt(x) instead of 1/sqrt(x), effectively reversing the intended semantics of the 'Reciprocal' flag. Additionally, the implementation does not properly account for LLVM's Newton-Raphson refinement pipeline. When refinement steps are requested, the initial estimate must be in reciprocal form so that the generic DAGCombiner can apply NR iterations correctly. This patch fixes the behavior by: - Returning the raw FRSQRTE result when Reciprocal is true, or when refinement steps are required. - Only reconstructing sqrt(x) via x * rsqrt(x) when no refinement is requested. - Refactoring type checks into a helper function (isSupportedReciprocalEstimateType) for improved readability and maintainability. The updated implementation aligns with the expectations of LLVM's reciprocal estimate framework and matches the behavior of other targets such as X86 and AArch64. No functional change when reciprocal estimates are disabled, but fixes incorrect results when fast-math enables reciprocal sqrt estimates. Fixes #186328
Author
Parents
Loading