Index: lib/Analysis/LazyValueInfo.cpp =================================================================== --- lib/Analysis/LazyValueInfo.cpp +++ lib/Analysis/LazyValueInfo.cpp @@ -1377,8 +1377,19 @@ } } +static bool isKnownNonConstant(Value *V) { + BitCastInst *CastInst; + if (isa(V) || ((CastInst = dyn_cast(V)) && + isa(CastInst->getOperand(0)))) + return true; + return false; +} + Constant *LazyValueInfo::getConstant(Value *V, BasicBlock *BB, Instruction *CxtI) { + if (isKnownNonConstant(V)) + return nullptr; + const DataLayout &DL = BB->getModule()->getDataLayout(); LVILatticeVal Result = getCache(PImpl, AC, &DL, DT).getValueInBlock(V, BB, CxtI); @@ -1493,9 +1504,29 @@ return getPredicateResult(Pred, C, Result, DL, TLI); } +static bool isKnownNonNull(Value *V) { + BitCastInst *CastInst; + if (isa(V) || ((CastInst = dyn_cast(V)) && + isa(CastInst->getOperand(0)))) + return true; + if (isa(V) || + ((CastInst = dyn_cast(V)) && + isa(CastInst->getOperand(0)))) + return true; + return false; +} + LazyValueInfo::Tristate LazyValueInfo::getPredicateAt(unsigned Pred, Value *V, Constant *C, Instruction *CxtI) { + PointerType *Type; + if ((Type = dyn_cast(V->getType())) && + (C == ConstantPointerNull::get(Type)) && isKnownNonNull(V)) { + if (Pred == ICmpInst::ICMP_EQ) + return LazyValueInfo::False; + else if (Pred == ICmpInst::ICMP_NE) + return LazyValueInfo::True; + } const DataLayout &DL = CxtI->getModule()->getDataLayout(); LVILatticeVal Result = getCache(PImpl, AC, &DL, DT).getValueAt(V, CxtI); Tristate Ret = getPredicateResult(Pred, C, Result, DL, TLI); Index: test/CodeGen/builtins-arm.c =================================================================== --- test/CodeGen/builtins-arm.c +++ test/CodeGen/builtins-arm.c @@ -75,14 +75,14 @@ void prefetch(int i) { __builtin_arm_prefetch(&i, 0, 1); -// CHECK: call {{.*}} @llvm.prefetch(i8* %{{.*}}, i32 0, i32 3, i32 1) +// CHECK: call {{.*}} @llvm.prefetch(i8* nonnull %{{.*}}, i32 0, i32 3, i32 1) __builtin_arm_prefetch(&i, 1, 1); -// CHECK: call {{.*}} @llvm.prefetch(i8* %{{.*}}, i32 1, i32 3, i32 1) +// CHECK: call {{.*}} @llvm.prefetch(i8* nonnull %{{.*}}, i32 1, i32 3, i32 1) __builtin_arm_prefetch(&i, 1, 0); -// CHECK: call {{.*}} @llvm.prefetch(i8* %{{.*}}, i32 1, i32 3, i32 0) +// CHECK: call {{.*}} @llvm.prefetch(i8* nonnull %{{.*}}, i32 1, i32 3, i32 0) } unsigned mrc() { Index: test/CodeGen/cleanup-destslot-simple.c =================================================================== --- test/CodeGen/cleanup-destslot-simple.c +++ test/CodeGen/cleanup-destslot-simple.c @@ -13,8 +13,8 @@ return *p; // CHECK: [[X:%.*]] = alloca i32 // CHECK: [[P:%.*]] = alloca i32* -// LIFETIME: call void @llvm.lifetime.start(i64 4, i8* %{{.*}}){{( #[0-9]+)?}}, !dbg -// LIFETIME: call void @llvm.lifetime.start(i64 8, i8* %{{.*}}){{( #[0-9]+)?}}, !dbg +// LIFETIME: call void @llvm.lifetime.start(i64 4, i8* nonnull %{{.*}}){{( #[0-9]+)?}}, !dbg +// LIFETIME: call void @llvm.lifetime.start(i64 8, i8* nonnull %{{.*}}){{( #[0-9]+)?}}, !dbg // CHECK-NOT: store i32 %{{.*}}, i32* %cleanup.dest.slot // LIFETIME: call void @llvm.lifetime.end(i64 8, {{.*}}){{( #[0-9]+)?}}, !dbg // LIFETIME: call void @llvm.lifetime.end(i64 4, {{.*}}){{( #[0-9]+)?}}, !dbg Index: test/CodeGen/tbaa-struct.cpp =================================================================== --- test/CodeGen/tbaa-struct.cpp +++ test/CodeGen/tbaa-struct.cpp @@ -24,7 +24,7 @@ *a = *b; } -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* %{{.*}}, i64 24, i32 4, i1 false), !tbaa.struct [[TS2:!.*]] +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull %{{.*}}, i8* nonnull %{{.*}}, i64 24, i32 4, i1 false), !tbaa.struct [[TS2:!.*]] typedef _Complex int T2; typedef _Complex char T5; @@ -36,7 +36,7 @@ *a = *b; } -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* %{{.*}}, i64 12, i32 4, i1 false), !tbaa.struct [[TS3:!.*]] +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull %{{.*}}, i8* nonnull %{{.*}}, i64 12, i32 4, i1 false), !tbaa.struct [[TS3:!.*]] // Make sure that zero-length bitfield works. #define ATTR __attribute__ ((ms_struct)) @@ -49,7 +49,7 @@ void copy4(struct five *a, struct five *b) { *a = *b; } -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* %{{.*}}, i64 3, i32 1, i1 false), !tbaa.struct [[TS4:!.*]] +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull %{{.*}}, i8* nonnull %{{.*}}, i64 3, i32 1, i1 false), !tbaa.struct [[TS4:!.*]] struct six { char a; @@ -60,7 +60,7 @@ void copy5(struct six *a, struct six *b) { *a = *b; } -// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* %{{.*}}, i64 6, i32 1, i1 false), !tbaa.struct [[TS5:!.*]] +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull %{{.*}}, i8* nonnull %{{.*}}, i64 6, i32 1, i1 false), !tbaa.struct [[TS5:!.*]] // CHECK: [[TS]] = !{i64 0, i64 2, !{{.*}}, i64 4, i64 4, !{{.*}}, i64 8, i64 1, !{{.*}}, i64 12, i64 4, !{{.*}}} // CHECK: [[CHAR:!.*]] = !{!"omnipotent char", !{{.*}}} Index: test/CodeGenCXX/microsoft-abi-dynamic-cast.cpp =================================================================== --- test/CodeGenCXX/microsoft-abi-dynamic-cast.cpp +++ test/CodeGenCXX/microsoft-abi-dynamic-cast.cpp @@ -25,7 +25,7 @@ // CHECK-NEXT: [[VBOFFP:%.*]] = getelementptr inbounds i32, i32* [[VBTBL]], i32 1 // CHECK-NEXT: [[VBOFFS:%.*]] = load i32, i32* [[VBOFFP]], align 4 // CHECK-NEXT: [[ADJ:%.*]] = getelementptr inbounds i8, i8* [[CAST]], i32 [[VBOFFS]] -// CHECK-NEXT: [[CALL:%.*]] = tail call i8* @__RTDynamicCast(i8* [[ADJ]], i32 [[VBOFFS]], i8* bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUA@@@8" to i8*), i8* bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUT@@@8" to i8*), i32 1) +// CHECK-NEXT: [[CALL:%.*]] = tail call i8* @__RTDynamicCast(i8* nonnull [[ADJ]], i32 [[VBOFFS]], i8* bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUA@@@8" to i8*), i8* bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUT@@@8" to i8*), i32 1) // CHECK-NEXT: [[RET:%.*]] = bitcast i8* [[CALL]] to %struct.T* // CHECK-NEXT: ret %struct.T* [[RET]] @@ -39,7 +39,7 @@ // CHECK-NEXT: [[VBOFFS:%.*]] = load i32, i32* [[VBOFFP]], align 4 // CHECK-NEXT: [[DELTA:%.*]] = add nsw i32 [[VBOFFS]], 4 // CHECK-NEXT: [[ADJ:%.*]] = getelementptr inbounds i8, i8* [[VOIDP]], i32 [[DELTA]] -// CHECK-NEXT: [[CALL:%.*]] = tail call i8* @__RTDynamicCast(i8* [[ADJ]], i32 [[DELTA]], i8* bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUB@@@8" to i8*), i8* bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUT@@@8" to i8*), i32 1) +// CHECK-NEXT: [[CALL:%.*]] = tail call i8* @__RTDynamicCast(i8* nonnull [[ADJ]], i32 [[DELTA]], i8* bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUB@@@8" to i8*), i8* bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUT@@@8" to i8*), i32 1) // CHECK-NEXT: [[RET:%.*]] = bitcast i8* [[CALL]] to %struct.T* // CHECK-NEXT: ret %struct.T* [[RET]] @@ -60,7 +60,7 @@ // CHECK-NEXT: [[VBOFFP:%.*]] = getelementptr inbounds i32, i32* [[VBTBL]], i32 1 // CHECK-NEXT: [[VBOFFS:%.*]] = load i32, i32* [[VBOFFP]], align 4 // CHECK-NEXT: [[ADJ:%.*]] = getelementptr inbounds i8, i8* [[VOIDP]], i32 [[VBOFFS]] -// CHECK-NEXT: [[CALL:%.*]] = tail call i8* @__RTDynamicCast(i8* [[ADJ]], i32 [[VBOFFS]], i8* {{.*}}bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUA@@@8" to i8*), i8* {{.*}}bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUT@@@8" to i8*), i32 0) +// CHECK-NEXT: [[CALL:%.*]] = tail call i8* @__RTDynamicCast(i8* nonnull [[ADJ]], i32 [[VBOFFS]], i8* {{.*}}bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUA@@@8" to i8*), i8* {{.*}}bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUT@@@8" to i8*), i32 0) // CHECK-NEXT: [[RES:%.*]] = bitcast i8* [[CALL]] to %struct.T* // CHECK-NEXT: br label // CHECK: [[RET:%.*]] = phi %struct.T* @@ -78,7 +78,7 @@ // CHECK-NEXT: [[VBOFFS:%.*]] = load i32, i32* [[VBOFFP]], align 4 // CHECK-NEXT: [[DELTA:%.*]] = add nsw i32 [[VBOFFS]], 4 // CHECK-NEXT: [[ADJ:%.*]] = getelementptr inbounds i8, i8* [[CAST]], i32 [[DELTA]] -// CHECK-NEXT: [[CALL:%.*]] = tail call i8* @__RTDynamicCast(i8* [[ADJ]], i32 [[DELTA]], i8* {{.*}}bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUB@@@8" to i8*), i8* {{.*}}bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUT@@@8" to i8*), i32 0) +// CHECK-NEXT: [[CALL:%.*]] = tail call i8* @__RTDynamicCast(i8* nonnull [[ADJ]], i32 [[DELTA]], i8* {{.*}}bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUB@@@8" to i8*), i8* {{.*}}bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUT@@@8" to i8*), i32 0) // CHECK-NEXT: [[RES:%.*]] = bitcast i8* [[CALL]] to %struct.T* // CHECK-NEXT: br label // CHECK: [[RET:%.*]] = phi %struct.T* @@ -100,7 +100,7 @@ // CHECK-NEXT: [[VBOFFP:%.*]] = getelementptr inbounds i32, i32* [[VBTBL]], i32 1 // CHECK-NEXT: [[VBOFFS:%.*]] = load i32, i32* [[VBOFFP]], align 4 // CHECK-NEXT: [[ADJ:%.*]] = getelementptr inbounds i8, i8* [[VOIDP]], i32 [[VBOFFS]] -// CHECK-NEXT: [[RES:%.*]] = tail call i8* @__RTCastToVoid(i8* [[ADJ]]) +// CHECK-NEXT: [[RES:%.*]] = tail call i8* @__RTCastToVoid(i8* nonnull [[ADJ]]) // CHECK-NEXT: br label // CHECK: [[RET:%.*]] = phi i8* // CHECK-NEXT: ret i8* [[RET]] @@ -117,7 +117,7 @@ // CHECK-NEXT: [[VBOFFS:%.*]] = load i32, i32* [[VBOFFP]], align 4 // CHECK-NEXT: [[DELTA:%.*]] = add nsw i32 [[VBOFFS]], 4 // CHECK-NEXT: [[ADJ:%.*]] = getelementptr inbounds i8, i8* [[CAST]], i32 [[DELTA]] -// CHECK-NEXT: [[CALL:%.*]] = tail call i8* @__RTCastToVoid(i8* [[ADJ]]) +// CHECK-NEXT: [[CALL:%.*]] = tail call i8* @__RTCastToVoid(i8* nonnull [[ADJ]]) // CHECK-NEXT: br label // CHECK: [[RET:%.*]] = phi i8* // CHECK-NEXT: ret i8* [[RET]] Index: test/CodeGenCXX/microsoft-abi-typeid.cpp =================================================================== --- test/CodeGenCXX/microsoft-abi-typeid.cpp +++ test/CodeGenCXX/microsoft-abi-typeid.cpp @@ -36,7 +36,7 @@ // CHECK-NEXT: [[VBSLOT:%.*]] = getelementptr inbounds i32, i32* [[VBTBL]], i32 1 // CHECK-NEXT: [[VBASE_OFFS:%.*]] = load i32, i32* [[VBSLOT]], align 4 // CHECK-NEXT: [[ADJ:%.*]] = getelementptr inbounds i8, i8* [[THIS]], i32 [[VBASE_OFFS]] -// CHECK-NEXT: [[RT:%.*]] = tail call i8* @__RTtypeid(i8* [[ADJ]]) +// CHECK-NEXT: [[RT:%.*]] = tail call i8* @__RTtypeid(i8* nonnull [[ADJ]]) // CHECK-NEXT: [[RET:%.*]] = bitcast i8* [[RT]] to %struct.type_info* // CHECK-NEXT: ret %struct.type_info* [[RET]] Index: test/CodeGenCXX/nrvo.cpp =================================================================== --- test/CodeGenCXX/nrvo.cpp +++ test/CodeGenCXX/nrvo.cpp @@ -178,11 +178,11 @@ return a; // CHECK: [[A:%.*]] = alloca [[X:%.*]], align 8 // CHECK-NEXT: [[PTR:%.*]] = getelementptr inbounds %class.X, %class.X* [[A]], i32 0, i32 0 - // CHECK-NEXT: call void @llvm.lifetime.start(i64 1, i8* [[PTR]]) + // CHECK-NEXT: call void @llvm.lifetime.start(i64 1, i8* nonnull [[PTR]]) // CHECK-NEXT: call {{.*}} @_ZN1XC1Ev([[X]]* nonnull [[A]]) // CHECK-NEXT: call {{.*}} @_ZN1XC1ERKS_([[X]]* {{%.*}}, [[X]]* nonnull dereferenceable({{[0-9]+}}) [[A]]) // CHECK-NEXT: call {{.*}} @_ZN1XD1Ev([[X]]* nonnull [[A]]) - // CHECK-NEXT: call void @llvm.lifetime.end(i64 1, i8* [[PTR]]) + // CHECK-NEXT: call void @llvm.lifetime.end(i64 1, i8* nonnull [[PTR]]) // CHECK-NEXT: ret void } Index: test/CodeGenObjC/exceptions.m =================================================================== --- test/CodeGenObjC/exceptions.m +++ test/CodeGenObjC/exceptions.m @@ -83,7 +83,7 @@ // CHECK: [[X:%.*]] = alloca i32 // CHECK: [[XPTR:%.*]] = bitcast i32* [[X]] to i8* - // CHECK: call void @llvm.lifetime.start(i64 4, i8* [[XPTR]]) + // CHECK: call void @llvm.lifetime.start(i64 4, i8* nonnull [[XPTR]]) // CHECK: store i32 0, i32* [[X]] int x = 0; Index: test/CodeGenObjCXX/exceptions-legacy.mm =================================================================== --- test/CodeGenObjCXX/exceptions-legacy.mm +++ test/CodeGenObjCXX/exceptions-legacy.mm @@ -17,7 +17,7 @@ // CHECK: call i32 @objc_sync_enter(i8* [[OBJ:%.*]]) // CHECK: call void @objc_exception_try_enter([[BUF_T:%.*]]* nonnull [[BUF:%.*]]) // CHECK-NEXT: [[T0:%.*]] = getelementptr [[BUF_T]], [[BUF_T]]* [[BUF]], i32 0, i32 0, i32 0 -// CHECK-NEXT: [[T1:%.*]] = call i32 @_setjmp(i32* [[T0]]) +// CHECK-NEXT: [[T1:%.*]] = call i32 @_setjmp(i32* nonnull [[T0]]) // CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0 // CHECK-NEXT: br i1 [[T2]], @@ -56,7 +56,7 @@ // Enter the @try block. // CHECK: call void @objc_exception_try_enter([[BUF_T]]* nonnull [[BUF:%.*]]) // CHECK-NEXT: [[T0:%.*]] = getelementptr [[BUF_T]], [[BUF_T]]* [[BUF]], i32 0, i32 0, i32 0 -// CHECK-NEXT: [[T1:%.*]] = call i32 @_setjmp(i32* [[T0]]) +// CHECK-NEXT: [[T1:%.*]] = call i32 @_setjmp(i32* nonnull [[T0]]) // CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0 // CHECK-NEXT: br i1 [[T2]], Index: test/Transforms/CorrelatedValuePropagation/alloca.ll =================================================================== --- test/Transforms/CorrelatedValuePropagation/alloca.ll +++ test/Transforms/CorrelatedValuePropagation/alloca.ll @@ -0,0 +1,50 @@ +; RUN: opt -S -correlated-propagation -debug-only=lazy-value-info <%s 2>&1 | FileCheck %s +; +; Shortcut in Correlated Value Propagation ensures not to take Lazy Value Info +; analysis for %a.i and %tmp because %a.i is defined by alloca and %tmp is +; defined by alloca + bitcast. We know the ret value of alloca is nonnull. +; Similarly because %c is defined by getelementptr, we know %c is nonnull. +; +; CHECK-NOT: LVI Getting edge value %a.i = alloca i64, align 8 at 'for.body' +; CHECK-NOT: LVI Getting edge value %c = getelementptr inbounds i64, i64* %b, i64 0 from 'for.cond' to 'for.body' +; CHECK-NOT: LVI Getting edge value %tmp = bitcast i64* %a.i to i8* from 'for.cond' to 'for.body' +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@.str = private unnamed_addr constant [8 x i8] c"a = %l\0A\00", align 1 + +; Function Attrs: argmemonly nounwind +declare void @llvm.lifetime.start(i64, i8* nocapture) + +declare void @hoo(i64*) + +declare i32 @printf(i8* nocapture readonly, ...) + +; Function Attrs: argmemonly nounwind +declare void @llvm.lifetime.end(i64, i8* nocapture) + +define void @goo(i32 %N, i64* %b) { +entry: + %a.i = alloca i64, align 8 + %tmp = bitcast i64* %a.i to i8* + %c = getelementptr inbounds i64, i64* %b, i64 0 + br label %for.cond + +for.cond: ; preds = %for.body, %entry + %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ] + %cmp = icmp slt i32 %i.0, %N + br i1 %cmp, label %for.body, label %for.end + +for.body: ; preds = %for.cond + call void @llvm.lifetime.start(i64 8, i8* %tmp) + call void @hoo(i64* %a.i) + call void @hoo(i64* %c) + %tmp1 = load volatile i64, i64* %a.i, align 8 + %call.i = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %tmp1) + call void @llvm.lifetime.end(i64 8, i8* %tmp) + %inc = add nsw i32 %i.0, 1 + br label %for.cond + +for.end: ; preds = %for.cond + ret void +}