diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -5191,7 +5191,9 @@ } if (auto *I = dyn_cast(V)) - if (I->getMetadata(LLVMContext::MD_noundef)) + if (I->hasMetadata(LLVMContext::MD_noundef) || + I->hasMetadata(LLVMContext::MD_dereferenceable) || + I->hasMetadata(LLVMContext::MD_dereferenceable_or_null)) return true; if (programUndefinedIfUndefOrPoison(V, PoisonOnly)) diff --git a/llvm/test/Transforms/InstCombine/freeze.ll b/llvm/test/Transforms/InstCombine/freeze.ll --- a/llvm/test/Transforms/InstCombine/freeze.ll +++ b/llvm/test/Transforms/InstCombine/freeze.ll @@ -834,8 +834,7 @@ define i8* @freeze_load_dereferenceable(i8** %ptr) { ; CHECK-LABEL: @freeze_load_dereferenceable( ; CHECK-NEXT: [[P:%.*]] = load i8*, i8** [[PTR:%.*]], align 8, !dereferenceable !1 -; CHECK-NEXT: [[P_FR:%.*]] = freeze i8* [[P]] -; CHECK-NEXT: ret i8* [[P_FR]] +; CHECK-NEXT: ret i8* [[P]] ; %p = load i8*, i8** %ptr, !dereferenceable !1 %p.fr = freeze i8* %p @@ -845,8 +844,7 @@ define i8* @freeze_load_dereferenceable_or_null(i8** %ptr) { ; CHECK-LABEL: @freeze_load_dereferenceable_or_null( ; CHECK-NEXT: [[P:%.*]] = load i8*, i8** [[PTR:%.*]], align 8, !dereferenceable_or_null !1 -; CHECK-NEXT: [[P_FR:%.*]] = freeze i8* [[P]] -; CHECK-NEXT: ret i8* [[P_FR]] +; CHECK-NEXT: ret i8* [[P]] ; %p = load i8*, i8** %ptr, !dereferenceable_or_null !1 %p.fr = freeze i8* %p