llvm.org GIT mirror llvm / ce542fd
Revert "Properly handle multi-element and dynamically sized allocas in getPointerDereferenceableBytes()" This reverts commit 217067d5179882de9deb60d2e866befea4c126e7. Fails on llvm-clang-x86_64-expensive-checks-win git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320945 91177308-0d34-0410-b5e6-96231b3b80d8 Bjorn Steinbrink 2 years ago
3 changed file(s) with 5 addition(s) and 24 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 uint64_t getPointerDereferenceableBytes(const DataLayout &DL,
572 unsigned 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 uint64_t Value::getPointerDereferenceableBytes(const DataLayout &DL,
621 unsigned Value::getPointerDereferenceableBytes(const DataLayout &DL,
622622 bool &CanBeNull) const {
623623 assert(getType()->isPointerTy() && "must be pointer");
624624
625 uint64_t DerefBytes = 0;
625 unsigned 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 const ConstantInt *ArraySize = dyn_cast(AI->getArraySize());
658 if (ArraySize && AI->getAllocatedType()->isSized()) {
659 DerefBytes = DL.getTypeStoreSize(AI->getAllocatedType()) *
660 ArraySize->getZExtValue();
657 if (AI->getAllocatedType()->isSized()) {
658 DerefBytes = DL.getTypeStoreSize(AI->getAllocatedType());
661659 CanBeNull = false;
662660 }
663661 } else if (auto *GV = dyn_cast(this)) {
3434 ; CHECK: %alloca{{.*}}(aligned)
3535 %alloca = alloca i1
3636 %load2 = load i1, i1* %alloca
37
38 ; Load from empty array alloca
39 ; CHECK-NOT: %empty_alloca
40 %empty_alloca = alloca i8, i64 0
41 %empty_load = load i8, i8* %empty_alloca
42
43 ; Load from too small array alloca
44 ; CHECK-NOT: %small_array_alloca
45 %small_array_alloca = alloca i8, i64 2
46 %saa_cast = bitcast i8* %small_array_alloca to i32*
47 %saa_load = load i32, i32* %saa_cast
48
49 ; Load from array alloca
50 ; CHECK: %big_array_alloca{{.*}}(unaligned)
51 %big_array_alloca = alloca i8, i64 4
52 %baa_cast = bitcast i8* %big_array_alloca to i32*
53 %baa_load = load i32, i32* %baa_cast
5437
5538 ; CHECK: %dparam{{.*}}(aligned)
5639 %load3 = load i32, i32 addrspace(1)* %dparam