Author: Bill Wendling Date: 2026-11-01T16:21:55-08:00 New Revision: 96950593da3be5385e3912fa216065515008b764
URL: https://github.com/llvm/llvm-project/commit/96950593da3be5385e3912fa216065515008b764 DIFF: https://github.com/llvm/llvm-project/commit/96950593da3be5385e3912fa216065515008b764.diff LOG: [Clang][CodeGen] Update the TBAA info for potential aliases (#236701) The stores were tagged as "unsigned long", but loads were tagged as "float". TBAA reports no aliases if the store and loads went through different pointers and GVN forwards a stale value. Fix this by giving the "store" the "omnipotent char" tag, so that TBAA treats it as aliasing every access to the destination's members. Using that tag over "Dest.getTBAAInfo()" because it doesn't depend on how CodeGenTBAA happens to tag struct and complex types. Assisted-by: Claude for testcases. Added: clang/test/CodeGen/X86/inline-asm-output-tbaa.c Modified: clang/lib/CodeGen/CGStmt.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index 05737ce071647d..347bf6b23cbc81 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -3389,7 +3389,11 @@ void AsmConstraintsInfo::EmitAsmStores( return; } - Dest = CGF.MakeAddrLValue(A, Ty); + // The store writes all of the destination's members at once, so it must + // be allowed to alias an access to any of them. A TBAA access type must + // be a scalar, so use may-alias (char), which aliases any access. + Dest = CGF.MakeAddrLValue(A, Ty, Dest.getBaseInfo(), + TBAAAccessInfo::getMayAliasInfo()); } CGF.EmitStoreThroughLValue(RValue::get(Tmp), Dest); diff --git a/clang/test/CodeGen/X86/inline-asm-output-tbaa.c b/clang/test/CodeGen/X86/inline-asm-output-tbaa.c new file mode 100644 index 00000000000000..9c6ab17d6818e0 --- /dev/null +++ b/clang/test/CodeGen/X86/inline-asm-output-tbaa.c @@ -0,0 +1,21 @@ +// REQUIRES: x86-registered-target +// Clang emits TBAA only when optimizing, so this test needs -O1. +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O1 -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s + +// A struct output with a register constraint is returned as an integer and +// stored to the destination. The store must not have the integer's TBAA tag, +// or it wouldn't alias accesses to the destination's members. + +struct S { + float a, b; +}; + +// CHECK-LABEL: define {{.*}}void @test_struct_output( +// CHECK: [[RES:%.*]] = call i64 asm "", "=r, +// CHECK-NEXT: store i64 [[RES]], ptr %{{.*}}, align 4, !tbaa [[CHAR_TAG:![0-9]+]] +void test_struct_output(struct S *p) { + asm("" : "=r"(*p)); +} + +// CHECK-DAG: [[CHAR_TAG]] = !{[[CHAR:![0-9]+]], [[CHAR]], i64 0} +// CHECK-DAG: [[CHAR]] = !{!"omnipotent char", _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
