diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -3194,7 +3194,8 @@ ->getType() ->getPointerAddressSpace()))) { Value *V = CS->getArgOperand(Idx); - + if (isa(*V)) + continue; Builder.SetInsertPoint(I->getParent(), I->getIterator()); Builder.CreateAssumption(Builder.CreateIsNotNull(V)); } diff --git a/llvm/test/Transforms/InstCombine/assume-replacing-call.ll b/llvm/test/Transforms/InstCombine/assume-replacing-call.ll --- a/llvm/test/Transforms/InstCombine/assume-replacing-call.ll +++ b/llvm/test/Transforms/InstCombine/assume-replacing-call.ll @@ -183,6 +183,30 @@ ret i32 %retval.0 } +define i64 @test_sink_undef(i1 %c, i64 %x) { +; Check that we don't insert a nonnull assumption for undef. +; CHECK-LABEL: @test_sink_undef( +; CHECK-NEXT: entry: +; CHECK-NOT: @llvm.assume( +; CHECK: br i1 %c, label %ctrue, label %cend +; CHECK: ctrue: +; CHECK-NEXT: %foo = call i64 @func_test_nonnull(i8* undef) +; CHECK-NEXT: br label %cend +; CHECK: cend: +; CHECK-NEXT: %retval = phi i64 [ %x, %entry ], [ %foo, %ctrue ] +; CHECK-NEXT: ret i64 %retval +entry: + %foo = call i64 @func_test_nonnull(i8* undef) #2 + br i1 %c, label %ctrue, label %cend + +ctrue: + br label %cend + +cend: + %retval = phi i64 [%x, %entry], [%foo, %ctrue] + ret i64 %retval +} + declare i64 @func_test(i8* %0) #1 declare i64 @func_test_nonnull(i8* nonnull %0) #3