[llvm] 9979299 - [Attributor] Simplify how we handle required alignment during heap-to-stack [NFC]

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 12 17:34:29 PST 2022


Author: Philip Reames
Date: 2022-01-12T17:34:17-08:00
New Revision: 9979299705817c90ef7e4928ba1fb10243cecb67

URL: https://github.com/llvm/llvm-project/commit/9979299705817c90ef7e4928ba1fb10243cecb67
DIFF: https://github.com/llvm/llvm-project/commit/9979299705817c90ef7e4928ba1fb10243cecb67.diff

LOG: [Attributor] Simplify how we handle required alignment during heap-to-stack [NFC]

The existing code duplicated the same concern in two places, and (weirdly) changed the inference of the allocation size based on whether we could meet the alignment requirement.  Instead, just directly check the allocation requirement.

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index d0534ed0e635..33e567b2fcb2 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -6022,10 +6022,7 @@ struct AAHeapToStackFunction final : public AAHeapToStack {
       return getAPInt(A, AA, *AI.CB->getArgOperand(0));
 
     if (AI.Kind == AllocationInfo::AllocationKind::ALIGNED_ALLOC)
-      // Only if the alignment is also constant we return a size.
-      return getAPInt(A, AA, *AI.CB->getArgOperand(0)).hasValue()
-                 ? getAPInt(A, AA, *AI.CB->getArgOperand(1))
-                 : llvm::None;
+      return getAPInt(A, AA, *AI.CB->getArgOperand(1));
 
     assert(AI.Kind == AllocationInfo::AllocationKind::CALLOC &&
            "Expected only callocs are left");
@@ -6267,23 +6264,24 @@ ChangeStatus AAHeapToStackFunction::updateImpl(Attributor &A) {
     if (AI.Status == AllocationInfo::INVALID)
       continue;
 
-    if (MaxHeapToStackSize == -1) {
-      if (AI.Kind == AllocationInfo::AllocationKind::ALIGNED_ALLOC) {
-        Value *Align = getAllocAlignment(AI.CB, TLI);
-        if (!Align || !getAPInt(A, *this, *Align)) {
-          LLVM_DEBUG(dbgs() << "[H2S] Unknown allocation alignment: " << *AI.CB
-                            << "\n");
-          AI.Status = AllocationInfo::INVALID;
-          Changed = ChangeStatus::CHANGED;
-          continue;
-        }
+    if (Value *Align = getAllocAlignment(AI.CB, TLI)) {
+      if (!getAPInt(A, *this, *Align)) {
+        // Can't generate an alloca which respects the required alignment
+        // on the allocation.
+        LLVM_DEBUG(dbgs() << "[H2S] Unknown allocation alignment: " << *AI.CB
+                          << "\n");
+        AI.Status = AllocationInfo::INVALID;
+        Changed = ChangeStatus::CHANGED;
+        continue;
       }
-    } else {
+    }
+
+    if (MaxHeapToStackSize != -1) {
       Optional<APInt> Size = getSize(A, *this, AI);
       if (!Size.hasValue() || Size.getValue().ugt(MaxHeapToStackSize)) {
         LLVM_DEBUG({
           if (!Size.hasValue())
-            dbgs() << "[H2S] Unknown allocation size (or alignment): " << *AI.CB
+            dbgs() << "[H2S] Unknown allocation size: " << *AI.CB
                    << "\n";
           else
             dbgs() << "[H2S] Allocation size too large: " << *AI.CB << " vs. "


        


More information about the llvm-commits mailing list