Index: lib/Analysis/ValueTracking.cpp =================================================================== --- lib/Analysis/ValueTracking.cpp +++ lib/Analysis/ValueTracking.cpp @@ -1409,7 +1409,7 @@ } } -static unsigned getAlignment(Value *V, const DataLayout &DL) { +static unsigned getAlignment(const Value *V, const DataLayout &DL) { unsigned Align = 0; if (auto *GO = dyn_cast(V)) { Align = GO->getAlignment(); @@ -1427,7 +1427,7 @@ } } } - } else if (Argument *A = dyn_cast(V)) { + } else if (const Argument *A = dyn_cast(V)) { Align = A->getType()->isPointerTy() ? A->getParamAlignment() : 0; if (!Align && A->hasStructRetAttr()) { @@ -1436,7 +1436,16 @@ if (EltTy->isSized()) Align = DL.getABITypeAlignment(EltTy); } - } + } else if (const AllocaInst *AI = dyn_cast(V)) + Align = AI->getAlignment(); + else if (auto CS = ImmutableCallSite(V)) + Align = CS.getAttributes().getParamAlignment(AttributeSet::ReturnIndex); + else if (const LoadInst *LI = dyn_cast(V)) + if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) { + ConstantInt *CI = mdconst::extract(MD->getOperand(0)); + Align = CI->getLimitedValue(); + } + return Align; } @@ -2975,20 +2984,7 @@ static bool isAligned(const Value *Base, APInt Offset, unsigned Align, const DataLayout &DL) { - APInt BaseAlign(Offset.getBitWidth(), 0); - if (const AllocaInst *AI = dyn_cast(Base)) - BaseAlign = AI->getAlignment(); - else if (const GlobalVariable *GV = dyn_cast(Base)) - BaseAlign = GV->getAlignment(); - else if (const Argument *A = dyn_cast(Base)) - BaseAlign = A->getParamAlignment(); - else if (auto CS = ImmutableCallSite(Base)) - BaseAlign = CS.getAttributes().getParamAlignment(AttributeSet::ReturnIndex); - else if (const LoadInst *LI = dyn_cast(Base)) - if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) { - ConstantInt *CI = mdconst::extract(MD->getOperand(0)); - BaseAlign = CI->getLimitedValue(); - } + APInt BaseAlign(Offset.getBitWidth(), getAlignment(Base, DL)); if (!BaseAlign) { Type *Ty = Base->getType()->getPointerElementType(); Index: test/Transforms/InstCombine/assume-redundant.ll =================================================================== --- test/Transforms/InstCombine/assume-redundant.ll +++ test/Transforms/InstCombine/assume-redundant.ll @@ -47,6 +47,20 @@ ret void } +declare align 8 i8* @get() + +; Check that redundant align assume is removed +; CHECK-LABEL: @test +; CHECK-NOT: call void @llvm.assume +define void @test() { + %p = call align 8 i8* @get() + %ptrint = ptrtoint i8* %p to i64 + %maskedptr = and i64 %ptrint, 7 + %maskcond = icmp eq i64 %maskedptr, 0 + call void @llvm.assume(i1 %maskcond) + ret void +} + ; Function Attrs: nounwind declare void @llvm.assume(i1) #1