[llvm] Add constant-folding for unary NVVM intrinsics (PR #141233)
Lewis Crawford via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 2 08:39:31 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) {
----------------
LewisCrawford wrote:
In the context of NVPTX, only sign-preserving FTZ exists. However, in clang there is also an option for `-fdenormal-fp-math=positive-zero` , so I wanted to make it clear what sort of flushing was being used here, since it isn't in a target-independent file. If you think doFTZ would be fine though, I'd be happy to change to the more concise name.
https://github.com/llvm/llvm-project/pull/141233
More information about the llvm-commits
mailing list