Skip to content

Commit ad86d3e

Browse files
committed
[BasicAA] Add wrapping test for #72831.
Add test with GEP where the index may wrap.
1 parent e6ef315 commit ad86d3e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

llvm/test/Analysis/BasicAA/gep-modulo.ll

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,35 @@ define i8 @mul_nsw_var_nonzero_minabsvarindex_one_index(ptr %arr, i8 %x, i64 %v)
362362
ret i8 %l
363363
}
364364

365+
; FIXME: %gep and %p can alias.
366+
define i8 @test_pr72831_may_wrap(i64 %off) {
367+
; CHECK-LABEL: Function: test_pr72831_may_wrap: 2 pointers, 0 call sites
368+
; CHECK-NEXT: NoAlias: i8* %gep, i8* %p
369+
entry:
370+
%p = alloca [2 x i8], align 1
371+
%ext = zext i1 false to i64
372+
%add.1 = add nuw nsw i64 %off, 1
373+
%add.2 = add nuw nsw i64 %add.1, %ext
374+
%idx = shl i64 %add.2, 32
375+
%gep = getelementptr inbounds [2 x i8], ptr %p, i64 0, i64 %idx
376+
store i8 0, ptr %gep, align 1
377+
%l = load i8, ptr %p, align 1
378+
ret i8 %l
379+
}
380+
381+
define i8 @test_pr72831_no_wrap(i64 %off) {
382+
; CHECK-LABEL: Function: test_pr72831_no_wrap: 2 pointers, 0 call sites
383+
; CHECK-NEXT: NoAlias: i8* %gep, i8* %p
384+
entry:
385+
%p = alloca [2 x i8], align 1
386+
%ext = zext i1 false to i64
387+
%add.1 = add nuw nsw i64 %off, 1
388+
%add.2 = add nuw nsw i64 %add.1, %ext
389+
%idx = shl nsw nuw i64 %add.2, 32
390+
%gep = getelementptr inbounds [2 x i8], ptr %p, i64 0, i64 %idx
391+
store i8 0, ptr %gep, align 1
392+
%l = load i8, ptr %p, align 1
393+
ret i8 %l
394+
}
395+
365396
declare void @llvm.assume(i1)

0 commit comments

Comments
 (0)