[llvm] f120be6 - InstCombineCalls: when adding an align attribute, never reduce it

Augie Fackler via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 7 09:38:56 PDT 2022


Author: Augie Fackler
Date: 2022-04-07T12:38:44-04:00
New Revision: f120be6c86dfc7a3b0978ae8765076acec1ea0b3

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

LOG: InstCombineCalls: when adding an align attribute, never reduce it

Sometimes we can infer an align from an allocalign but the function
already promised it'd be more-aligned than the allocalign and there's an
existing align that we shouldn't reduce. Make sure we handle that
correctly.

Differential Revision: https://reviews.llvm.org/D121642

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
    llvm/test/Transforms/InstCombine/InferAlignAttribute.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index cf44ee057783b..d57ee6aadcc8a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -2837,9 +2837,12 @@ void InstCombinerImpl::annotateAnyAllocSite(CallBase &Call, const TargetLibraryI
   if (AlignOpC && AlignOpC->getValue().ult(llvm::Value::MaximumAlignment)) {
     uint64_t AlignmentVal = AlignOpC->getZExtValue();
     if (llvm::isPowerOf2_64(AlignmentVal)) {
-      Call.removeRetAttr(Attribute::Alignment);
-      Call.addRetAttr(Attribute::getWithAlignment(Call.getContext(),
-                                                  Align(AlignmentVal)));
+      Align ExistingAlign = Call.getRetAlign().valueOrOne();
+      Align NewAlign = Align(AlignmentVal);
+      if (NewAlign > ExistingAlign) {
+        Call.addRetAttr(
+            Attribute::getWithAlignment(Call.getContext(), NewAlign));
+      }
     }
   }
 }

diff  --git a/llvm/test/Transforms/InstCombine/InferAlignAttribute.ll b/llvm/test/Transforms/InstCombine/InferAlignAttribute.ll
index cf94c195c6731..fc0c1e02c86b6 100644
--- a/llvm/test/Transforms/InstCombine/InferAlignAttribute.ll
+++ b/llvm/test/Transforms/InstCombine/InferAlignAttribute.ll
@@ -26,12 +26,10 @@ entry:
   ret i8* %call
 }
 
-; BUG: we shouldn't narrow this alignment since we already had a stronger
-; constraint, but we do.
 define i8* @dont_narrow_align_from_allocalign() {
 ; CHECK-LABEL: @dont_narrow_align_from_allocalign(
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:    [[CALL:%.*]] = tail call align 8 i8* @my_aligned_alloc(i32 noundef 320, i32 noundef 8)
+; CHECK-NEXT:    [[CALL:%.*]] = tail call align 16 i8* @my_aligned_alloc(i32 noundef 320, i32 noundef 8)
 ; CHECK-NEXT:    ret i8* [[CALL]]
 ;
 entry:


        


More information about the llvm-commits mailing list