BasicAA currently says that any Constant cannot alias an identified
local object. This is not correct if the local object escaped, as it's
possible to create a pointer to the escaped object using an inttoptr
constant expression base.
To compensate for this, make sure that inttoptr constant expressions are
treated as escape sources, just like inttoptr instructions. This ensures
that the optimization can still be applied if the local object is
non-escaping. This is sufficient to still optimize the original
motivating case from c53e2ecf02.
Fixes https://github.com/llvm/llvm-project/issues/76789.
50 lines
1.4 KiB
LLVM
50 lines
1.4 KiB
LLVM
; RUN: opt -passes=aa-eval -print-all-alias-modref-info -disable-output < %s 2>&1 | FileCheck %s
|
|
|
|
; CHECK: MayAlias: i8* %a, i8* %gep
|
|
define void @inttoptr_alloca() {
|
|
%a = alloca i8
|
|
%a.int = ptrtoint ptr %a to i64
|
|
%a.int.1 = add i64 %a.int, 1
|
|
%gep = getelementptr i8, ptr inttoptr (i64 -1 to ptr), i64 %a.int.1
|
|
%load = load i8, ptr %gep
|
|
store i8 1, ptr %a
|
|
ret void
|
|
}
|
|
|
|
; CHECK: MayAlias: i8* %a, i8* %gep
|
|
define void @inttoptr_alloca_unknown_relation(i64 %offset) {
|
|
%a = alloca i8
|
|
%a.int = ptrtoint ptr %a to i64
|
|
%gep = getelementptr i8, ptr inttoptr (i64 -1 to ptr), i64 %offset
|
|
%load = load i8, ptr %gep
|
|
store i8 1, ptr %a
|
|
ret void
|
|
}
|
|
|
|
; CHECK: NoAlias: i8* %a, i8* %gep
|
|
define void @inttoptr_alloca_noescape(i64 %offset) {
|
|
%a = alloca i8
|
|
%gep = getelementptr i8, ptr inttoptr (i64 -1 to ptr), i64 %offset
|
|
%load = load i8, ptr %gep
|
|
store i8 1, ptr %a
|
|
ret void
|
|
}
|
|
|
|
; CHECK: MayAlias: i8* %a, i8* %gep
|
|
define void @inttoptr_noalias(ptr noalias %a) {
|
|
%a.int = ptrtoint ptr %a to i64
|
|
%a.int.1 = add i64 %a.int, 1
|
|
%gep = getelementptr i8, ptr inttoptr (i64 -1 to ptr), i64 %a.int.1
|
|
%load = load i8, ptr %gep
|
|
store i8 1, ptr %a
|
|
ret void
|
|
}
|
|
|
|
; CHECK: NoAlias: i8* %a, i8* %gep
|
|
define void @inttoptr_noalias_noescape(ptr noalias %a, i64 %offset) {
|
|
%gep = getelementptr i8, ptr inttoptr (i64 -1 to ptr), i64 %offset
|
|
%load = load i8, ptr %gep
|
|
store i8 1, ptr %a
|
|
ret void
|
|
}
|