Skip to content

Commit 2148978

Browse files
committed
address comments
1 parent adce747 commit 2148978

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,6 +1805,8 @@ bool VectorCombine::scalarizeLoadExtract(Instruction &I) {
18051805
// erased in the correct order.
18061806
Worklist.push(LI);
18071807

1808+
Type *ElemType = VecTy->getElementType();
1809+
18081810
// Replace extracts with narrow scalar loads.
18091811
for (User *U : LI->users()) {
18101812
auto *EI = cast<ExtractElementInst>(U);
@@ -1819,18 +1821,16 @@ bool VectorCombine::scalarizeLoadExtract(Instruction &I) {
18191821
Value *GEP =
18201822
Builder.CreateInBoundsGEP(VecTy, Ptr, {Builder.getInt32(0), Idx});
18211823
auto *NewLoad = cast<LoadInst>(Builder.CreateLoad(
1822-
VecTy->getElementType(), GEP, EI->getName() + ".scalar"));
1824+
ElemType, GEP, EI->getName() + ".scalar"));
18231825

18241826
Align ScalarOpAlignment = computeAlignmentAfterScalarization(
1825-
LI->getAlign(), VecTy->getElementType(), Idx, *DL);
1827+
LI->getAlign(), ElemType, Idx, *DL);
18261828
NewLoad->setAlignment(ScalarOpAlignment);
18271829

1828-
if (MDNode *aliasScope = LI->getMetadata(LLVMContext::MD_alias_scope)) {
1829-
NewLoad->setMetadata(LLVMContext::MD_alias_scope, aliasScope);
1830-
}
1831-
1832-
if (MDNode *noAlias = LI->getMetadata(LLVMContext::MD_noalias)) {
1833-
NewLoad->setMetadata(LLVMContext::MD_noalias, noAlias);
1830+
if (auto *ConstIdx = dyn_cast<ConstantInt>(Idx)) {
1831+
size_t Offset = ConstIdx->getZExtValue() * DL->getTypeStoreSize(ElemType);
1832+
AAMDNodes OldAAMD = LI->getAAMetadata();
1833+
NewLoad->setAAMetadata(OldAAMD.adjustForAccess(Offset, ElemType, *DL));
18341834
}
18351835

18361836
replaceValue(*EI, *NewLoad);

llvm/test/Transforms/VectorCombine/alias.ll

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ define <4 x i32> @quux(ptr addrspace(3) %arg) {
55
; CHECK-LABEL: define <4 x i32> @quux(
66
; CHECK-SAME: ptr addrspace(3) [[ARG:%.*]]) {
77
; CHECK-NEXT: [[BB:.*:]]
8-
; CHECK-NEXT: [[EXTRACTELEMENT:%.*]] = load i8, ptr addrspace(3) [[ARG]], align 4, !alias.scope [[META0:![0-9]+]], !noalias [[META0]]
8+
; CHECK-NEXT: [[EXTRACTELEMENT:%.*]] = load i8, ptr addrspace(3) [[ARG]], align 4, !tbaa [[TBAA0:![0-9]+]], !alias.scope [[META0:![0-9]+]], !noalias [[META0]]
99
; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds <4 x i8>, ptr addrspace(3) [[ARG]], i32 0, i64 1
10-
; CHECK-NEXT: [[EXTRACTELEMENT1:%.*]] = load i8, ptr addrspace(3) [[TMP0]], align 1, !alias.scope [[META0]], !noalias [[META0]]
10+
; CHECK-NEXT: [[EXTRACTELEMENT1:%.*]] = load i8, ptr addrspace(3) [[TMP0]], align 1, !tbaa [[TBAA0]], !alias.scope [[META0]], !noalias [[META0]]
1111
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds <4 x i8>, ptr addrspace(3) [[ARG]], i32 0, i64 2
12-
; CHECK-NEXT: [[EXTRACTELEMENT2:%.*]] = load i8, ptr addrspace(3) [[TMP1]], align 2, !alias.scope [[META0]], !noalias [[META0]]
12+
; CHECK-NEXT: [[EXTRACTELEMENT2:%.*]] = load i8, ptr addrspace(3) [[TMP1]], align 2, !tbaa [[TBAA0]], !alias.scope [[META0]], !noalias [[META0]]
1313
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds <4 x i8>, ptr addrspace(3) [[ARG]], i32 0, i64 3
14-
; CHECK-NEXT: [[EXTRACTELEMENT3:%.*]] = load i8, ptr addrspace(3) [[TMP2]], align 1, !alias.scope [[META0]], !noalias [[META0]]
14+
; CHECK-NEXT: [[EXTRACTELEMENT3:%.*]] = load i8, ptr addrspace(3) [[TMP2]], align 1, !tbaa [[TBAA0]], !alias.scope [[META0]], !noalias [[META0]]
1515
; CHECK-NEXT: [[ZEXT:%.*]] = zext i8 [[EXTRACTELEMENT]] to i32
1616
; CHECK-NEXT: [[ZEXT4:%.*]] = zext i8 [[EXTRACTELEMENT1]] to i32
1717
; CHECK-NEXT: [[ZEXT5:%.*]] = zext i8 [[EXTRACTELEMENT2]] to i32
@@ -23,7 +23,7 @@ define <4 x i32> @quux(ptr addrspace(3) %arg) {
2323
; CHECK-NEXT: ret <4 x i32> [[INSERTELEMENT9]]
2424
;
2525
bb:
26-
%load = load <4 x i8>, ptr addrspace(3) %arg, align 4, !alias.scope !0, !noalias !0
26+
%load = load <4 x i8>, ptr addrspace(3) %arg, align 4, !alias.scope !0, !noalias !0, !tbaa !5
2727
%extractelement = extractelement <4 x i8> %load, i64 0
2828
%extractelement1 = extractelement <4 x i8> %load, i64 1
2929
%extractelement2 = extractelement <4 x i8> %load, i64 2
@@ -42,6 +42,9 @@ bb:
4242
!0 = !{!1}
4343
!1 = distinct !{!1, !2}
4444
!2 = distinct !{!2}
45+
!3 = !{!"Simple C/C++ TBAA"}
46+
!4 = !{!"omnipotent char", !3, i64 0}
47+
!5 = !{!"i8", !4, i64 0}
4548
;.
4649
; CHECK: [[META0]] = !{[[META1:![0-9]+]]}
4750
; CHECK: [[META1]] = distinct !{[[META1]], [[META2:![0-9]+]]}

0 commit comments

Comments
 (0)