ValueTracking: use getAlignment in isAligned
authorArtur Pilipenko <apilipenko@azulsystems.com>
Fri, 9 Oct 2015 15:58:26 +0000 (15:58 +0000)
committerArtur Pilipenko <apilipenko@azulsystems.com>
Fri, 9 Oct 2015 15:58:26 +0000 (15:58 +0000)
Reviewed By: reames

Differential Revision: http://reviews.llvm.org/D13517

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249841 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ValueTracking.cpp

index 2259d871c8c0d26aa1db5934bb6005fc5e1ca782..8b0850d105e660462c5f730b7d34e1bea9a50230 100644 (file)
@@ -2998,20 +2998,7 @@ static bool isDereferenceableFromAttribute(const Value *V, const DataLayout &DL,
 
 static bool isAligned(const Value *Base, APInt Offset, unsigned Align,
                       const DataLayout &DL) {
-  APInt BaseAlign(Offset.getBitWidth(), 0);
-  if (const AllocaInst *AI = dyn_cast<AllocaInst>(Base))
-    BaseAlign = AI->getAlignment();
-  else if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Base))
-    BaseAlign = GV->getAlignment();
-  else if (const Argument *A = dyn_cast<Argument>(Base))
-    BaseAlign = A->getParamAlignment();
-  else if (auto CS = ImmutableCallSite(Base))
-    BaseAlign = CS.getAttributes().getParamAlignment(AttributeSet::ReturnIndex);
-  else if (const LoadInst *LI = dyn_cast<LoadInst>(Base))
-    if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
-      ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
-      BaseAlign = CI->getLimitedValue();
-    }
+  APInt BaseAlign(Offset.getBitWidth(), getAlignment(Base, DL));
 
   if (!BaseAlign) {
     Type *Ty = Base->getType()->getPointerElementType();