[llvm] Support non-malloc functions in malloc+memset->calloc fold (PR #138299)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat May 3 00:52:57 PDT 2025


================
@@ -2028,9 +2028,18 @@ struct DSEState {
     if (!InnerCallee)
       return false;
     LibFunc Func;
+    std::optional<StringRef> ZeroedVariantName = std::nullopt;
     if (!TLI.getLibFunc(*InnerCallee, Func) || !TLI.has(Func) ||
-        Func != LibFunc_malloc)
-      return false;
+        Func != LibFunc_malloc) {
+      if (!Malloc->getFnAttr("alloc-variant-zeroed").isValid()) {
+        return false;
+      }
+      ZeroedVariantName =
+          Malloc->getFnAttr("alloc-variant-zeroed").getValueAsString();
----------------
nikic wrote:

Avoid duplicate getFnAttr call.

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


More information about the llvm-commits mailing list