[llvm] [SimplifyLibCalls] Constant fold nan libcall (PR #101459)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 1 00:33:43 PDT 2024


================
@@ -3858,6 +3858,22 @@ Value *LibCallSimplifier::optimizeStringMemoryLibCall(CallInst *CI,
   return nullptr;
 }
 
+/// Constant folding nan/nanf/nanl.
+static Value *optimizeNaN(CallInst *CI) {
+  StringRef CharSeq;
+  if (!getConstantStringInfo(CI->getArgOperand(0), CharSeq))
+    return nullptr;
+
+  llvm::APInt Fill;
+  // Treat empty strings as if they were zero.
+  if (CharSeq.empty())
+    Fill = llvm::APInt(32, 0);
----------------
nikic wrote:

```suggestion
    Fill = APInt(32, 0);
```

https://github.com/llvm/llvm-project/pull/101459


More information about the llvm-commits mailing list