[llvm] [AMDGPU] Flush denormal results when constant folding amdgcn.rcp (PR #203566)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 12 08:35:16 PDT 2026
================
@@ -1130,10 +1130,21 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
APFloat Val(ArgVal.getSemantics(), 1);
Val.divide(ArgVal, APFloat::rmNearestTiesToEven);
- // This is more precise than the instruction may give.
- //
- // TODO: The instruction always flushes denormal results (except for f16),
- // should this also?
+ // v_rcp_f32/f64 flush denormal results to zero (preserving sign); only
+ // f16 always keeps them. Match the hardware so the fold cannot emit a
+ // denormal the instruction wouldn't.
+ const fltSemantics &Sem = Val.getSemantics();
+ if (Val.isDenormal() && &Sem != &APFloat::IEEEhalf()) {
+ DenormalMode Mode = II.getFunction()->getDenormalMode(Sem);
+ if (Mode.Output == DenormalMode::PreserveSign)
+ Val = APFloat::getZero(Sem, Val.isNegative());
+ else if (Mode.Output == DenormalMode::PositiveZero)
----------------
arsenm wrote:
We do not have a positive zero mode and this should be ignored
https://github.com/llvm/llvm-project/pull/203566
More information about the llvm-commits
mailing list