| 1 |
; Remove 'S' Scalar Dependencies #119345 |
| 2 |
; Scalar dependencies are not handled correctly, so they were removed to avoid |
| 3 |
; miscompiles. The loop nest in this test case used to be interchanged, but it's |
| 4 |
; no longer triggering. XFAIL'ing this test to indicate that this test should |
| 5 |
; interchanged if scalar deps are handled correctly. |
| 6 |
; |
| 7 |
; XFAIL: * |
| 8 |
|
| 9 |
; RUN: opt < %s -passes=loop-interchange -pass-remarks-output=%t -disable-output |
| 10 |
; RUN: FileCheck -input-file %t %s |
| 11 |
|
| 12 |
@f = dso_local local_unnamed_addr global [4 x [9 x i32]] [[9 x i32] [i32 5, i32 3, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0], [9 x i32] zeroinitializer, [9 x i32] zeroinitializer, [9 x i32] zeroinitializer], align 4 |
| 13 |
@g = common dso_local local_unnamed_addr global i32 0, align 4 |
| 14 |
|
| 15 |
; int32_t f[3][3]; |
| 16 |
; int32_t g; |
| 17 |
; |
| 18 |
; int32_t test1(_Bool cond) { |
| 19 |
; for (int64_t i = 0; i < 3; i++) { |
| 20 |
; for (int64_t j = 0; j < 3; j++) { |
| 21 |
; int32_t val = f[i][j]; |
| 22 |
; if (val == 0) |
| 23 |
; if (!cond) |
| 24 |
; g++; |
| 25 |
; else |
| 26 |
; g = 3; |
| 27 |
; if (!cond) |
| 28 |
; g++; |
| 29 |
; } |
| 30 |
; } |
| 31 |
; return g; |
| 32 |
; } |
| 33 |
; |
| 34 |
define dso_local i32 @test1(i1 %cond) { |
| 35 |
; |
| 36 |
; FIXME: if there's an output dependency inside the loop and Src doesn't |
| 37 |
; dominate Dst, we should not interchange. Thus, this currently miscompiles. |
| 38 |
; |
| 39 |
; CHECK: --- !Passed |
| 40 |
; CHECK-NEXT: Pass: loop-interchange |
| 41 |
; CHECK-NEXT: Name: Interchanged |
| 42 |
; CHECK-NEXT: Function: test1 |
| 43 |
; CHECK-NEXT: Args: |
| 44 |
; CHECK-NEXT: - String: Loop interchanged with enclosing loop. |
| 45 |
; CHECK-NEXT: ... |
| 46 |
; |
| 47 |
for.preheader: |
| 48 |
br label %outerloop |
| 49 |
|
| 50 |
outerloop: |
| 51 |
%i = phi i64 [ 0, %for.preheader ], [ %indvars.iv.next21.i, %for.latch ] |
| 52 |
br label %innerloop |
| 53 |
|
| 54 |
innerloop: |
| 55 |
%j = phi i64 [ 0, %outerloop ], [ %j.next, %if.end ] |
| 56 |
%arrayidx6.i = getelementptr inbounds [4 x [9 x i32]], [4 x [9 x i32]]* @f, i64 0, i64 %j, i64 %i |
| 57 |
%i1 = load i32, i32* %arrayidx6.i, align 4 |
| 58 |
%tobool.i = icmp eq i32 %i1, 0 |
| 59 |
br i1 %tobool.i, label %land.end, label %land.rhs |
| 60 |
|
| 61 |
land.rhs: |
| 62 |
store i32 3, i32* @g, align 4 |
| 63 |
br label %land.end |
| 64 |
|
| 65 |
land.end: |
| 66 |
br i1 %cond, label %if.end, label %if.then |
| 67 |
|
| 68 |
if.then: |
| 69 |
%i2 = load i32, i32* @g, align 4 |
| 70 |
%inc.i = add i32 %i2, 1 |
| 71 |
store i32 %inc.i, i32* @g, align 4 |
| 72 |
br label %if.end |
| 73 |
|
| 74 |
if.end: |
| 75 |
%j.next = add nuw nsw i64 %j, 1 |
| 76 |
%exitcond.i = icmp eq i64 %j.next, 3 |
| 77 |
br i1 %exitcond.i, label %for.latch, label %innerloop |
| 78 |
|
| 79 |
for.latch: |
| 80 |
%indvars.iv.next21.i = add nsw i64 %i, 1 |
| 81 |
%cmp.i = icmp slt i64 %i, 2 |
| 82 |
br i1 %cmp.i, label %outerloop, label %exit |
| 83 |
|
| 84 |
exit: |
| 85 |
%i3 = load i32, i32* @g, align 4 |
| 86 |
ret i32 %i3 |
| 87 |
} |
| 88 |
|
| 89 |
; int32_t f[3][3]; |
| 90 |
; int32_t g; |
| 91 |
; |
| 92 |
; int32_t test2(_Bool cond) { |
| 93 |
; for (int64_t i = 0; i < 3; i++) { |
| 94 |
; for (int64_t j = 0; j < 3; j++) { |
| 95 |
; int32_t val = f[i][j]; |
| 96 |
; g = 3; |
| 97 |
; if (val == 0) |
| 98 |
; if (!cond) |
| 99 |
; g++; |
| 100 |
; else |
| 101 |
; if (!cond) |
| 102 |
; g++; |
| 103 |
; } |
| 104 |
; } |
| 105 |
; return g; |
| 106 |
; } |
| 107 |
; |
| 108 |
define dso_local i32 @test2(i1 %cond) { |
| 109 |
; |
| 110 |
; FIXME: if there's an output dependency inside the loop and Src doesn't |
| 111 |
; dominate Dst, we should not interchange. Thus, this currently miscompiles. |
| 112 |
; |
| 113 |
; CHECK: --- !Passed |
| 114 |
; CHECK-NEXT: Pass: loop-interchange |
| 115 |
; CHECK-NEXT: Name: Interchanged |
| 116 |
; CHECK-NEXT: Function: test2 |
| 117 |
; CHECK-NEXT: Args: |
| 118 |
; CHECK-NEXT: - String: Loop interchanged with enclosing loop. |
| 119 |
; CHECK-NEXT: ... |
| 120 |
; |
| 121 |
for.preheader: |
| 122 |
br label %outerloop |
| 123 |
|
| 124 |
outerloop: |
| 125 |
%i = phi i64 [ 0, %for.preheader ], [ %indvars.iv.next21.i, %for.latch ] |
| 126 |
br label %innerloop |
| 127 |
|
| 128 |
innerloop: |
| 129 |
%j = phi i64 [ 0, %outerloop ], [ %j.next, %if.end ] |
| 130 |
%arrayidx6.i = getelementptr inbounds [4 x [9 x i32]], [4 x [9 x i32]]* @f, i64 0, i64 %j, i64 %i |
| 131 |
%i1 = load i32, i32* %arrayidx6.i, align 4 |
| 132 |
%tobool.i = icmp eq i32 %i1, 0 |
| 133 |
store i32 3, i32* @g, align 4 |
| 134 |
br i1 %tobool.i, label %land.end, label %land.rhs |
| 135 |
|
| 136 |
land.rhs: |
| 137 |
br label %land.end |
| 138 |
|
| 139 |
land.end: |
| 140 |
br i1 %cond, label %if.end, label %if.then |
| 141 |
|
| 142 |
if.then: |
| 143 |
%i2 = load i32, i32* @g, align 4 |
| 144 |
%inc.i = add i32 %i2, 1 |
| 145 |
store i32 %inc.i, i32* @g, align 4 |
| 146 |
br label %if.end |
| 147 |
|
| 148 |
if.end: |
| 149 |
%j.next = add nuw nsw i64 %j, 1 |
| 150 |
%exitcond.i = icmp eq i64 %j.next, 3 |
| 151 |
br i1 %exitcond.i, label %for.latch, label %innerloop |
| 152 |
|
| 153 |
for.latch: |
| 154 |
%indvars.iv.next21.i = add nsw i64 %i, 1 |
| 155 |
%cmp.i = icmp slt i64 %i, 2 |
| 156 |
br i1 %cmp.i, label %outerloop, label %exit |
| 157 |
|
| 158 |
exit: |
| 159 |
%i3 = load i32, i32* @g, align 4 |
| 160 |
ret i32 %i3 |
| 161 |
} |