
We are not handling 'S' scalar dependencies correctly and have at least the following miscompiles related to that: [LoopInterchange] incorrect handling of scalar dependencies and dependence vectors starting with ">" #54176 [LoopInterchange] Interchange breaks program correctness #46867 [LoopInterchange] Loops should not interchanged due to dependencies #47259 [LoopInterchange] Loops should not interchanged due to control flow #47401 This patch does no longer insert the "S" dependency/direction into the dependency matrix, so a dependency is never "S". We seem to have forgotten what the exact meaning is of this dependency type, and don't see why it should be treated differently. We prefer correctness over incorrect and more aggressive results. I.e., this prevents the miscompiles at the expense of handling less cases, i.e. making interchange more pessimistic. However, some of the cases that are now rejected for dependence analysis reasons, were rejected before too but for other reasons (e.g. profitability). So at least for the llvm regression tests, the number of regression are very reasonable. This should be a stopgap. We would like to get interchange enabled by default and thus prefer correctness over unsafe transforms, and later see if we can get solve the regressions.
94 lines
3.2 KiB
LLVM
94 lines
3.2 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
; RUN: opt < %s -passes=loop-interchange -cache-line-size=64 -pass-remarks-missed='loop-interchange' -pass-remarks-output=%t -S
|
|
; RUN: FileCheck --input-file=%t %s
|
|
|
|
@b = external dso_local global [5 x i32], align 16
|
|
|
|
;; Not profitable to interchange, because the access is invariant to j loop.
|
|
;;
|
|
;; for(int i=0;i<4;i++) {
|
|
;; for(int j=1;j<4;j++) {
|
|
;; b[i] = ....
|
|
;; }
|
|
;; }
|
|
|
|
; CHECK: --- !Missed
|
|
; CHECK-NEXT: Pass: loop-interchange
|
|
; CHECK-NEXT: Name: Dependence
|
|
; CHECK-NEXT: Function: test1
|
|
; CHECK-NEXT: Args:
|
|
; CHECK-NEXT: - String: Cannot interchange loops due to dependences.
|
|
|
|
define void @test1() {
|
|
entry:
|
|
br label %for.body
|
|
|
|
for.body: ; preds = %for.inc3, %entry
|
|
%inc41 = phi i32 [ %inc4, %for.inc3 ], [ undef, %entry ]
|
|
br label %for.body2
|
|
|
|
for.body2: ; preds = %for.inc, %for.body
|
|
%lsr.iv = phi i32 [ %lsr.iv.next, %for.inc ], [ 1, %for.body ]
|
|
br label %for.inc
|
|
|
|
for.inc: ; preds = %for.body2
|
|
%idxprom = sext i32 %inc41 to i64
|
|
%arrayidx = getelementptr inbounds [5 x i32], ptr @b, i64 0, i64 %idxprom
|
|
%0 = load i32, ptr %arrayidx, align 4
|
|
store i32 undef, ptr %arrayidx, align 4
|
|
%cmp = icmp slt i32 %lsr.iv, 4
|
|
%lsr.iv.next = add nuw nsw i32 %lsr.iv, 1
|
|
br i1 %cmp, label %for.body2, label %for.cond1.for.end_crit_edge
|
|
|
|
for.cond1.for.end_crit_edge: ; preds = %for.inc
|
|
br label %for.inc3
|
|
|
|
for.inc3: ; preds = %for.cond1.for.end_crit_edge
|
|
%inc4 = add nsw i32 %inc41, 1
|
|
br i1 false, label %for.body, label %for.cond.for.end5_crit_edge
|
|
|
|
for.cond.for.end5_crit_edge: ; preds = %for.inc3
|
|
ret void
|
|
}
|
|
|
|
|
|
; CHECK: --- !Missed
|
|
; CHECK-NEXT: Pass: loop-interchange
|
|
; CHECK-NEXT: Name: Dependence
|
|
; CHECK-NEXT: Function: test2
|
|
; CHECK-NEXT: Args:
|
|
; CHECK-NEXT: - String: Cannot interchange loops due to dependences.
|
|
|
|
define void @test2() {
|
|
entry:
|
|
br label %for.body
|
|
|
|
for.body: ; preds = %for.inc3, %entry
|
|
%inc41 = phi i32 [ %inc4, %for.inc3 ], [ undef, %entry ]
|
|
br label %for.body2
|
|
|
|
for.body2: ; preds = %for.inc, %for.body
|
|
%lsr.iv = phi i32 [ %lsr.iv.next, %for.inc ], [ 1, %for.body ]
|
|
br label %for.inc
|
|
|
|
for.inc: ; preds = %for.body2
|
|
%idxprom = sext i32 %inc41 to i64
|
|
%arrayidx = getelementptr inbounds [5 x i32], ptr @b, i64 0, i64 %idxprom
|
|
%0 = load i32, ptr %arrayidx, align 4
|
|
%cmp = icmp slt i32 %lsr.iv, 4
|
|
%cmp.zext = zext i1 %cmp to i32
|
|
store i32 %cmp.zext, ptr %arrayidx, align 4
|
|
%lsr.iv.next = add nuw nsw i32 %lsr.iv, 1
|
|
br i1 %cmp, label %for.body2, label %for.cond1.for.end_crit_edge
|
|
|
|
for.cond1.for.end_crit_edge: ; preds = %for.inc
|
|
br label %for.inc3
|
|
|
|
for.inc3: ; preds = %for.cond1.for.end_crit_edge
|
|
%inc4 = add nsw i32 %inc41, 1
|
|
br i1 false, label %for.body, label %for.cond.for.end5_crit_edge
|
|
|
|
for.cond.for.end5_crit_edge: ; preds = %for.inc3
|
|
ret void
|
|
}
|