Skip to content

Commit d7bf86f

Browse files
committed
[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 (cherry-picked from 3b6e250)
1 parent 268147a commit d7bf86f

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
@@ -822,14 +822,15 @@ MDNode *AAMDNodes::extendToTBAA(MDNode *MD, ssize_t Len) {
822822
AAMDNodes AAMDNodes::adjustForAccess(unsigned AccessSize) {
823823
AAMDNodes New = *this;
824824
MDNode *M = New.TBAAStruct;
825-
New.TBAAStruct = nullptr;
826825
if (M && M->getNumOperands() == 3 && M->getOperand(0) &&
827826
mdconst::hasa<ConstantInt>(M->getOperand(0)) &&
828827
mdconst::extract<ConstantInt>(M->getOperand(0))->isZero() &&
829828
M->getOperand(1) && mdconst::hasa<ConstantInt>(M->getOperand(1)) &&
830829
mdconst::extract<ConstantInt>(M->getOperand(1))->getValue() ==
831830
AccessSize &&
832-
M->getOperand(2) && isa<MDNode>(M->getOperand(2)))
831+
M->getOperand(2) && isa<MDNode>(M->getOperand(2))) {
832+
New.TBAAStruct = nullptr;
833833
New.TBAA = cast<MDNode>(M->getOperand(2));
834+
}
834835
return New;
835836
}

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)