[PATCH] D103009: [DSE] Transform memset + malloc --> calloc (PR25892)

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 15 03:08:55 PDT 2021


xbolva00 added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp:1843
+            return false;
+          if (Malloc->getOperand(0) == MemSet->getLength()) {
+            if (DT.dominates(DefUOInst, MemSet) &&
----------------
We dont need this check, do we?

p = malloc(20)
memset(p, 0, 10)

Reading p between 10 and 20 is UB, so with calloc we would have 0s in this area so fine.

And reverse case is UB too.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103009/new/

https://reviews.llvm.org/D103009



More information about the llvm-commits mailing list