[llvm] [AMDGPU] Constant fold FMAD_FTZ (PR #69443)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 19 03:56:49 PDT 2023
================
@@ -5047,11 +5047,24 @@ SDValue AMDGPUTargetLowering::PerformDAGCombine(SDNode *N,
SDValue N2 = N->getOperand(2);
EVT VT = N->getValueType(0);
- // FMAD_FTZ is a FMAD, but flushing to zero is allowed (not required).
- // if all operands are constant we can just constant-fold it like a FMAD.
- if (isa<ConstantFPSDNode>(N0) && isa<ConstantFPSDNode>(N1) &&
- isa<ConstantFPSDNode>(N2))
- return DAG.getNode(ISD::FMAD, DL, VT, {N0, N1, N2});
+ // FMAD_FTZ is a FMAD + flush denormals to zero.
+ // We flush the inputs, the intermediate step, and the output.
+ ConstantFPSDNode *N0CFP = dyn_cast<ConstantFPSDNode>(N0);
+ ConstantFPSDNode *N1CFP = dyn_cast<ConstantFPSDNode>(N1);
+ ConstantFPSDNode *N2CFP = dyn_cast<ConstantFPSDNode>(N2);
+ if (N0CFP && N1CFP && N2CFP) {
+ const auto FTZ = [](const APFloat &V) {
+ return V.isDenormal() ? APFloat(V.getSemantics(), 0) : V;
----------------
jayfoad wrote:
I think mad/mac flushing preserves sign, doesn't it? So -denormal should flush to -0.
https://github.com/llvm/llvm-project/pull/69443
More information about the llvm-commits
mailing list