[llvm] Add constant-folding for unary NVVM intrinsics (PR #141233)
Artem Belevich via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 2 11:09:03 PDT 2025
================
@@ -1944,16 +2006,32 @@ static const APFloat FTZPreserveSign(const APFloat &V) {
return V;
}
-Constant *ConstantFoldFP(double (*NativeFP)(double), const APFloat &V,
- Type *Ty) {
+// Get only the upper word of the input double in 1.11.20 format
+// by making the lower 32-bits of the mantissa all 0.
+static const APFloat ZeroLower32Bits(const APFloat &V) {
+ assert(V.getSizeInBits(V.getSemantics()) == 64);
+ uint64_t DoubleBits = V.bitcastToAPInt().getZExtValue();
+ DoubleBits &= 0xffffffff00000000;
+ return APFloat(V.getSemantics(), APInt(64, DoubleBits, false, false));
+}
+
+Constant *ConstantFoldFP(double (*NativeFP)(double), const APFloat &V, Type *Ty,
+ bool ShouldFTZPreservingSign = false) {
----------------
Artem-B wrote:
Interesting. I wasn't aware of that. Do we need to make the parameter an enum (none, ftz, ftz-positive) then? It sounds like constant folding should change its behavior based on the `-fdenormal-fp-math`, too.
https://github.com/llvm/llvm-project/pull/141233
More information about the llvm-commits
mailing list