Skip to content

Commit 3b6e250

Browse files
authored
[TBAA] Only clear TBAAStruct if field can be extracted. (llvm#81285)
Retain TBAAStruct if we fail to match the access to a single field. All users at the moment use this when using the full size of the original access. SROA also retains the original TBAAStruct when accessing parts at offset 0. Motivation for this and follow-on patches is to improve codegen for libc++, where using memcpy limits optimizations, like vectorization for code iteration over std::vector<std::complex<float>>: https://godbolt.org/z/f3vqYos3c Depends on llvm#81284
1 parent 92ef408 commit 3b6e250

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,14 +821,15 @@ MDNode *AAMDNodes::extendToTBAA(MDNode *MD, ssize_t Len) {
821821
AAMDNodes AAMDNodes::adjustForAccess(unsigned AccessSize) {
822822
AAMDNodes New = *this;
823823
MDNode *M = New.TBAAStruct;
824-
New.TBAAStruct = nullptr;
825824
if (M && M->getNumOperands() == 3 && M->getOperand(0) &&
826825
mdconst::hasa<ConstantInt>(M->getOperand(0)) &&
827826
mdconst::extract<ConstantInt>(M->getOperand(0))->isZero() &&
828827
M->getOperand(1) && mdconst::hasa<ConstantInt>(M->getOperand(1)) &&
829828
mdconst::extract<ConstantInt>(M->getOperand(1))->getValue() ==
830829
AccessSize &&
831-
M->getOperand(2) && isa<MDNode>(M->getOperand(2)))
830+
M->getOperand(2) && isa<MDNode>(M->getOperand(2))) {
831+
New.TBAAStruct = nullptr;
832832
New.TBAA = cast<MDNode>(M->getOperand(2));
833+
}
833834
return New;
834835
}

llvm/test/Transforms/InstCombine/struct-assign-tbaa.ll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ define ptr @test2() {
3838
define void @test3_multiple_fields(ptr nocapture %a, ptr nocapture %b) {
3939
; CHECK-LABEL: @test3_multiple_fields(
4040
; CHECK-NEXT: entry:
41-
; CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr [[B:%.*]], align 4
42-
; CHECK-NEXT: store i64 [[TMP0]], ptr [[A:%.*]], align 4
41+
; CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr [[B:%.*]], align 4, !tbaa.struct [[TBAA_STRUCT3:![0-9]+]]
42+
; CHECK-NEXT: store i64 [[TMP0]], ptr [[A:%.*]], align 4, !tbaa.struct [[TBAA_STRUCT3]]
4343
; CHECK-NEXT: ret void
4444
;
4545
entry:
@@ -86,4 +86,5 @@ entry:
8686
; CHECK: [[TBAA0]] = !{[[META1:![0-9]+]], [[META1]], i64 0}
8787
; CHECK: [[META1]] = !{!"float", [[META2:![0-9]+]]}
8888
; CHECK: [[META2]] = !{!"Simple C/C++ TBAA"}
89+
; CHECK: [[TBAA_STRUCT3]] = !{i64 0, i64 4, [[TBAA0]], i64 4, i64 4, [[TBAA0]]}
8990
;.

0 commit comments

Comments
 (0)