diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -6843,7 +6843,7 @@ if (llvm::isKnownNonZero(V, DL)) MinVal = Align; ConservativeResult = ConservativeResult.intersectWith( - {MinVal, MaxVal + 1}, RangeType); + ConstantRange::getNonEmpty(MinVal, MaxVal + 1), RangeType); } } diff --git a/llvm/test/Analysis/ScalarEvolution/malloc.ll b/llvm/test/Analysis/ScalarEvolution/malloc.ll --- a/llvm/test/Analysis/ScalarEvolution/malloc.ll +++ b/llvm/test/Analysis/ScalarEvolution/malloc.ll @@ -23,4 +23,15 @@ ret ptr %alloc } +define ptr @undefined_max() { +; CHECK-LABEL: 'undefined_max' +; CHECK-NEXT: Classifying expressions for: @undefined_max +; CHECK-NEXT: %alloc = call nonnull ptr @malloc(i64 -1) +; CHECK-NEXT: --> %alloc U: full-set S: full-set +; CHECK-NEXT: Determining loop execution counts for: @undefined_max +; + %alloc = call nonnull ptr @malloc(i64 -1) + ret ptr %alloc +} + declare noalias noundef ptr @malloc(i64 noundef) allockind("alloc,uninitialized") allocsize(0)