| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6 |
| ; RUN: opt < %s -passes=loop-interchange -S | FileCheck %s |
| |
| ;; In the following case, p0 and p1 may alias, so the direction vector must be [* *]. |
| ;; |
| ;; void may_alias(float *p0, float *p1) { |
| ;; for (int i = 0; i < 4; i++) |
| ;; for (int j = 0; j < 4; j++) |
| ;; p0[4 * i + j] = p1[4 * j + i]; |
| ;; } |
| |
| define void @may_alias(ptr %p0, ptr %p1) { |
| ; CHECK-LABEL: define void @may_alias( |
| ; CHECK-SAME: ptr [[P0:%.*]], ptr [[P1:%.*]]) { |
| ; CHECK-NEXT: [[ENTRY:.*]]: |
| ; CHECK-NEXT: br label %[[FOR_I_HEADER:.*]] |
| ; CHECK: [[FOR_I_HEADER]]: |
| ; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ [[I_INC:%.*]], %[[FOR_I_LATCH:.*]] ] |
| ; CHECK-NEXT: br label %[[FOR_J:.*]] |
| ; CHECK: [[FOR_J]]: |
| ; CHECK-NEXT: [[J:%.*]] = phi i32 [ 0, %[[FOR_I_HEADER]] ], [ [[J_INC:%.*]], %[[FOR_J]] ] |
| ; CHECK-NEXT: [[IDX_0:%.*]] = getelementptr inbounds [4 x [4 x float]], ptr [[P0]], i32 0, i32 [[J]], i32 [[I]] |
| ; CHECK-NEXT: [[IDX_1:%.*]] = getelementptr inbounds [4 x [4 x float]], ptr [[P1]], i32 0, i32 [[I]], i32 [[J]] |
| ; CHECK-NEXT: [[TMP0:%.*]] = load float, ptr [[IDX_0]], align 4 |
| ; CHECK-NEXT: store float [[TMP0]], ptr [[IDX_1]], align 4 |
| ; CHECK-NEXT: [[J_INC]] = add nuw nsw i32 [[J]], 1 |
| ; CHECK-NEXT: [[CMP_J:%.*]] = icmp slt i32 [[J_INC]], 4 |
| ; CHECK-NEXT: br i1 [[CMP_J]], label %[[FOR_J]], label %[[FOR_I_LATCH]] |
| ; CHECK: [[FOR_I_LATCH]]: |
| ; CHECK-NEXT: [[I_INC]] = add nuw nsw i32 [[I]], 1 |
| ; CHECK-NEXT: [[CMP_I:%.*]] = icmp slt i32 [[I_INC]], 4 |
| ; CHECK-NEXT: br i1 [[CMP_I]], label %[[FOR_I_HEADER]], label %[[EXIT:.*]] |
| ; CHECK: [[EXIT]]: |
| ; CHECK-NEXT: ret void |
| ; |
| entry: |
| br label %for.i.header |
| |
| for.i.header: |
| %i = phi i32 [ 0, %entry ], [ %i.inc, %for.i.latch ] |
| br label %for.j |
| |
| for.j: |
| %j = phi i32 [ 0, %for.i.header ], [ %j.inc, %for.j ] |
| %idx.0 = getelementptr inbounds [4 x [4 x float]], ptr %p0, i32 0, i32 %j, i32 %i |
| %idx.1 = getelementptr inbounds [4 x [4 x float]], ptr %p1, i32 0, i32 %i, i32 %j |
| %0 = load float, ptr %idx.0, align 4 |
| store float %0, ptr %idx.1, align 4 |
| %j.inc = add nuw nsw i32 %j, 1 |
| %cmp.j = icmp slt i32 %j.inc, 4 |
| br i1 %cmp.j, label %for.j, label %for.i.latch |
| |
| for.i.latch: |
| %i.inc = add nuw nsw i32 %i, 1 |
| %cmp.i = icmp slt i32 %i.inc, 4 |
| br i1 %cmp.i, label %for.i.header, label %exit |
| |
| exit: |
| ret void |
| } |