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 @@ -2084,7 +2084,7 @@ } // If we have a zero-sized type, the index doesn't matter. Keep looping. - if (Q.DL.getTypeAllocSize(GTI.getIndexedType()) == 0) + if (Q.DL.getTypeAllocSize(GTI.getIndexedType()).getKnownMinSize() == 0) continue; // Fast path the constant operand case both for efficiency and so we don't diff --git a/llvm/test/Transforms/InstSimplify/vscale.ll b/llvm/test/Transforms/InstSimplify/vscale.ll --- a/llvm/test/Transforms/InstSimplify/vscale.ll +++ b/llvm/test/Transforms/InstSimplify/vscale.ll @@ -133,3 +133,13 @@ %ptr = getelementptr , * null, i64 %x ret * %ptr } + +; Check GEP's result is known to be non-null. +define i1 @gep13(* %ptr) { +; CHECK-LABEL: @gep13( +; CHECK-NEXT: ret i1 false +; + %x = getelementptr inbounds , * %ptr, i32 1 + %cmp = icmp eq * %x, null + ret i1 %cmp +}