[all-commits] [llvm/llvm-project] 6ae580: [LoongArch] Fix incorrect reciprocal sqrt estimate...
wanglei via All-commits
all-commits at lists.llvm.org
Tue Mar 24 18:59:01 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 6ae5803ffdebf1486d9a1987b818a231444cfd8d
https://github.com/llvm/llvm-project/commit/6ae5803ffdebf1486d9a1987b818a231444cfd8d
Author: wanglei <wanglei at loongson.cn>
Date: 2026-03-25 (Wed, 25 Mar 2026)
Changed paths:
M llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
M llvm/test/CodeGen/LoongArch/fsqrt-reciprocal-estimate.ll
M llvm/test/CodeGen/LoongArch/lasx/fsqrt-reciprocal-estimate.ll
M llvm/test/CodeGen/LoongArch/lsx/fsqrt-reciprocal-estimate.ll
Log Message:
-----------
[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
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list