Skip to content

[LoopInterchange] Remove 'S' Scalar Dependencies #119345

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

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions llvm/lib/Transforms/Scalar/LoopInterchange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,17 @@ static bool populateDependencyMatrix(CharMatrix &DepMatrix, unsigned Level,
unsigned Levels = D->getLevels();
char Direction;
for (unsigned II = 1; II <= Levels; ++II) {
if (D->isScalar(II)) {
Direction = 'S';
Dep.push_back(Direction);
} else {
unsigned Dir = D->getDirection(II);
if (Dir == Dependence::DVEntry::LT ||
Dir == Dependence::DVEntry::LE)
Direction = '<';
else if (Dir == Dependence::DVEntry::GT ||
Dir == Dependence::DVEntry::GE)
Direction = '>';
else if (Dir == Dependence::DVEntry::EQ)
Direction = '=';
else
Direction = '*';
Dep.push_back(Direction);
}
unsigned Dir = D->getDirection(II);
if (Dir == Dependence::DVEntry::LT || Dir == Dependence::DVEntry::LE)
Direction = '<';
else if (Dir == Dependence::DVEntry::GT ||
Dir == Dependence::DVEntry::GE)
Direction = '>';
else if (Dir == Dependence::DVEntry::EQ)
Direction = '=';
else
Direction = '*';
Dep.push_back(Direction);
}
while (Dep.size() != Level) {
Dep.push_back('I');
Expand Down
8 changes: 8 additions & 0 deletions llvm/test/Transforms/LoopInterchange/gh54176-scalar-deps.ll
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
; Remove 'S' Scalar Dependencies #119345
; Scalar dependencies are not handled correctly, so they were removed to avoid
; miscompiles. The loop nest in this test case used to be interchanged, but it's
; no longer triggering. XFAIL'ing this test to indicate that this test should
; interchanged if scalar deps are handled correctly.
;
; XFAIL: *

; RUN: opt < %s -passes=loop-interchange -pass-remarks-output=%t -disable-output
; RUN: FileCheck -input-file %t %s

Expand Down
11 changes: 7 additions & 4 deletions llvm/test/Transforms/LoopInterchange/inner-only-reductions.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
; RUN: -verify-dom-info -verify-loop-info -verify-loop-lcssa 2>&1 | FileCheck -check-prefix=IR %s
; RUN: FileCheck --input-file=%t %s

; Inner loop only reductions are not supported currently. See discussion at
; D53027 for more information on the required checks.
; Both tests should be rejected as interchange candidates. For now, they are
; rejected for dependence analysis reasons, but that's because support for 'S'
; scalar dependencies was removed. When that is properly, the inner loop only
; reductions should still not be supported currently, see discussion at D53027
; for more information on the required checks.

@A = common global [500 x [500 x i32]] zeroinitializer
@X = common global i32 0
Expand All @@ -18,7 +21,7 @@

; CHECK: --- !Missed
; CHECK-NEXT: Pass: loop-interchange
; CHECK-NEXT: Name: UnsupportedPHI
; CHECK-NEXT: Name: Dependence
; CHECK-NEXT: Function: reduction_01

; IR-LABEL: @reduction_01(
Expand Down Expand Up @@ -71,7 +74,7 @@ for.end8: ; preds = %for.cond1.for.inc6_

; CHECK: --- !Missed
; CHECK-NEXT: Pass: loop-interchange
; CHECK-NEXT: Name: UnsupportedPHIOuter
; CHECK-NEXT: Name: Dependence
; CHECK-NEXT: Function: reduction_03

; IR-LABEL: @reduction_03(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
; Remove 'S' Scalar Dependencies #119345
; Scalar dependencies are not handled correctly, so they were removed to avoid
; miscompiles. The loop nest in this test case used to be interchanged, but it's
; no longer triggering. XFAIL'ing this test to indicate that this test should
; interchanged if scalar deps are handled correctly.
;
; XFAIL: *

; RUN: opt < %s -passes=loop-interchange -verify-dom-info -verify-loop-info -pass-remarks-output=%t -disable-output
; RUN: FileCheck -input-file %t %s

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
; Remove 'S' Scalar Dependencies #119345
; Scalar dependencies are not handled correctly, so they were removed to avoid
; miscompiles. The loop nest in this test case used to be interchanged, but it's
; no longer triggering. XFAIL'ing this test to indicate that this test should
; interchanged if scalar deps are handled correctly.
;
; XFAIL: *

; RUN: opt < %s -passes=loop-interchange -cache-line-size=64 -verify-dom-info -verify-loop-info -pass-remarks-output=%t -disable-output
; RUN: FileCheck -input-file %t %s

Expand Down
12 changes: 10 additions & 2 deletions llvm/test/Transforms/LoopInterchange/lcssa.ll
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
; Remove 'S' Scalar Dependencies #119345
; Scalar dependencies are not handled correctly, so they were removed to avoid
; miscompiles. The loop nest in this test case used to be interchanged, but it's
; no longer triggering. XFAIL'ing this test to indicate that this test should
; interchanged if scalar deps are handled correctly.
;
; XFAIL: *

; RUN: opt < %s -passes=loop-interchange -cache-line-size=64 -pass-remarks-missed='loop-interchange' -verify-loop-lcssa -pass-remarks-output=%t -S
; RUN: FileCheck --input-file %t --check-prefix REMARK %s

Expand Down Expand Up @@ -177,7 +185,7 @@ for.end16: ; preds = %for.exit
}

; PHI node in inner latch with multiple predecessors.
; REMARK: Interchanged
; REMARK: Interchanged
; REMARK-NEXT: lcssa_05

define void @lcssa_05(ptr %ptr, i1 %arg) {
Expand Down Expand Up @@ -222,7 +230,7 @@ for.end16: ; preds = %for.exit
ret void
}

; REMARK: UnsupportedExitPHI
; REMARK: UnsupportedExitPHI
; REMARK-NEXT: lcssa_06

define void @lcssa_06(ptr %ptr, ptr %ptr1, i1 %arg) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
; Remove 'S' Scalar Dependencies #119345
; Scalar dependencies are not handled correctly, so they were removed to avoid
; miscompiles. The loop nest in this test case used to be interchanged, but it's
; no longer triggering. XFAIL'ing this test to indicate that this test should
; interchanged if scalar deps are handled correctly.
;
; XFAIL: *

; RUN: opt -passes=loop-interchange -cache-line-size=64 -verify-dom-info -verify-loop-info -verify-loop-lcssa %s -pass-remarks-output=%t -disable-output
; RUN: FileCheck -input-file %t %s

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

; CHECK: --- !Missed
; CHECK-NEXT: Pass: loop-interchange
; CHECK-NEXT: Name: InterchangeNotProfitable
; CHECK-NEXT: Name: Dependence
; CHECK-NEXT: Function: test1
; CHECK-NEXT: Args:
; CHECK-NEXT: - String: Interchanging loops is not considered to improve cache locality nor vectorization.
; CHECK-NEXT: - String: Cannot interchange loops due to dependences.

define void @test1() {
entry:
Expand Down Expand Up @@ -54,10 +54,10 @@ for.cond.for.end5_crit_edge: ; preds = %for.inc3

; CHECK: --- !Missed
; CHECK-NEXT: Pass: loop-interchange
; CHECK-NEXT: Name: InterchangeNotProfitable
; CHECK-NEXT: Name: Dependence
; CHECK-NEXT: Function: test2
; CHECK-NEXT: Args:
; CHECK-NEXT: - String: Interchanging loops is not considered to improve cache locality nor vectorization.
; CHECK-NEXT: - String: Cannot interchange loops due to dependences.

define void @test2() {
entry:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
; Remove 'S' Scalar Dependencies #119345
; Scalar dependencies are not handled correctly, so they were removed to avoid
; miscompiles. The loop nest in this test case used to be interchanged, but it's
; no longer triggering. XFAIL'ing this test to indicate that this test should
; interchanged if scalar deps are handled correctly.
;
; XFAIL: *

; RUN: opt -passes=loop-interchange -cache-line-size=64 -verify-loop-lcssa %s -pass-remarks-output=%t -disable-output
; RUN: FileCheck -input-file %t %s

Expand Down
8 changes: 8 additions & 0 deletions llvm/test/Transforms/LoopInterchange/profitability.ll
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
; Remove 'S' Scalar Dependencies #119345
; Scalar dependencies are not handled correctly, so they were removed to avoid
; miscompiles. The loop nest in this test case used to be interchanged, but it's
; no longer triggering. XFAIL'ing this test to indicate that this test should
; interchanged if scalar deps are handled correctly.
;
; XFAIL: *

; RUN: opt < %s -passes=loop-interchange -cache-line-size=64 -pass-remarks-output=%t -verify-dom-info -verify-loop-info \
; RUN: -pass-remarks=loop-interchange -pass-remarks-missed=loop-interchange
; RUN: FileCheck -input-file %t %s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ for1.loopexit: ; preds = %for1.inc
; Check that we do not interchange if reduction is stored in an invariant address inside inner loop
; REMARKS: --- !Missed
; REMARKS-NEXT: Pass: loop-interchange
; REMARKS-NEXT: Name: UnsupportedPHIOuter
; REMARKS-NEXT: Name: Dependence
; REMARKS-NEXT: Function: test4

define i64 @test4(ptr %Arr, ptr %dst) {
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/Transforms/LoopInterchange/unique-dep-matrix.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

; CHECK: Dependency matrix before interchange:
; CHECK-NEXT: I I
; CHECK-NEXT: = S
; CHECK-NEXT: < S
; CHECK-NEXT: = *
; CHECK-NEXT: < *
; CHECK-NEXT: Processing InnerLoopId

; This example is taken from github issue #54176
Expand Down
8 changes: 8 additions & 0 deletions llvm/test/Transforms/LoopInterchange/vector-gep-operand.ll
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
; Remove 'S' Scalar Dependencies #119345
; Scalar dependencies are not handled correctly, so they were removed to avoid
; miscompiles. The loop nest in this test case used to be interchanged, but it's
; no longer triggering. XFAIL'ing this test to indicate that this test should
; interchanged if scalar deps are handled correctly.
;
; XFAIL: *

; RUN: opt -passes=loop-interchange -cache-line-size=64 -loop-interchange-threshold=-10 %s -pass-remarks-output=%t -disable-output
; RUN: FileCheck -input-file %t %s

Expand Down
Loading