[PATCH] D116971: [AttributorAttributes] Remove hardcoded parameters

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 12 08:13:38 PST 2022


reames added inline comments.


================
Comment at: llvm/lib/Transforms/IPO/AttributorAttributes.cpp:5840
+
+      auto *AllocValue = getInitialValueOfAllocation(CB, TLI, CB->getType());
+      AllocationInfo::AllocationKind Kind;
----------------
Can be null in general, might be prevented by the kind precondition, might not.  Haven't looked.  


================
Comment at: llvm/lib/Transforms/IPO/AttributorAttributes.cpp:5843
+      if (AllocValue->isNullValue()) {
+        Kind = AllocationInfo::AllocationKind::AllocZeros;
+      } else if (isa<UndefValue>(AllocValue)) {
----------------
I think all you need in client code is a boolean IsZeroInit.  


================
Comment at: llvm/lib/Transforms/IPO/AttributorAttributes.cpp:5989
       // Zero out the allocated memory if it was a calloc.
-      if (AI.Kind == AllocationInfo::AllocationKind::CALLOC) {
+      if (AI.Kind == AllocationInfo::AllocationKind::AllocZeros) {
         auto *BI = new BitCastInst(Alloca, AI.CB->getType(), "calloc_bc",
----------------
I might be missing something, but I think you can simplify/generalize this code by querying the init value as an i8 before deleting the call using AI.CB, use that value in the memset, and then just check that the value being memset is not undef/poison.  (The last check is in fact optional - it's a minor compile time win.)

I think this removes the need for the whole alloc state enum, and upfront detection.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116971



More information about the llvm-commits mailing list