llvm-project/llvm/test/Analysis/BasicAA/inttoptr_constexpr.ll
Nikita Popov 5f57ad85a1
[BasicAA] Remove incorrect rule about constant pointers (#76815)
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 c53e2ecf0296a55d3c33c19fb70a3aa7f81f2732.

Fixes https://github.com/llvm/llvm-project/issues/76789.
2024-01-17 09:31:00 +01:00

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
}