brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · d80b442 Raw
78 lines · plain
1; REQUIRES: asserts2 3; RUN: opt -passes=loop-interchange -debug -disable-output %s 2>&1 | FileCheck %s4 5@A = global [16 x [16 x i32]] zeroinitializer6 7; Check that the CacheCost is calculated only when required. In this case, it8; is computed after passing the legality check.9;10; for (i = 0; i < 16; i++)11;   for (j = 0; j < 16; j++)12;     A[j][i] += 1;13 14; CHECK: Loops are legal to interchange15; CHECK: Compute CacheCost16define void @legal_to_interchange() {17entry:18  br label %for.i.header19 20for.i.header:21  %i = phi i32 [ 0, %entry ], [ %i.next, %for.i.latch ]22  br label %for.j23 24for.j:25  %j = phi i32 [ 0, %for.i.header ], [ %j.next, %for.j ]26  %idx = getelementptr inbounds [16 x [16 x i32]], ptr @A, i32 0, i32 %j, i32 %i27  %val = load i32, ptr %idx28  %inc = add i32 %val, 129  store i32 %inc, ptr %idx30  %j.next = add i32 %j, 131  %j.exit = icmp eq i32 %j.next, 1632  br i1 %j.exit, label %for.i.latch, label %for.j33 34for.i.latch:35  %i.next = add i32 %i, 136  %i.exit = icmp eq i32 %i.next, 1637  br i1 %i.exit, label %exit, label %for.i.header38 39exit:40  ret void41}42 43; Check that the CacheCost is not calculated when not required. In this case,44; the legality check always fails so that we do not need to compute the45; CacheCost.46;47; for (i = 0; i < 16; i++)48;   for (j = 0; j < 16; j++)49;     A[j][i] = A[i][j];50 51; CHECK-NOT: Compute CacheCost52define void @illegal_to_interchange() {53entry:54  br label %for.i.header55 56for.i.header:57  %i = phi i32 [ 0, %entry ], [ %i.next, %for.i.latch ]58  br label %for.j59 60for.j:61  %j = phi i32 [ 0, %for.i.header ], [ %j.next, %for.j ]62  %idx.load = getelementptr inbounds [16 x [16 x i32]], ptr @A, i32 0, i32 %i, i32 %j63  %idx.store = getelementptr inbounds [16 x [16 x i32]], ptr @A, i32 0, i32 %j, i32 %i64  %val = load i32, ptr %idx.load65  store i32 %val, ptr %idx.store66  %j.next = add i32 %j, 167  %j.exit = icmp eq i32 %j.next, 1668  br i1 %j.exit, label %for.i.latch, label %for.j69 70for.i.latch:71  %i.next = add i32 %i, 172  %i.exit = icmp eq i32 %i.next, 1673  br i1 %i.exit, label %exit, label %for.i.header74 75exit:76  ret void77}78