[llvm] f3c702f - InstCombineCalls: fix annotateAnyAllocCallSite to report changes

Augie Fackler via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 7 10:49:16 PDT 2022


Author: Augie Fackler
Date: 2022-04-07T13:49:09-04:00
New Revision: f3c702fbd16a295bfbf4900c57794857f31b94ca

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

LOG: InstCombineCalls: fix annotateAnyAllocCallSite to report changes

Spotted during review of D123052.

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

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
    llvm/lib/Transforms/InstCombine/InstCombineInternal.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index d57ee6aadcc8a..6163b40e15173 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -2807,11 +2807,13 @@ static IntrinsicInst *findInitTrampoline(Value *Callee) {
   return nullptr;
 }
 
-void InstCombinerImpl::annotateAnyAllocSite(CallBase &Call, const TargetLibraryInfo *TLI) {
+bool InstCombinerImpl::annotateAnyAllocSite(CallBase &Call,
+                                            const TargetLibraryInfo *TLI) {
   // Note: We only handle cases which can't be driven from generic attributes
   // here.  So, for example, nonnull and noalias (which are common properties
   // of some allocation functions) are expected to be handled via annotation
   // of the respective allocator declaration with generic attributes.
+  bool Changed = false;
 
   if (isAllocationFn(&Call, TLI)) {
     uint64_t Size;
@@ -2819,19 +2821,22 @@ void InstCombinerImpl::annotateAnyAllocSite(CallBase &Call, const TargetLibraryI
     if (getObjectSize(&Call, Size, DL, TLI, Opts) && Size > 0) {
       // TODO: We really should just emit deref_or_null here and then
       // let the generic inference code combine that with nonnull.
-      if (Call.hasRetAttr(Attribute::NonNull))
+      if (Call.hasRetAttr(Attribute::NonNull)) {
+        Changed = !Call.hasRetAttr(Attribute::Dereferenceable);
         Call.addRetAttr(
             Attribute::getWithDereferenceableBytes(Call.getContext(), Size));
-      else
+      } else {
+        Changed = !Call.hasRetAttr(Attribute::DereferenceableOrNull);
         Call.addRetAttr(Attribute::getWithDereferenceableOrNullBytes(
             Call.getContext(), Size));
+      }
     }
   }
 
   // Add alignment attribute if alignment is a power of two constant.
   Value *Alignment = getAllocAlignment(&Call, TLI);
   if (!Alignment)
-    return;
+    return Changed;
 
   ConstantInt *AlignOpC = dyn_cast<ConstantInt>(Alignment);
   if (AlignOpC && AlignOpC->getValue().ult(llvm::Value::MaximumAlignment)) {
@@ -2842,16 +2847,16 @@ void InstCombinerImpl::annotateAnyAllocSite(CallBase &Call, const TargetLibraryI
       if (NewAlign > ExistingAlign) {
         Call.addRetAttr(
             Attribute::getWithAlignment(Call.getContext(), NewAlign));
+        Changed = true;
       }
     }
   }
+  return Changed;
 }
 
 /// Improvements for call, callbr and invoke instructions.
 Instruction *InstCombinerImpl::visitCallBase(CallBase &Call) {
-  annotateAnyAllocSite(Call, &TLI);
-
-  bool Changed = false;
+  bool Changed = annotateAnyAllocSite(Call, &TLI);
 
   // Mark any parameters that are known to be non-null with the nonnull
   // attribute.  This is helpful for inlining calls to functions with null

diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
index b6237a54ebc51..6bcae604dcf91 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -192,7 +192,7 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
                                  const Twine &Suffix = "");
 
 private:
-  void annotateAnyAllocSite(CallBase &Call, const TargetLibraryInfo *TLI);
+  bool annotateAnyAllocSite(CallBase &Call, const TargetLibraryInfo *TLI);
   bool isDesirableIntType(unsigned BitWidth) const;
   bool shouldChangeType(unsigned FromBitWidth, unsigned ToBitWidth) const;
   bool shouldChangeType(Type *From, Type *To) const;


        


More information about the llvm-commits mailing list