llvm.org GIT mirror llvm / 217067d
Properly handle multi-element and dynamically sized allocas in getPointerDereferenceableBytes() Reviewers: hfinkel, rnk Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D41288 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320938 91177308-0d34-0410-b5e6-96231b3b80d8 Bjorn Steinbrink 2 years ago
3 changed file(s) with 24 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
569569 ///
570570 /// If CanBeNull is set by this function the pointer can either be null or be
571571 /// dereferenceable up to the returned number of bytes.
572 unsigned getPointerDereferenceableBytes(const DataLayout &DL,
572 uint64_t getPointerDereferenceableBytes(const DataLayout &DL,
573573 bool &CanBeNull) const;
574574
575575 /// \brief Returns an alignment of the pointer value.
618618 return stripPointerCastsAndOffsets(this);
619619 }
620620
621 unsigned Value::getPointerDereferenceableBytes(const DataLayout &DL,
621 uint64_t Value::getPointerDereferenceableBytes(const DataLayout &DL,
622622 bool &CanBeNull) const {
623623 assert(getType()->isPointerTy() && "must be pointer");
624624
625 unsigned DerefBytes = 0;
625 uint64_t DerefBytes = 0;
626626 CanBeNull = false;
627627 if (const Argument *A = dyn_cast(this)) {
628628 DerefBytes = A->getDereferenceableBytes();
654654 CanBeNull = true;
655655 }
656656 } else if (auto *AI = dyn_cast(this)) {
657 if (AI->getAllocatedType()->isSized()) {
658 DerefBytes = DL.getTypeStoreSize(AI->getAllocatedType());
657 const ConstantInt *ArraySize = dyn_cast(AI->getArraySize());
658 if (ArraySize && AI->getAllocatedType()->isSized()) {
659 DerefBytes = DL.getTypeStoreSize(AI->getAllocatedType()) *
660 ArraySize->getZExtValue();
659661 CanBeNull = false;
660662 }
661663 } else if (auto *GV = dyn_cast(this)) {
3232 ; CHECK: %alloca{{.*}}(aligned)
3333 %alloca = alloca i1
3434 %load2 = load i1, i1* %alloca
35
36 ; Load from empty array alloca
37 ; CHECK-NOT: %empty_alloca
38 %empty_alloca = alloca i8, i64 0
39 %empty_load = load i8, i8* %empty_alloca
40
41 ; Load from too small array alloca
42 ; CHECK-NOT: %small_array_alloca
43 %small_array_alloca = alloca i8, i64 2
44 %saa_cast = bitcast i8* %small_array_alloca to i32*
45 %saa_load = load i32, i32* %saa_cast
46
47 ; Load from array alloca
48 ; CHECK: %big_array_alloca{{.*}}(unaligned)
49 %big_array_alloca = alloca i8, i64 4
50 %baa_cast = bitcast i8* %big_array_alloca to i32*
51 %baa_load = load i32, i32* %baa_cast
3552
3653 ; CHECK: %dparam{{.*}}(aligned)
3754 %load3 = load i32, i32 addrspace(1)* %dparam