[PATCH] D16426: [NFC] LoadInst: add two helper methods: getLoadedSize and getActualAlignment.

Eduard Burtescu via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 21 12:14:36 PST 2016


eddyb created this revision.
eddyb added reviewers: mjacob, dblaikie.
eddyb added a subscriber: llvm-commits.

Depends on http://reviews.llvm.org/D16425, only commit after that.

http://reviews.llvm.org/D16426

Files:
  include/llvm/IR/Instructions.h
  lib/Analysis/MemDerefPrinter.cpp
  lib/Analysis/ValueTracking.cpp
  lib/IR/Instructions.cpp

Index: lib/IR/Instructions.cpp
===================================================================
--- lib/IR/Instructions.cpp
+++ lib/IR/Instructions.cpp
@@ -1293,6 +1293,20 @@
   assert(getAlignment() == Align && "Alignment representation error!");
 }
 
+unsigned LoadInst::getActualAlignment() const {
+  unsigned Align = getAlignment();
+  if (Align == 0) {
+    const DataLayout &DL = getModule()->getDataLayout();
+    return DL.getABITypeAlignment(getType());
+  }
+  return Align;
+}
+
+uint64_t LoadInst::getLoadedSize() const {
+  const DataLayout &DL = getModule()->getDataLayout();
+  return DL.getTypeStoreSize(getType());
+}
+
 //===----------------------------------------------------------------------===//
 //                           StoreInst Implementation
 //===----------------------------------------------------------------------===//
Index: lib/Analysis/ValueTracking.cpp
===================================================================
--- lib/Analysis/ValueTracking.cpp
+++ lib/Analysis/ValueTracking.cpp
@@ -3372,12 +3372,9 @@
             Attribute::SanitizeAddress))
       return false;
     const DataLayout &DL = LI->getModule()->getDataLayout();
-    uint64_t Size = DL.getTypeStoreSize(LI->getType());
-    unsigned Align = LI->getAlignment();
-    if (Align == 0)
-      Align = DL.getABITypeAlignment(LI->getType());
     return isDereferenceableAndAlignedPointer(
-        LI->getPointerOperand(), Size, Align, DL, CtxI, DT, TLI);
+        LI->getPointerOperand(), LI->getLoadedSize(),
+        LI->getActualAlignment(), DL, CtxI, DT, TLI);
   }
   case Instruction::Call: {
     if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst)) {
Index: lib/Analysis/MemDerefPrinter.cpp
===================================================================
--- lib/Analysis/MemDerefPrinter.cpp
+++ lib/Analysis/MemDerefPrinter.cpp
@@ -56,10 +56,8 @@
   for (auto &I: instructions(F)) {
     if (LoadInst *LI = dyn_cast<LoadInst>(&I)) {
       Value *PO = LI->getPointerOperand();
-      uint64_t Size = DL.getTypeStoreSize(LI->getType());
-      unsigned Align = LI->getAlignment();
-      if (Align == 0)
-        Align = DL.getABITypeAlignment(LI->getType());
+      uint64_t Size = LI->getLoadedSize();
+      unsigned Align = LI->getActualAlignment();
       if (isDereferenceablePointer(PO, Size, DL))
         Deref.push_back(PO);
       if (isDereferenceableAndAlignedPointer(PO, Size, Align, DL))
Index: include/llvm/IR/Instructions.h
===================================================================
--- include/llvm/IR/Instructions.h
+++ include/llvm/IR/Instructions.h
@@ -292,6 +292,12 @@
     return getPointerOperand()->getType()->getPointerAddressSpace();
   }
 
+  /// \brief Returns the explicit aligment, if present, or the ABI one.
+  unsigned getActualAlignment() const;
+
+  /// \brief Returns the size in bytes of the loaded value.
+  uint64_t getLoadedSize() const;
+
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const Instruction *I) {
     return I->getOpcode() == Instruction::Load;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16426.45582.patch
Type: text/x-patch
Size: 3103 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160121/b065ddb7/attachment.bin>


More information about the llvm-commits mailing list