[SLPVectorizer] Make aliasing check more precise

SLPVectorizer currently uses AA::isNoAlias() to determine whether
two locations alias. This does not work if one of the instructions
is a call. Instead, we should check getModRefInfo(), which
determines whether an arbitrary instruction modifies or references
a given location.

Among other things, this prevents @llvm.experimental.noalias.scope.decl()
and other inaccessiblmemonly intrinsics from interfering with SLP
vectorization.

Differential Revision: https://reviews.llvm.org/D109012
This commit is contained in:
Nikita Popov 2021-08-31 20:10:50 +02:00
parent 964053d56f
commit 48ebe427c9
2 changed files with 6 additions and 13 deletions

View File

@ -1965,12 +1965,9 @@ private:
if (result.hasValue()) {
return result.getValue();
}
MemoryLocation Loc2 = getLocation(Inst2, AA);
bool aliased = true;
if (Loc1.Ptr && Loc2.Ptr && isSimple(Inst1) && isSimple(Inst2)) {
// Do the alias check.
aliased = !AA->isNoAlias(Loc1, Loc2);
}
if (Loc1.Ptr && isSimple(Inst1))
aliased = isModOrRefSet(AA->getModRefInfo(Inst2, Loc1));
// Store the result in the cache.
result = aliased;
return aliased;

View File

@ -44,16 +44,12 @@ define void @test_inaccessiblememonly(float* %p) {
; CHECK-NEXT: [[P1:%.*]] = getelementptr float, float* [[P]], i64 1
; CHECK-NEXT: [[P2:%.*]] = getelementptr float, float* [[P]], i64 2
; CHECK-NEXT: [[P3:%.*]] = getelementptr float, float* [[P]], i64 3
; CHECK-NEXT: [[L0:%.*]] = load float, float* [[P0]], align 4
; CHECK-NEXT: [[L1:%.*]] = load float, float* [[P1]], align 4
; CHECK-NEXT: [[L2:%.*]] = load float, float* [[P2]], align 4
; CHECK-NEXT: call void @foo() #[[ATTR1:[0-9]+]]
; CHECK-NEXT: [[L3:%.*]] = load float, float* [[P3]], align 4
; CHECK-NEXT: store float [[L0]], float* [[P0]], align 4
; CHECK-NEXT: [[TMP1:%.*]] = bitcast float* [[P0]] to <4 x float>*
; CHECK-NEXT: [[TMP2:%.*]] = load <4 x float>, <4 x float>* [[TMP1]], align 4
; CHECK-NEXT: call void @foo() #[[ATTR1]]
; CHECK-NEXT: store float [[L1]], float* [[P1]], align 4
; CHECK-NEXT: store float [[L2]], float* [[P2]], align 4
; CHECK-NEXT: store float [[L3]], float* [[P3]], align 4
; CHECK-NEXT: [[TMP3:%.*]] = bitcast float* [[P0]] to <4 x float>*
; CHECK-NEXT: store <4 x float> [[TMP2]], <4 x float>* [[TMP3]], align 4
; CHECK-NEXT: ret void
;
%p0 = getelementptr float, float* %p, i64 0