[PATCH] D13470: Teach computeKnownBits to use new align attribute/metadata

Artur Pilipenko via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 7 09:03:13 PDT 2015


This revision was automatically updated to reflect the committed changes.
Closed by commit rL249557: Teach computeKnownBits to use new align attribute/metadata (authored by apilipenko).

Changed prior to commit:
  http://reviews.llvm.org/D13470?vs=36618&id=36750#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D13470

Files:
  llvm/trunk/lib/Analysis/ValueTracking.cpp
  llvm/trunk/test/Transforms/InstCombine/assume-redundant.ll

Index: llvm/trunk/test/Transforms/InstCombine/assume-redundant.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/assume-redundant.ll
+++ llvm/trunk/test/Transforms/InstCombine/assume-redundant.ll
@@ -47,6 +47,32 @@
   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
 
Index: llvm/trunk/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp
@@ -1415,7 +1415,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<GlobalObject>(V)) {
     Align = GO->getAlignment();
@@ -1433,16 +1433,25 @@
         }
       }
     }
-  } else if (Argument *A = dyn_cast<Argument>(V)) {
+  } else if (const Argument *A = dyn_cast<Argument>(V)) {
     Align = A->getType()->isPointerTy() ? A->getParamAlignment() : 0;
 
     if (!Align && A->hasStructRetAttr()) {
       // An sret parameter has at least the ABI alignment of the return type.
       Type *EltTy = cast<PointerType>(A->getType())->getElementType();
       if (EltTy->isSized())
         Align = DL.getABITypeAlignment(EltTy);
     }
-  }
+  } else if (const AllocaInst *AI = dyn_cast<AllocaInst>(V))
+    Align = AI->getAlignment();
+  else if (auto CS = ImmutableCallSite(V))
+    Align = CS.getAttributes().getParamAlignment(AttributeSet::ReturnIndex);
+  else if (const LoadInst *LI = dyn_cast<LoadInst>(V))
+    if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
+      ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
+      Align = CI->getLimitedValue();
+    }
+
   return Align;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13470.36750.patch
Type: text/x-patch
Size: 2528 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151007/a39f53a3/attachment.bin>


More information about the llvm-commits mailing list