-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[SLP] Invariant loads cannot have a memory dependency on stores. #167929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-vectorizers Author: Michael Bedy (mjbedy) ChangesFull diff: https://github.com/llvm/llvm-project/pull/167929.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index cc53b0dd3577e..e67e607ee1632 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -21623,6 +21623,17 @@ void BoUpSLP::BlockScheduling::calculateDependencies(
}
}
+ // Helper to detect loads marked with !invariant.load metadata. Such loads
+ // are defined to read from memory that never changes for the lifetime of
+ // the program; any store to the same location would be UB. Therefore we
+ // can conservatively treat an invariant load and any store as non-aliasing
+ // for scheduling/dep purposes and skip creating a dependency edge.
+ auto IsInvariantLoad = [](const Instruction *I) {
+ if (const auto *LI = dyn_cast<LoadInst>(I))
+ return LI->getMetadata(LLVMContext::MD_invariant_load) != nullptr;
+ return false;
+ };
+
// Handle the memory dependencies (if any).
ScheduleData *NextLoadStore = BundleMember->getNextLoadStore();
if (!NextLoadStore)
@@ -21636,10 +21647,15 @@ void BoUpSLP::BlockScheduling::calculateDependencies(
unsigned DistToSrc = 1;
bool IsNonSimpleSrc = !SrcLoc.Ptr || !isSimple(SrcInst);
+ if (IsInvariantLoad(SrcInst))
+ return; // Invariant load cannot have memory dependencies.
+
for (ScheduleData *DepDest = NextLoadStore; DepDest;
DepDest = DepDest->getNextLoadStore()) {
assert(isInSchedulingRegion(*DepDest) && "Expected to be in region");
+ Instruction *DestInst = DepDest->getInst();
+
// We have two limits to reduce the complexity:
// 1) AliasedCheckLimit: It's a small limit to reduce calls to
// SLP->isAliased (which is the expensive part in this loop).
@@ -21648,7 +21664,8 @@ void BoUpSLP::BlockScheduling::calculateDependencies(
// It's important for the loop break condition (see below) to
// check this limit even between two read-only instructions.
if (DistToSrc >= MaxMemDepDistance ||
- ((SrcMayWrite || DepDest->getInst()->mayWriteToMemory()) &&
+ (!IsInvariantLoad(DestInst) && // Cannot have memory deps.
+ (SrcMayWrite || DepDest->getInst()->mayWriteToMemory()) &&
(IsNonSimpleSrc || NumAliased >= AliasedCheckLimit ||
SLP->isAliased(SrcLoc, SrcInst, DepDest->getInst())))) {
diff --git a/llvm/test/Transforms/SLPVectorizer/AMDGPU/invariant-load-no-alias-store.ll b/llvm/test/Transforms/SLPVectorizer/AMDGPU/invariant-load-no-alias-store.ll
new file mode 100644
index 0000000000000..00bd0feb8c0fa
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/AMDGPU/invariant-load-no-alias-store.ll
@@ -0,0 +1,82 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -passes="function(slp-vectorizer)" -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1200 %s -S | FileCheck %s
+
+define void @test(ptr addrspace(1) %base, ptr addrspace(1) %otherA, ptr addrspace(1) %otherB) #0 {
+; CHECK-LABEL: define void @test(
+; CHECK-SAME: ptr addrspace(1) [[BASE:%.*]], ptr addrspace(1) [[OTHERA:%.*]], ptr addrspace(1) [[OTHERB:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[P0:%.*]] = getelementptr half, ptr addrspace(1) [[BASE]], i32 0
+; CHECK-NEXT: [[A0PTR:%.*]] = getelementptr half, ptr addrspace(1) [[OTHERA]], i32 0
+; CHECK-NEXT: [[B0PTR:%.*]] = getelementptr half, ptr addrspace(1) [[OTHERB]], i32 0
+; CHECK-NEXT: [[TMP0:%.*]] = load <2 x half>, ptr addrspace(1) [[A0PTR]], align 2, !invariant.load [[META0:![0-9]+]]
+; CHECK-NEXT: [[TMP1:%.*]] = load <2 x half>, ptr addrspace(1) [[B0PTR]], align 2, !invariant.load [[META0]]
+; CHECK-NEXT: [[TMP2:%.*]] = fadd reassoc <2 x half> [[TMP0]], [[TMP1]]
+; CHECK-NEXT: store <2 x half> [[TMP2]], ptr addrspace(1) [[P0]], align 2
+; CHECK-NEXT: ret void
+;
+entry:
+ %p0 = getelementptr half, ptr addrspace(1) %base, i32 0
+ %p1 = getelementptr half, ptr addrspace(1) %base, i32 1
+ ; First pair of invariant loads from otherA.
+ %A0PTR = getelementptr half, ptr addrspace(1) %otherA, i32 0
+ %B0PTR = getelementptr half, ptr addrspace(1) %otherB, i32 0
+ %A0 = load half, ptr addrspace(1) %A0PTR, align 2, !invariant.load !0
+ %B0 = load half, ptr addrspace(1) %B0PTR, align 2, !invariant.load !0
+ %add0 = fadd reassoc half %A0, %B0
+ store half %add0, ptr addrspace(1) %p0, align 2
+ %A1PTR = getelementptr half, ptr addrspace(1) %otherA, i32 1
+ %B1PTR = getelementptr half, ptr addrspace(1) %otherB, i32 1
+ %A1 = load half, ptr addrspace(1) %A1PTR, align 2, !invariant.load !0
+ %B1 = load half, ptr addrspace(1) %B1PTR, align 2, !invariant.load !0
+ %add1 = fadd reassoc half %A1, %B1
+ store half %add1, ptr addrspace(1) %p1, align 2
+ ret void
+}
+
+
+define void @aliastest(ptr addrspace(1) %base, ptr addrspace(1) %otherA, ptr addrspace(1) %otherB) #0 {
+; CHECK-LABEL: define void @aliastest(
+; CHECK-SAME: ptr addrspace(1) [[BASE:%.*]], ptr addrspace(1) [[OTHERA:%.*]], ptr addrspace(1) [[OTHERB:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[P0:%.*]] = getelementptr half, ptr addrspace(1) [[BASE]], i32 0
+; CHECK-NEXT: [[P1:%.*]] = getelementptr half, ptr addrspace(1) [[BASE]], i32 1
+; CHECK-NEXT: [[A0PTR:%.*]] = getelementptr half, ptr addrspace(1) [[OTHERA]], i32 0
+; CHECK-NEXT: [[B0PTR:%.*]] = getelementptr half, ptr addrspace(1) [[OTHERB]], i32 0
+; CHECK-NEXT: [[A0:%.*]] = load half, ptr addrspace(1) [[A0PTR]], align 2
+; CHECK-NEXT: [[B0:%.*]] = load half, ptr addrspace(1) [[B0PTR]], align 2
+; CHECK-NEXT: [[ADD0:%.*]] = fadd reassoc half [[A0]], [[B0]]
+; CHECK-NEXT: store half [[ADD0]], ptr addrspace(1) [[P0]], align 2
+; CHECK-NEXT: [[A1PTR:%.*]] = getelementptr half, ptr addrspace(1) [[OTHERA]], i32 1
+; CHECK-NEXT: [[B1PTR:%.*]] = getelementptr half, ptr addrspace(1) [[OTHERB]], i32 1
+; CHECK-NEXT: [[A1:%.*]] = load half, ptr addrspace(1) [[A1PTR]], align 2
+; CHECK-NEXT: [[B1:%.*]] = load half, ptr addrspace(1) [[B1PTR]], align 2
+; CHECK-NEXT: [[ADD1:%.*]] = fadd reassoc half [[A1]], [[B1]]
+; CHECK-NEXT: store half [[ADD1]], ptr addrspace(1) [[P1]], align 2
+; CHECK-NEXT: ret void
+;
+entry:
+ %p0 = getelementptr half, ptr addrspace(1) %base, i32 0
+ %p1 = getelementptr half, ptr addrspace(1) %base, i32 1
+ ; First pair of invariant loads from otherA.
+ %A0PTR = getelementptr half, ptr addrspace(1) %otherA, i32 0
+ %B0PTR = getelementptr half, ptr addrspace(1) %otherB, i32 0
+ %A0 = load half, ptr addrspace(1) %A0PTR, align 2
+ %B0 = load half, ptr addrspace(1) %B0PTR, align 2
+ %add0 = fadd reassoc half %A0, %B0
+ store half %add0, ptr addrspace(1) %p0, align 2
+ %A1PTR = getelementptr half, ptr addrspace(1) %otherA, i32 1
+ %B1PTR = getelementptr half, ptr addrspace(1) %otherB, i32 1
+ %A1 = load half, ptr addrspace(1) %A1PTR, align 2
+ %B1 = load half, ptr addrspace(1) %B1PTR, align 2
+ %add1 = fadd reassoc half %A1, %B1
+ store half %add1, ptr addrspace(1) %p1, align 2
+ ret void
+}
+
+
+attributes #0 = { nounwind }
+
+!0 = !{}
+;.
+; CHECK: [[META0]] = !{}
+;.
|
|
@llvm/pr-subscribers-llvm-transforms Author: Michael Bedy (mjbedy) ChangesFull diff: https://github.com/llvm/llvm-project/pull/167929.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index cc53b0dd3577e..e67e607ee1632 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -21623,6 +21623,17 @@ void BoUpSLP::BlockScheduling::calculateDependencies(
}
}
+ // Helper to detect loads marked with !invariant.load metadata. Such loads
+ // are defined to read from memory that never changes for the lifetime of
+ // the program; any store to the same location would be UB. Therefore we
+ // can conservatively treat an invariant load and any store as non-aliasing
+ // for scheduling/dep purposes and skip creating a dependency edge.
+ auto IsInvariantLoad = [](const Instruction *I) {
+ if (const auto *LI = dyn_cast<LoadInst>(I))
+ return LI->getMetadata(LLVMContext::MD_invariant_load) != nullptr;
+ return false;
+ };
+
// Handle the memory dependencies (if any).
ScheduleData *NextLoadStore = BundleMember->getNextLoadStore();
if (!NextLoadStore)
@@ -21636,10 +21647,15 @@ void BoUpSLP::BlockScheduling::calculateDependencies(
unsigned DistToSrc = 1;
bool IsNonSimpleSrc = !SrcLoc.Ptr || !isSimple(SrcInst);
+ if (IsInvariantLoad(SrcInst))
+ return; // Invariant load cannot have memory dependencies.
+
for (ScheduleData *DepDest = NextLoadStore; DepDest;
DepDest = DepDest->getNextLoadStore()) {
assert(isInSchedulingRegion(*DepDest) && "Expected to be in region");
+ Instruction *DestInst = DepDest->getInst();
+
// We have two limits to reduce the complexity:
// 1) AliasedCheckLimit: It's a small limit to reduce calls to
// SLP->isAliased (which is the expensive part in this loop).
@@ -21648,7 +21664,8 @@ void BoUpSLP::BlockScheduling::calculateDependencies(
// It's important for the loop break condition (see below) to
// check this limit even between two read-only instructions.
if (DistToSrc >= MaxMemDepDistance ||
- ((SrcMayWrite || DepDest->getInst()->mayWriteToMemory()) &&
+ (!IsInvariantLoad(DestInst) && // Cannot have memory deps.
+ (SrcMayWrite || DepDest->getInst()->mayWriteToMemory()) &&
(IsNonSimpleSrc || NumAliased >= AliasedCheckLimit ||
SLP->isAliased(SrcLoc, SrcInst, DepDest->getInst())))) {
diff --git a/llvm/test/Transforms/SLPVectorizer/AMDGPU/invariant-load-no-alias-store.ll b/llvm/test/Transforms/SLPVectorizer/AMDGPU/invariant-load-no-alias-store.ll
new file mode 100644
index 0000000000000..00bd0feb8c0fa
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/AMDGPU/invariant-load-no-alias-store.ll
@@ -0,0 +1,82 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -passes="function(slp-vectorizer)" -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1200 %s -S | FileCheck %s
+
+define void @test(ptr addrspace(1) %base, ptr addrspace(1) %otherA, ptr addrspace(1) %otherB) #0 {
+; CHECK-LABEL: define void @test(
+; CHECK-SAME: ptr addrspace(1) [[BASE:%.*]], ptr addrspace(1) [[OTHERA:%.*]], ptr addrspace(1) [[OTHERB:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[P0:%.*]] = getelementptr half, ptr addrspace(1) [[BASE]], i32 0
+; CHECK-NEXT: [[A0PTR:%.*]] = getelementptr half, ptr addrspace(1) [[OTHERA]], i32 0
+; CHECK-NEXT: [[B0PTR:%.*]] = getelementptr half, ptr addrspace(1) [[OTHERB]], i32 0
+; CHECK-NEXT: [[TMP0:%.*]] = load <2 x half>, ptr addrspace(1) [[A0PTR]], align 2, !invariant.load [[META0:![0-9]+]]
+; CHECK-NEXT: [[TMP1:%.*]] = load <2 x half>, ptr addrspace(1) [[B0PTR]], align 2, !invariant.load [[META0]]
+; CHECK-NEXT: [[TMP2:%.*]] = fadd reassoc <2 x half> [[TMP0]], [[TMP1]]
+; CHECK-NEXT: store <2 x half> [[TMP2]], ptr addrspace(1) [[P0]], align 2
+; CHECK-NEXT: ret void
+;
+entry:
+ %p0 = getelementptr half, ptr addrspace(1) %base, i32 0
+ %p1 = getelementptr half, ptr addrspace(1) %base, i32 1
+ ; First pair of invariant loads from otherA.
+ %A0PTR = getelementptr half, ptr addrspace(1) %otherA, i32 0
+ %B0PTR = getelementptr half, ptr addrspace(1) %otherB, i32 0
+ %A0 = load half, ptr addrspace(1) %A0PTR, align 2, !invariant.load !0
+ %B0 = load half, ptr addrspace(1) %B0PTR, align 2, !invariant.load !0
+ %add0 = fadd reassoc half %A0, %B0
+ store half %add0, ptr addrspace(1) %p0, align 2
+ %A1PTR = getelementptr half, ptr addrspace(1) %otherA, i32 1
+ %B1PTR = getelementptr half, ptr addrspace(1) %otherB, i32 1
+ %A1 = load half, ptr addrspace(1) %A1PTR, align 2, !invariant.load !0
+ %B1 = load half, ptr addrspace(1) %B1PTR, align 2, !invariant.load !0
+ %add1 = fadd reassoc half %A1, %B1
+ store half %add1, ptr addrspace(1) %p1, align 2
+ ret void
+}
+
+
+define void @aliastest(ptr addrspace(1) %base, ptr addrspace(1) %otherA, ptr addrspace(1) %otherB) #0 {
+; CHECK-LABEL: define void @aliastest(
+; CHECK-SAME: ptr addrspace(1) [[BASE:%.*]], ptr addrspace(1) [[OTHERA:%.*]], ptr addrspace(1) [[OTHERB:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[P0:%.*]] = getelementptr half, ptr addrspace(1) [[BASE]], i32 0
+; CHECK-NEXT: [[P1:%.*]] = getelementptr half, ptr addrspace(1) [[BASE]], i32 1
+; CHECK-NEXT: [[A0PTR:%.*]] = getelementptr half, ptr addrspace(1) [[OTHERA]], i32 0
+; CHECK-NEXT: [[B0PTR:%.*]] = getelementptr half, ptr addrspace(1) [[OTHERB]], i32 0
+; CHECK-NEXT: [[A0:%.*]] = load half, ptr addrspace(1) [[A0PTR]], align 2
+; CHECK-NEXT: [[B0:%.*]] = load half, ptr addrspace(1) [[B0PTR]], align 2
+; CHECK-NEXT: [[ADD0:%.*]] = fadd reassoc half [[A0]], [[B0]]
+; CHECK-NEXT: store half [[ADD0]], ptr addrspace(1) [[P0]], align 2
+; CHECK-NEXT: [[A1PTR:%.*]] = getelementptr half, ptr addrspace(1) [[OTHERA]], i32 1
+; CHECK-NEXT: [[B1PTR:%.*]] = getelementptr half, ptr addrspace(1) [[OTHERB]], i32 1
+; CHECK-NEXT: [[A1:%.*]] = load half, ptr addrspace(1) [[A1PTR]], align 2
+; CHECK-NEXT: [[B1:%.*]] = load half, ptr addrspace(1) [[B1PTR]], align 2
+; CHECK-NEXT: [[ADD1:%.*]] = fadd reassoc half [[A1]], [[B1]]
+; CHECK-NEXT: store half [[ADD1]], ptr addrspace(1) [[P1]], align 2
+; CHECK-NEXT: ret void
+;
+entry:
+ %p0 = getelementptr half, ptr addrspace(1) %base, i32 0
+ %p1 = getelementptr half, ptr addrspace(1) %base, i32 1
+ ; First pair of invariant loads from otherA.
+ %A0PTR = getelementptr half, ptr addrspace(1) %otherA, i32 0
+ %B0PTR = getelementptr half, ptr addrspace(1) %otherB, i32 0
+ %A0 = load half, ptr addrspace(1) %A0PTR, align 2
+ %B0 = load half, ptr addrspace(1) %B0PTR, align 2
+ %add0 = fadd reassoc half %A0, %B0
+ store half %add0, ptr addrspace(1) %p0, align 2
+ %A1PTR = getelementptr half, ptr addrspace(1) %otherA, i32 1
+ %B1PTR = getelementptr half, ptr addrspace(1) %otherB, i32 1
+ %A1 = load half, ptr addrspace(1) %A1PTR, align 2
+ %B1 = load half, ptr addrspace(1) %B1PTR, align 2
+ %add1 = fadd reassoc half %A1, %B1
+ store half %add1, ptr addrspace(1) %p1, align 2
+ ret void
+}
+
+
+attributes #0 = { nounwind }
+
+!0 = !{}
+;.
+; CHECK: [[META0]] = !{}
+;.
|
|
@llvm/pr-subscribers-backend-amdgpu Author: Michael Bedy (mjbedy) ChangesFull diff: https://github.com/llvm/llvm-project/pull/167929.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index cc53b0dd3577e..e67e607ee1632 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -21623,6 +21623,17 @@ void BoUpSLP::BlockScheduling::calculateDependencies(
}
}
+ // Helper to detect loads marked with !invariant.load metadata. Such loads
+ // are defined to read from memory that never changes for the lifetime of
+ // the program; any store to the same location would be UB. Therefore we
+ // can conservatively treat an invariant load and any store as non-aliasing
+ // for scheduling/dep purposes and skip creating a dependency edge.
+ auto IsInvariantLoad = [](const Instruction *I) {
+ if (const auto *LI = dyn_cast<LoadInst>(I))
+ return LI->getMetadata(LLVMContext::MD_invariant_load) != nullptr;
+ return false;
+ };
+
// Handle the memory dependencies (if any).
ScheduleData *NextLoadStore = BundleMember->getNextLoadStore();
if (!NextLoadStore)
@@ -21636,10 +21647,15 @@ void BoUpSLP::BlockScheduling::calculateDependencies(
unsigned DistToSrc = 1;
bool IsNonSimpleSrc = !SrcLoc.Ptr || !isSimple(SrcInst);
+ if (IsInvariantLoad(SrcInst))
+ return; // Invariant load cannot have memory dependencies.
+
for (ScheduleData *DepDest = NextLoadStore; DepDest;
DepDest = DepDest->getNextLoadStore()) {
assert(isInSchedulingRegion(*DepDest) && "Expected to be in region");
+ Instruction *DestInst = DepDest->getInst();
+
// We have two limits to reduce the complexity:
// 1) AliasedCheckLimit: It's a small limit to reduce calls to
// SLP->isAliased (which is the expensive part in this loop).
@@ -21648,7 +21664,8 @@ void BoUpSLP::BlockScheduling::calculateDependencies(
// It's important for the loop break condition (see below) to
// check this limit even between two read-only instructions.
if (DistToSrc >= MaxMemDepDistance ||
- ((SrcMayWrite || DepDest->getInst()->mayWriteToMemory()) &&
+ (!IsInvariantLoad(DestInst) && // Cannot have memory deps.
+ (SrcMayWrite || DepDest->getInst()->mayWriteToMemory()) &&
(IsNonSimpleSrc || NumAliased >= AliasedCheckLimit ||
SLP->isAliased(SrcLoc, SrcInst, DepDest->getInst())))) {
diff --git a/llvm/test/Transforms/SLPVectorizer/AMDGPU/invariant-load-no-alias-store.ll b/llvm/test/Transforms/SLPVectorizer/AMDGPU/invariant-load-no-alias-store.ll
new file mode 100644
index 0000000000000..00bd0feb8c0fa
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/AMDGPU/invariant-load-no-alias-store.ll
@@ -0,0 +1,82 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -passes="function(slp-vectorizer)" -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1200 %s -S | FileCheck %s
+
+define void @test(ptr addrspace(1) %base, ptr addrspace(1) %otherA, ptr addrspace(1) %otherB) #0 {
+; CHECK-LABEL: define void @test(
+; CHECK-SAME: ptr addrspace(1) [[BASE:%.*]], ptr addrspace(1) [[OTHERA:%.*]], ptr addrspace(1) [[OTHERB:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[P0:%.*]] = getelementptr half, ptr addrspace(1) [[BASE]], i32 0
+; CHECK-NEXT: [[A0PTR:%.*]] = getelementptr half, ptr addrspace(1) [[OTHERA]], i32 0
+; CHECK-NEXT: [[B0PTR:%.*]] = getelementptr half, ptr addrspace(1) [[OTHERB]], i32 0
+; CHECK-NEXT: [[TMP0:%.*]] = load <2 x half>, ptr addrspace(1) [[A0PTR]], align 2, !invariant.load [[META0:![0-9]+]]
+; CHECK-NEXT: [[TMP1:%.*]] = load <2 x half>, ptr addrspace(1) [[B0PTR]], align 2, !invariant.load [[META0]]
+; CHECK-NEXT: [[TMP2:%.*]] = fadd reassoc <2 x half> [[TMP0]], [[TMP1]]
+; CHECK-NEXT: store <2 x half> [[TMP2]], ptr addrspace(1) [[P0]], align 2
+; CHECK-NEXT: ret void
+;
+entry:
+ %p0 = getelementptr half, ptr addrspace(1) %base, i32 0
+ %p1 = getelementptr half, ptr addrspace(1) %base, i32 1
+ ; First pair of invariant loads from otherA.
+ %A0PTR = getelementptr half, ptr addrspace(1) %otherA, i32 0
+ %B0PTR = getelementptr half, ptr addrspace(1) %otherB, i32 0
+ %A0 = load half, ptr addrspace(1) %A0PTR, align 2, !invariant.load !0
+ %B0 = load half, ptr addrspace(1) %B0PTR, align 2, !invariant.load !0
+ %add0 = fadd reassoc half %A0, %B0
+ store half %add0, ptr addrspace(1) %p0, align 2
+ %A1PTR = getelementptr half, ptr addrspace(1) %otherA, i32 1
+ %B1PTR = getelementptr half, ptr addrspace(1) %otherB, i32 1
+ %A1 = load half, ptr addrspace(1) %A1PTR, align 2, !invariant.load !0
+ %B1 = load half, ptr addrspace(1) %B1PTR, align 2, !invariant.load !0
+ %add1 = fadd reassoc half %A1, %B1
+ store half %add1, ptr addrspace(1) %p1, align 2
+ ret void
+}
+
+
+define void @aliastest(ptr addrspace(1) %base, ptr addrspace(1) %otherA, ptr addrspace(1) %otherB) #0 {
+; CHECK-LABEL: define void @aliastest(
+; CHECK-SAME: ptr addrspace(1) [[BASE:%.*]], ptr addrspace(1) [[OTHERA:%.*]], ptr addrspace(1) [[OTHERB:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[P0:%.*]] = getelementptr half, ptr addrspace(1) [[BASE]], i32 0
+; CHECK-NEXT: [[P1:%.*]] = getelementptr half, ptr addrspace(1) [[BASE]], i32 1
+; CHECK-NEXT: [[A0PTR:%.*]] = getelementptr half, ptr addrspace(1) [[OTHERA]], i32 0
+; CHECK-NEXT: [[B0PTR:%.*]] = getelementptr half, ptr addrspace(1) [[OTHERB]], i32 0
+; CHECK-NEXT: [[A0:%.*]] = load half, ptr addrspace(1) [[A0PTR]], align 2
+; CHECK-NEXT: [[B0:%.*]] = load half, ptr addrspace(1) [[B0PTR]], align 2
+; CHECK-NEXT: [[ADD0:%.*]] = fadd reassoc half [[A0]], [[B0]]
+; CHECK-NEXT: store half [[ADD0]], ptr addrspace(1) [[P0]], align 2
+; CHECK-NEXT: [[A1PTR:%.*]] = getelementptr half, ptr addrspace(1) [[OTHERA]], i32 1
+; CHECK-NEXT: [[B1PTR:%.*]] = getelementptr half, ptr addrspace(1) [[OTHERB]], i32 1
+; CHECK-NEXT: [[A1:%.*]] = load half, ptr addrspace(1) [[A1PTR]], align 2
+; CHECK-NEXT: [[B1:%.*]] = load half, ptr addrspace(1) [[B1PTR]], align 2
+; CHECK-NEXT: [[ADD1:%.*]] = fadd reassoc half [[A1]], [[B1]]
+; CHECK-NEXT: store half [[ADD1]], ptr addrspace(1) [[P1]], align 2
+; CHECK-NEXT: ret void
+;
+entry:
+ %p0 = getelementptr half, ptr addrspace(1) %base, i32 0
+ %p1 = getelementptr half, ptr addrspace(1) %base, i32 1
+ ; First pair of invariant loads from otherA.
+ %A0PTR = getelementptr half, ptr addrspace(1) %otherA, i32 0
+ %B0PTR = getelementptr half, ptr addrspace(1) %otherB, i32 0
+ %A0 = load half, ptr addrspace(1) %A0PTR, align 2
+ %B0 = load half, ptr addrspace(1) %B0PTR, align 2
+ %add0 = fadd reassoc half %A0, %B0
+ store half %add0, ptr addrspace(1) %p0, align 2
+ %A1PTR = getelementptr half, ptr addrspace(1) %otherA, i32 1
+ %B1PTR = getelementptr half, ptr addrspace(1) %otherB, i32 1
+ %A1 = load half, ptr addrspace(1) %A1PTR, align 2
+ %B1 = load half, ptr addrspace(1) %B1PTR, align 2
+ %add1 = fadd reassoc half %A1, %B1
+ store half %add1, ptr addrspace(1) %p1, align 2
+ ret void
+}
+
+
+attributes #0 = { nounwind }
+
+!0 = !{}
+;.
+; CHECK: [[META0]] = !{}
+;.
|
|
Looks like it's been too long since I committed upstream and no longer have write access. @alexey-bataev for review, @piotrAMD and @jayfoad FYI. |
| // for scheduling/dep purposes and skip creating a dependency edge. | ||
| auto IsInvariantLoad = [](const Instruction *I) { | ||
| if (const auto *LI = dyn_cast<LoadInst>(I)) | ||
| return LI->getMetadata(LLVMContext::MD_invariant_load) != nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expect this to go through an AA query instead of parsing this specific situation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally agree, would be good to have a general solution for this issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did consider that - and I guess I can look into that as well, but in this case it seems likely less expensive in compile time to do the check ahead of time (at least the early out for SrcInst.)
I can look into the AA aspect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dug in a bit more. It appears the MemoryDepedenceAnalysis code is also handling this explicitly. I assume there is a reason SLP doesn't use it?
There's an interesting and very similar comment in that code.
// If the load is invariant, we "know" that it doesn't alias *any* write. We
// do want to respect mustalias results since defs are useful for value
// forwarding, but any mayalias write can be assumed to be noalias.
// Arguably, this logic should be pushed inside AliasAnalysis itself.
if (isLoad && QueryInst)
if (LoadInst *LI = dyn_cast<LoadInst>(QueryInst)) {
if (LI->hasMetadata(LLVMContext::MD_invariant_load))
isInvariantLoad = true;There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To close the loop on this, although I'm not familiar enough with the AA code to really be able to assess, after further digging it appears there are some pretty subtle questions about how AA would handle this. As noted above, MemoryDependenceAnalysis does in fact seem to take this into account, and that might be the better analysis phase for it anyway.
…t scheduler data list. Add volatile test.
alexey-bataev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG with a nit
|
@mjbedy Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/169/builds/17191 Here is the relevant piece of the build log for the reference |
No description provided.