@@ -384,6 +384,21 @@ entry:
384384 ret i1 %nonnull
385385}
386386
387+ define i1 @test_known_nonnull_at_callsite_gep_inbounds (ptr %src , i64 %x ) {
388+ ; CHECK-LABEL: @test_known_nonnull_at_callsite_gep_inbounds(
389+ ; CHECK-NEXT: entry:
390+ ; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, ptr [[SRC:%.*]], i64 [[X:%.*]]
391+ ; CHECK-NEXT: call void @callee(ptr noundef nonnull [[GEP]])
392+ ; CHECK-NEXT: [[NONNULL:%.*]] = icmp eq ptr [[SRC]], null
393+ ; CHECK-NEXT: ret i1 false
394+ ;
395+ entry:
396+ %gep = getelementptr inbounds i8 , ptr %src , i64 %x
397+ call void @callee (ptr noundef nonnull %gep )
398+ %nonnull = icmp eq ptr %src , null
399+ ret i1 %nonnull
400+ }
401+
387402; Negative tests
388403
389404define i1 @test_known_nonnull_at_callsite_without_noundef (ptr %src ) {
@@ -412,6 +427,21 @@ entry:
412427 ret i1 %nonnull
413428}
414429
430+ define i1 @test_known_nonnull_at_callsite_gep_without_inbounds (ptr %src , i64 %x ) {
431+ ; CHECK-LABEL: @test_known_nonnull_at_callsite_gep_without_inbounds(
432+ ; CHECK-NEXT: entry:
433+ ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[SRC:%.*]], i64 [[X:%.*]]
434+ ; CHECK-NEXT: call void @callee(ptr noundef nonnull [[GEP]])
435+ ; CHECK-NEXT: [[NONNULL:%.*]] = icmp eq ptr [[SRC]], null
436+ ; CHECK-NEXT: ret i1 false
437+ ;
438+ entry:
439+ %gep = getelementptr i8 , ptr %src , i64 %x
440+ call void @callee (ptr noundef nonnull %gep )
441+ %nonnull = icmp eq ptr %src , null
442+ ret i1 %nonnull
443+ }
444+
415445declare void @callee (ptr )
416446declare void @callee2 (ptr noundef)
417447
0 commit comments