Files
clang-p2996/llvm/test/Transforms/LoopInterchange/pr43326-ideal-access-pattern.ll
Madhur Amilkanthwar 0074a462f1 [LoopInterchange] Hoist isComputableLoopNest() in the control flow (#124247)
The profiling of the LLVM Test-suite reveals that a significant portion,
specifically 14,090 out of 139,323, loop nests were identified as
non-viable candidates for transformation, leading to the transform
exiting from isComputableLoopNest() without any action.

More importantly, dependence information was computed for these loop
nests before reaching the function isComputableLoopNest(), which does
not require DI and relies solely on scalar evolution (SE).

To enhance compile-time efficiency, this patch moves the call to
isComputableLoopNest() earlier in the control-flow, thereby avoiding
unnecessary dependence calculations.

The impact of this change is evident on the compile-time-tracker, with
the overall geometric mean improvement recorded at 0.11%, while the
lencode benchmark gets a more substantial benefit of 0.44%.
This improvement can be tracked in the isc-ln-exp-2 branch under my
repo.
2025-02-05 13:50:17 +05:30

73 lines
3.3 KiB
LLVM

; RUN: opt < %s -passes=loop-interchange -cache-line-size=64 -pass-remarks-missed='loop-interchange' -pass-remarks-output=%t -S \
; RUN: -verify-dom-info -verify-loop-info -verify-loop-lcssa -stats 2>&1
; RUN: FileCheck --input-file=%t --check-prefix=REMARKS %s
; Triply nested loop, should be able to do interchange three times
; to get the ideal access pattern.
; void f(int e[10][10][10], int f[10][10][10]) {
; for (int a = 0; a < 10; a++) {
; for (int b = 0; b < 10; b++) {
; for (int c = 0; c < 10; c++) {
; f[c][b][a] = e[c][b][a];
; }
; }
; }
; }
; REMARKS: --- !Analysis
; REMARKS-NEXT: Pass: loop-interchange
; REMARKS-NEXT: Name: Dependence
; REMARKS-NEXT: Function: pr43326-triply-nested
; REMARKS-NEXT: Args:
; REMARKS-NEXT: - String: Computed dependence info, invoking the transform.
; REMARKS-NEXT: ...
; REMARKS: --- !Passed
; REMARKS-NEXT: Pass: loop-interchange
; REMARKS-NEXT: Name: Interchanged
; REMARKS-NEXT: Function: pr43326-triply-nested
; REMARKS: --- !Passed
; REMARKS-NEXT: Pass: loop-interchange
; REMARKS-NEXT: Name: Interchanged
; REMARKS-NEXT: Function: pr43326-triply-nested
; REMARKS: --- !Passed
; REMARKS-NEXT: Pass: loop-interchange
; REMARKS-NEXT: Name: Interchanged
; REMARKS-NEXT: Function: pr43326-triply-nested
define void @pr43326-triply-nested(ptr %e, ptr %f) {
entry:
br label %for.outermost.header
for.outermost.header: ; preds = %entry, %for.outermost.latch
%indvars.outermost = phi i64 [ 0, %entry ], [ %indvars.outermost.next, %for.outermost.latch ]
br label %for.middle.header
for.cond.cleanup: ; preds = %for.outermost.latch
ret void
for.middle.header: ; preds = %for.outermost.header, %for.middle.latch
%indvars.middle = phi i64 [ 0, %for.outermost.header ], [ %indvars.middle.next, %for.middle.latch ]
br label %for.innermost
for.outermost.latch: ; preds = %for.middle.latch
%indvars.outermost.next = add nuw nsw i64 %indvars.outermost, 1
%exitcond.outermost = icmp ne i64 %indvars.outermost.next, 10
br i1 %exitcond.outermost, label %for.outermost.header, label %for.cond.cleanup
for.middle.latch: ; preds = %for.innermost
%indvars.middle.next = add nuw nsw i64 %indvars.middle, 1
%exitcond.middle = icmp ne i64 %indvars.middle.next, 10
br i1 %exitcond.middle, label %for.middle.header, label %for.outermost.latch
for.innermost: ; preds = %for.middle.header, %for.innermost
%indvars.innermost = phi i64 [ 0, %for.middle.header ], [ %indvars.innermost.next, %for.innermost ]
%arrayidx12 = getelementptr inbounds [10 x [10 x i32]], ptr %e, i64 %indvars.innermost, i64 %indvars.middle, i64 %indvars.outermost
%0 = load i32, ptr %arrayidx12
%arrayidx18 = getelementptr inbounds [10 x [10 x i32]], ptr %f, i64 %indvars.innermost, i64 %indvars.middle, i64 %indvars.outermost
store i32 %0, ptr %arrayidx18
%indvars.innermost.next = add nuw nsw i64 %indvars.innermost, 1
%exitcond.innermost = icmp ne i64 %indvars.innermost.next, 10
br i1 %exitcond.innermost, label %for.innermost, label %for.middle.latch
}