diff --git a/llvm/lib/Transforms/Utils/SCCPSolver.cpp b/llvm/lib/Transforms/Utils/SCCPSolver.cpp --- a/llvm/lib/Transforms/Utils/SCCPSolver.cpp +++ b/llvm/lib/Transforms/Utils/SCCPSolver.cpp @@ -1600,12 +1600,8 @@ Constant *Ptr = getConstant(PtrVal, I.getOperand(0)->getType()); // load null is undefined. - if (isa(Ptr)) { - if (NullPointerIsDefined(I.getFunction(), I.getPointerAddressSpace())) - return (void)markOverdefined(IV, &I); - else - return; - } + if (isa(Ptr)) + return (void)markOverdefined(IV, &I); // Transform load (constant global) into the value loaded. if (auto *GV = dyn_cast(Ptr)) { diff --git a/llvm/test/Transforms/PhaseOrdering/load-from-null.ll b/llvm/test/Transforms/PhaseOrdering/load-from-null.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/PhaseOrdering/load-from-null.ll @@ -0,0 +1,24 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2 +; RUN: opt -O1 -S < %s | FileCheck %s +; RUN: opt -O2 -S < %s | FileCheck %s +; RUN: opt -O3 -S < %s | FileCheck %s +; +define void @load_invalid_address(ptr %p, i1 %a) { +; CHECK-LABEL: define void @load_invalid_address +; CHECK-SAME: (ptr nocapture readnone [[P:%.*]], i1 [[A:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { +; CHECK-NEXT: entry: +; CHECK-NEXT: unreachable +; +entry: + br i1 %a, label %if.then, label %if.else + +if.else: + br label %if.then + +if.then: ; preds = %lbl, %for.cond1 + %e.2 = phi ptr [ undef, %entry ], [ null, %if.else ] + %0 = load i32, ptr %e.2, align 4 + store i32 %0, ptr %p + ret void + +}