[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 (cherry picked from commit 6ae5803ffdebf1486d9a1987b818a231444cfd8d)
Welcome to the LLVM project!
This repository contains the source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and run-time environments.
The LLVM project has multiple components. The core of the project is itself called “LLVM”. This contains all of the tools, libraries, and header files needed to process intermediate representations and convert them into object files. Tools include an assembler, disassembler, bitcode analyzer, and bitcode optimizer.
C-like languages use the Clang frontend. This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM.
Other components include: the libc++ C++ standard library, the LLD linker, and more.
Consult the Getting Started with LLVM page for information on building and running LLVM.
For information on how to contribute to the LLVM project, please take a look at the Contributing to LLVM guide.
Join the LLVM Discourse forums, Discord chat, LLVM Office Hours or Regular sync-ups.
The LLVM project has adopted a code of conduct for participants to all modes of communication within the project.