From: Artur Pilipenko Date: Wed, 7 Oct 2015 16:01:18 +0000 (+0000) Subject: Teach computeKnownBits to use new align attribute/metadata X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=d929b8a4bbd6a496f2a0ba51d4e5ea7818eb9762;p=oota-llvm.git Teach computeKnownBits to use new align attribute/metadata Reviewed By: reames Differential Revision: http://reviews.llvm.org/D13470 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249557 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp index d3723037dda..d8a449193a3 100644 --- a/lib/Analysis/ValueTracking.cpp +++ b/lib/Analysis/ValueTracking.cpp @@ -1415,7 +1415,7 @@ static void computeKnownBitsFromOperator(Operator *I, APInt &KnownZero, } } -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(); @@ -1433,7 +1433,7 @@ static unsigned getAlignment(Value *V, const DataLayout &DL) { } } } - } 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()) { @@ -1442,7 +1442,16 @@ static unsigned getAlignment(Value *V, const DataLayout &DL) { 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; } diff --git a/test/Transforms/InstCombine/assume-redundant.ll b/test/Transforms/InstCombine/assume-redundant.ll index 4b869ef2c50..4bdbcc8d086 100644 --- a/test/Transforms/InstCombine/assume-redundant.ll +++ b/test/Transforms/InstCombine/assume-redundant.ll @@ -47,6 +47,32 @@ for.end: ; preds = %for.body 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 @test1() { + %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 +} + +; Check that redundant align assume is removed +; CHECK-LABEL: @test +; CHECK-NOT: call void @llvm.assume +define void @test3() { + %p = alloca i8, align 8 + %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