Index: lib/Analysis/LazyValueInfo.cpp =================================================================== --- lib/Analysis/LazyValueInfo.cpp +++ lib/Analysis/LazyValueInfo.cpp @@ -222,12 +222,22 @@ if (RHS.isConstant()) { if (Val == RHS.Val) return false; + + PointerType *PT = dyn_cast(Val->getType()); + if (PT && isKnownNonNull(Val) && isKnownNonNull(RHS.Val)) + return markNotConstant(ConstantPointerNull::get(PT)); + return markOverdefined(); } if (RHS.isNotConstant()) { if (Val == RHS.Val) return markOverdefined(); + + PointerType *PT = dyn_cast(Val->getType()); + if (PT && isa(RHS.Val) && isKnownNonNull(Val)) + return markNotConstant(ConstantPointerNull::get(PT)); + return markOverdefined(); } @@ -238,6 +248,11 @@ if (RHS.isConstant()) { if (Val == RHS.Val) return markOverdefined(); + + PointerType *PT = dyn_cast(Val->getType()); + if (PT && isa(Val) && isKnownNonNull(RHS.Val)) + return false; + return markOverdefined(); } Index: test/Transforms/CorrelatedValuePropagation/select.ll =================================================================== --- test/Transforms/CorrelatedValuePropagation/select.ll +++ test/Transforms/CorrelatedValuePropagation/select.ll @@ -216,3 +216,53 @@ ; CHECK: ret i1 true ret i1 true } + +define i1 @test7(i1 %unknown, i32* nonnull %p1, i32* nonnull %p2 ) { +; CHECK-LABEL: @test7 + %sel = select i1 %unknown, i32* %p1, i32* %p2 + ;; TODO: This pointless branch shouldn't be neccessary + br label %next2 +next2: +; CHECK-LABEL: next2: +; CHECK: ret i1 true + %res = icmp ne i32* %sel, null + ret i1 %res +} +@g1 = external global i32 +@g2 = external global i32 + +define i1 @test8a(i1 %unknown, i32* nonnull %p1) { +; CHECK-LABEL: @test8 + %sel = select i1 %unknown, i32* %p1, i32* @g1 + ;; TODO: This pointless branch shouldn't be neccessary + br label %next2 +next2: +; CHECK-LABEL: next2: +; CHECK: ret i1 true + %res = icmp ne i32* %sel, null + ret i1 %res +} + +define i1 @test8b(i1 %unknown, i32* nonnull %p1) { +; CHECK-LABEL: @test8 + %sel = select i1 %unknown, i32* %p1, i32* @g1 + ;; TODO: This pointless branch shouldn't be neccessary + br label %next2 +next2: +; CHECK-LABEL: next2: +; CHECK: ret i1 true + %res = icmp ne i32* %sel, null + ret i1 %res +} + +define i1 @test9(i1 %unknown) { +; CHECK-LABEL: @test9 + %sel = select i1 %unknown, i32* @g1, i32* @g2 + ;; TODO: This pointless branch shouldn't be neccessary + br label %next2 +next2: +; CHECK-LABEL: next2: +; CHECK: ret i1 true + %res = icmp ne i32* %sel, null + ret i1 %res +}