Skip to content

[TBAA] Emit "omnipotent char" for intrinsics with type cast #107793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions clang/lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10155,6 +10155,11 @@ Value *CodeGenFunction::EmitSVEMaskedLoad(const CallExpr *E,
auto *Load =
cast<llvm::Instruction>(Builder.CreateCall(F, {Predicate, BasePtr}));
auto TBAAInfo = CGM.getTBAAAccessInfo(LangPTy->getPointeeType());
if (auto *CastE = dyn_cast<CastExpr>(E->getArg(1))) {
CastKind CK = CastE->getCastKind();
if (CK == CK_BitCast)
TBAAInfo = CGM.genConservativeTBAA(LangPTy->getPointeeType());
}
CGM.DecorateInstructionWithTBAA(Load, TBAAInfo);

if (IsQuadLoad)
Expand Down Expand Up @@ -10207,6 +10212,11 @@ Value *CodeGenFunction::EmitSVEMaskedStore(const CallExpr *E,
auto *Store =
cast<llvm::Instruction>(Builder.CreateCall(F, {Val, Predicate, BasePtr}));
auto TBAAInfo = CGM.getTBAAAccessInfo(LangPTy->getPointeeType());
if (auto *CastE = dyn_cast<CastExpr>(E->getArg(1))) {
CastKind CK = CastE->getCastKind();
if (CK == CK_BitCast)
TBAAInfo = CGM.genConservativeTBAA(LangPTy->getPointeeType());
}
CGM.DecorateInstructionWithTBAA(Store, TBAAInfo);
return Store;
}
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,10 @@ TBAAAccessInfo CodeGenModule::getTBAAAccessInfo(QualType AccessType) {
return TBAA->getAccessInfo(AccessType);
}

TBAAAccessInfo CodeGenModule::genConservativeTBAA(QualType AccessType) {
return TBAA->genConservativeTBAA(AccessType);
}

TBAAAccessInfo
CodeGenModule::getTBAAVTablePtrAccessInfo(llvm::Type *VTablePtrType) {
if (!TBAA)
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/CodeGen/CodeGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,8 @@ class CodeGenModule : public CodeGenTypeCache {
/// an object of the given type.
TBAAAccessInfo getTBAAAccessInfo(QualType AccessType);

TBAAAccessInfo genConservativeTBAA(QualType AccessType);

/// getTBAAVTablePtrAccessInfo - Get the TBAA information that describes an
/// access to a virtual table pointer.
TBAAAccessInfo getTBAAVTablePtrAccessInfo(llvm::Type *VTablePtrType);
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/CodeGen/CodeGenTBAA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ llvm::MDNode *CodeGenTBAA::getTypeInfo(QualType QTy) {
return MetadataCache[Ty] = TypeNode;
}

TBAAAccessInfo CodeGenTBAA::genConservativeTBAA(QualType AccessType) {
uint64_t Size = Context.getTypeSizeInChars(AccessType).getQuantity();
return TBAAAccessInfo(getChar(), Size);
}

TBAAAccessInfo CodeGenTBAA::getAccessInfo(QualType AccessType) {
// Pointee values may have incomplete types, but they shall never be
// dereferenced.
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/CodeGen/CodeGenTBAA.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ class CodeGenTBAA {
/// purpose of memory transfer calls.
TBAAAccessInfo mergeTBAAInfoForMemoryTransfer(TBAAAccessInfo DestInfo,
TBAAAccessInfo SrcInfo);

TBAAAccessInfo genConservativeTBAA(QualType AccessType);
};

} // end namespace CodeGen
Expand Down
17 changes: 17 additions & 0 deletions clang/test/CodeGen/tbaa-sve-store-acle.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -O1 %s \
// RUN: -emit-llvm -o - | FileCheck %s -check-prefix=TBAA
#include <arm_sve.h>

// TBAA: store <vscale x 2 x i64>
// TBAA: !tbaa ![[TBAA6:[0-9]+]]
long long sveStoreWithTypeCast(int *datas) {
long long res2[16];
svbool_t pa = svptrue_b32();
svint32_t v1 = svld1(pa, &datas[0]);
svint64_t v2 = svunpklo(v1);
svst1(pa, (long *)&res2[0], v2);
return res2[0] + res2[1];
}

// TBAA: ![[CHAR:[0-9]+]] = !{!"omnipotent char",
// TBAA: ![[TBAA6:[0-9]+]] = !{![[CHAR]], ![[CHAR]], i64 0}
Loading