Index: lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -380,8 +380,16 @@ break; case LLVMContext::MD_range: // FIXME: It would be nice to propagate this in some way, but the type - // conversions make it hard. If the new type is a pointer, we could - // translate it to !nonnull metadata. + // conversions make it hard. + + // If it's a pointer now and the range does not contain 0, make it !nonnull. + if (NewTy->isPointerTy() && N->getNumOperands() == 2) { + unsigned int BitWidth = IC.getDataLayout().getTypeSizeInBits(NewTy); + if (!getConstantRangeFromMetadata(*N).contains(APInt(BitWidth, 0))) { + MDNode *NN = MDNode::get(LI.getContext(), None); + NewLoad->setMetadata(LLVMContext::MD_nonnull, NN); + } + } break; } } @@ -1279,7 +1287,7 @@ bool InstCombiner::SimplifyStoreAtEndOfBlock(StoreInst &SI) { assert(SI.isUnordered() && "this code has not been auditted for volatile or ordered store case"); - + BasicBlock *StoreBB = SI.getParent(); // Check to see if the successor block has exactly two incoming edges. If Index: test/Transforms/InstCombine/PR30597.ll =================================================================== --- /dev/null +++ test/Transforms/InstCombine/PR30597.ll @@ -0,0 +1,25 @@ +; RUN: opt < %s -instcombine -simplifycfg -S | FileCheck %s + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; CHECK-LABEL: @dot_ref_s +; CHECK-NEXT: ret 42 + +; Function Attrs: readonly uwtable +define i32 @dot_ref_s(i32** noalias nocapture readonly dereferenceable(8)) { +entry-block: + %loadedptr = load i32*, i32** %0, align 8, !nonnull !0 + %ptrtoint = ptrtoint i32* %loadedptr to i64 + %inttoptr = inttoptr i64 %ptrtoint to i32* + %switchtmp = icmp eq i32* %inttoptr, null + br i1 %switchtmp, label %bb6, label %bb7 + +bb6: + ret i32 0 + +bb7: + ret i32 42 +} + +!0 = !{}