162 lines · plain
1; Remove 'S' Scalar Dependencies #1193452; Scalar dependencies are not handled correctly, so they were removed to avoid3; miscompiles. The loop nest in this test case used to be interchanged, but it's4; no longer triggering. XFAIL'ing this test to indicate that this test should5; interchanged if scalar deps are handled correctly.6;7; XFAIL: *8 9; RUN: opt < %s -passes=loop-interchange -pass-remarks-output=%t -disable-output10; RUN: FileCheck -input-file %t %s11 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 413@g = common dso_local local_unnamed_addr global i32 0, align 414 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; else26; g = 3;27; if (!cond)28; g++;29; }30; }31; return g;32; }33;34define dso_local i32 @test1(i1 %cond) {35;36; FIXME: if there's an output dependency inside the loop and Src doesn't37; dominate Dst, we should not interchange. Thus, this currently miscompiles.38;39; CHECK: --- !Passed40; CHECK-NEXT: Pass: loop-interchange41; CHECK-NEXT: Name: Interchanged42; CHECK-NEXT: Function: test143; CHECK-NEXT: Args:44; CHECK-NEXT: - String: Loop interchanged with enclosing loop.45; CHECK-NEXT: ...46;47for.preheader:48 br label %outerloop49 50outerloop:51 %i = phi i64 [ 0, %for.preheader ], [ %indvars.iv.next21.i, %for.latch ]52 br label %innerloop53 54innerloop: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 %i57 %i1 = load i32, i32* %arrayidx6.i, align 458 %tobool.i = icmp eq i32 %i1, 059 br i1 %tobool.i, label %land.end, label %land.rhs60 61land.rhs:62 store i32 3, i32* @g, align 463 br label %land.end64 65land.end:66 br i1 %cond, label %if.end, label %if.then67 68if.then:69 %i2 = load i32, i32* @g, align 470 %inc.i = add i32 %i2, 171 store i32 %inc.i, i32* @g, align 472 br label %if.end73 74if.end:75 %j.next = add nuw nsw i64 %j, 176 %exitcond.i = icmp eq i64 %j.next, 377 br i1 %exitcond.i, label %for.latch, label %innerloop78 79for.latch:80 %indvars.iv.next21.i = add nsw i64 %i, 181 %cmp.i = icmp slt i64 %i, 282 br i1 %cmp.i, label %outerloop, label %exit83 84exit:85 %i3 = load i32, i32* @g, align 486 ret i32 %i387}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; else101; if (!cond)102; g++;103; }104; }105; return g;106; }107;108define dso_local i32 @test2(i1 %cond) {109;110; FIXME: if there's an output dependency inside the loop and Src doesn't111; dominate Dst, we should not interchange. Thus, this currently miscompiles.112;113; CHECK: --- !Passed114; CHECK-NEXT: Pass: loop-interchange115; CHECK-NEXT: Name: Interchanged116; CHECK-NEXT: Function: test2117; CHECK-NEXT: Args:118; CHECK-NEXT: - String: Loop interchanged with enclosing loop.119; CHECK-NEXT: ...120;121for.preheader:122 br label %outerloop123 124outerloop:125 %i = phi i64 [ 0, %for.preheader ], [ %indvars.iv.next21.i, %for.latch ]126 br label %innerloop127 128innerloop: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 %i131 %i1 = load i32, i32* %arrayidx6.i, align 4132 %tobool.i = icmp eq i32 %i1, 0133 store i32 3, i32* @g, align 4134 br i1 %tobool.i, label %land.end, label %land.rhs135 136land.rhs:137 br label %land.end138 139land.end:140 br i1 %cond, label %if.end, label %if.then141 142if.then:143 %i2 = load i32, i32* @g, align 4144 %inc.i = add i32 %i2, 1145 store i32 %inc.i, i32* @g, align 4146 br label %if.end147 148if.end:149 %j.next = add nuw nsw i64 %j, 1150 %exitcond.i = icmp eq i64 %j.next, 3151 br i1 %exitcond.i, label %for.latch, label %innerloop152 153for.latch:154 %indvars.iv.next21.i = add nsw i64 %i, 1155 %cmp.i = icmp slt i64 %i, 2156 br i1 %cmp.i, label %outerloop, label %exit157 158exit:159 %i3 = load i32, i32* @g, align 4160 ret i32 %i3161}162