| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6 |
| ; RUN: opt < %s -passes=loop-interchange -S | FileCheck %s |
| |
| ; This test used to crash due to a dereference of a null ScalarEvolution pointer |
| ; inside isReductionPHI. |
| define void @reduction_smax_store(ptr %A) { |
| ; CHECK-LABEL: define void @reduction_smax_store( |
| ; CHECK-SAME: ptr [[A:%.*]]) { |
| ; 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: [[MAX_I:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ [[MAX_I_LCSSA:%.*]], %[[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: [[MAX_J:%.*]] = phi i32 [ [[MAX_I]], %[[FOR_I_HEADER]] ], [ [[MAX_J_NEXT:%.*]], %[[FOR_J]] ] |
| ; CHECK-NEXT: [[IDX:%.*]] = getelementptr inbounds [2 x [2 x i32]], ptr [[A]], i32 0, i32 [[J]], i32 [[I]] |
| ; CHECK-NEXT: [[A:%.*]] = load i32, ptr [[IDX]], align 4 |
| ; CHECK-NEXT: [[MAX_J_NEXT]] = tail call i32 @llvm.smax.i32(i32 [[MAX_J]], i32 [[A]]) |
| ; CHECK-NEXT: store i32 [[MAX_J_NEXT]], ptr [[IDX]], align 4 |
| ; CHECK-NEXT: [[J_INC]] = add i32 [[J]], 1 |
| ; CHECK-NEXT: [[CMP_J:%.*]] = icmp slt i32 [[J_INC]], 2 |
| ; CHECK-NEXT: br i1 [[CMP_J]], label %[[FOR_J]], label %[[FOR_I_LATCH]] |
| ; CHECK: [[FOR_I_LATCH]]: |
| ; CHECK-NEXT: [[MAX_I_LCSSA]] = phi i32 [ [[MAX_J_NEXT]], %[[FOR_J]] ] |
| ; CHECK-NEXT: [[I_INC]] = add i32 [[I]], 1 |
| ; CHECK-NEXT: [[CMP_I:%.*]] = icmp slt i32 [[I_INC]], 2 |
| ; 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 ] |
| %max.i = phi i32 [ 0, %entry ], [ %max.i.lcssa, %for.i.latch ] |
| br label %for.j |
| |
| for.j: |
| %j = phi i32 [ 0, %for.i.header ], [ %j.inc, %for.j ] |
| %max.j = phi i32 [ %max.i, %for.i.header ], [ %max.j.next, %for.j ] |
| %idx = getelementptr inbounds [2 x [2 x i32]], ptr %A, i32 0, i32 %j, i32 %i |
| %a = load i32, ptr %idx, align 4 |
| %max.j.next = tail call i32 @llvm.smax.i32(i32 %max.j, i32 %a) |
| store i32 %max.j.next, ptr %idx |
| %j.inc = add i32 %j, 1 |
| %cmp.j = icmp slt i32 %j.inc, 2 |
| br i1 %cmp.j, label %for.j, label %for.i.latch |
| |
| for.i.latch: |
| %max.i.lcssa = phi i32 [ %max.j.next, %for.j ] |
| %i.inc = add i32 %i, 1 |
| %cmp.i = icmp slt i32 %i.inc, 2 |
| br i1 %cmp.i, label %for.i.header, label %exit |
| |
| exit: |
| ret void |
| } |