mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:32:44 +01:00
[LoopIdiom] Add additional test cases.
This commit is contained in:
parent
8a486ecfa3
commit
fa290f0aab
59
test/Transforms/LoopIdiom/phi-insertion.ll
Normal file
59
test/Transforms/LoopIdiom/phi-insertion.ll
Normal file
@ -0,0 +1,59 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
||||
; RUN: opt -loop-idiom -S %s | FileCheck %s
|
||||
|
||||
define void @phi_insertion(i1 %c, i32* %ptr.start, i32* %ptr.end, i64 %offset) {
|
||||
; CHECK-LABEL: @phi_insertion(
|
||||
; CHECK-NEXT: bb5:
|
||||
; CHECK-NEXT: br i1 [[C:%.*]], label [[LOOP_0_PH:%.*]], label [[EXIT:%.*]]
|
||||
; CHECK: loop.0.ph:
|
||||
; CHECK-NEXT: br label [[LOOP_0:%.*]]
|
||||
; CHECK: loop.0:
|
||||
; CHECK-NEXT: [[IV_0:%.*]] = phi i32* [ [[IV_0_NEXT:%.*]], [[LOOP_0_LATCH:%.*]] ], [ [[PTR_START:%.*]], [[LOOP_0_PH]] ]
|
||||
; CHECK-NEXT: [[COND:%.*]] = icmp eq i32* [[IV_0]], [[PTR_END:%.*]]
|
||||
; CHECK-NEXT: br i1 [[COND]], label [[LOOP_1_PREHEADER:%.*]], label [[EXIT_LOOPEXIT:%.*]]
|
||||
; CHECK: loop.1.preheader:
|
||||
; CHECK-NEXT: br label [[LOOP_1:%.*]]
|
||||
; CHECK: loop.1:
|
||||
; CHECK-NEXT: [[PTR_1:%.*]] = getelementptr inbounds i32, i32* [[IV_0]], i64 0
|
||||
; CHECK-NEXT: [[LV:%.*]] = load i32, i32* [[PTR_1]], align 8
|
||||
; CHECK-NEXT: [[PTR_2:%.*]] = getelementptr inbounds i32, i32* [[IV_0]], i64 0
|
||||
; CHECK-NEXT: store i32 [[LV]], i32* [[PTR_2]], align 8
|
||||
; CHECK-NEXT: [[IV_1_NEXT:%.*]] = add nuw nsw i64 0, 1
|
||||
; CHECK-NEXT: [[EC:%.*]] = icmp eq i64 [[IV_1_NEXT]], 100
|
||||
; CHECK-NEXT: br i1 [[EC]], label [[LOOP_0_LATCH]], label [[LOOP_1]]
|
||||
; CHECK: loop.0.latch:
|
||||
; CHECK-NEXT: [[IV_0_NEXT]] = getelementptr inbounds i32, i32* [[IV_0]], i64 [[OFFSET:%.*]]
|
||||
; CHECK-NEXT: br label [[LOOP_0]]
|
||||
; CHECK: exit.loopexit:
|
||||
; CHECK-NEXT: br label [[EXIT]]
|
||||
; CHECK: exit:
|
||||
; CHECK-NEXT: ret void
|
||||
;
|
||||
bb5:
|
||||
br i1 %c, label %loop.0.ph, label %exit
|
||||
|
||||
loop.0.ph: ; preds = %bb5
|
||||
br label %loop.0
|
||||
|
||||
loop.0: ; preds = %loop.0.latch, %loop.0.ph
|
||||
%iv.0 = phi i32* [ %iv.0.next, %loop.0.latch ], [ %ptr.start, %loop.0.ph ]
|
||||
%cond = icmp eq i32* %iv.0, %ptr.end
|
||||
br i1 %cond, label %loop.1, label %exit
|
||||
|
||||
loop.1: ; preds = %loop.1, %loop.0
|
||||
%iv.1 = phi i64 [ 0, %loop.0 ], [ %iv.1, %loop.1 ]
|
||||
%ptr.1 = getelementptr inbounds i32, i32* %iv.0, i64 %iv.1
|
||||
%lv = load i32, i32* %ptr.1, align 8
|
||||
%ptr.2 = getelementptr inbounds i32, i32* %iv.0, i64 %iv.1
|
||||
store i32 %lv, i32* %ptr.2, align 8
|
||||
%iv.1.next = add nuw nsw i64 %iv.1, 1
|
||||
%ec = icmp eq i64 %iv.1.next, 100
|
||||
br i1 %ec, label %loop.0.latch, label %loop.1
|
||||
|
||||
loop.0.latch: ; preds = %loop.1
|
||||
%iv.0.next = getelementptr inbounds i32, i32* %iv.0, i64 %offset
|
||||
br label %loop.0
|
||||
|
||||
exit: ; preds = %loop.0, %bb5
|
||||
ret void
|
||||
}
|
131
test/Transforms/LoopIdiom/reuse-cast.ll
Normal file
131
test/Transforms/LoopIdiom/reuse-cast.ll
Normal file
@ -0,0 +1,131 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
||||
; RUN: opt -loop-idiom -S %s | FileCheck %s
|
||||
|
||||
define void @reuse_cast_1(float** %ptr, i1 %c) {
|
||||
; CHECK-LABEL: @reuse_cast_1(
|
||||
; CHECK-NEXT: entry:
|
||||
; CHECK-NEXT: br label [[LOOP_0:%.*]]
|
||||
; CHECK: loop.0:
|
||||
; CHECK-NEXT: [[TMP:%.*]] = load float*, float** [[PTR:%.*]], align 8
|
||||
; CHECK-NEXT: [[TMP2:%.*]] = bitcast float* [[TMP]] to i8*
|
||||
; CHECK-NEXT: br i1 [[C:%.*]], label [[LOOP_2_PREHEADER:%.*]], label [[LOOP_1_PREHEADER:%.*]]
|
||||
; CHECK: loop.1.preheader:
|
||||
; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 4 [[TMP2]], i8 0, i64 400, i1 false)
|
||||
; CHECK-NEXT: br label [[LOOP_1:%.*]]
|
||||
; CHECK: loop.2.preheader:
|
||||
; CHECK-NEXT: br label [[LOOP_2:%.*]]
|
||||
; CHECK: loop.1:
|
||||
; CHECK-NEXT: [[IV_1:%.*]] = phi i64 [ [[IV_1_NEXT:%.*]], [[LOOP_1]] ], [ 0, [[LOOP_1_PREHEADER]] ]
|
||||
; CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds float, float* [[TMP]], i64 [[IV_1]]
|
||||
; CHECK-NEXT: [[IV_1_NEXT]] = add nuw nsw i64 [[IV_1]], 1
|
||||
; CHECK-NEXT: [[C_1:%.*]] = icmp ne i64 [[IV_1_NEXT]], 100
|
||||
; CHECK-NEXT: br i1 [[C_1]], label [[LOOP_1]], label [[LOOP_0_LATCH_LOOPEXIT1:%.*]]
|
||||
; CHECK: loop.2:
|
||||
; CHECK-NEXT: [[IV_2:%.*]] = phi i64 [ [[IV_2_NEXT:%.*]], [[LOOP_2]] ], [ 0, [[LOOP_2_PREHEADER]] ]
|
||||
; CHECK-NEXT: [[TMP10:%.*]] = getelementptr inbounds float, float* [[TMP]], i64 [[IV_2]]
|
||||
; CHECK-NEXT: store float 0.000000e+00, float* [[TMP10]], align 4
|
||||
; CHECK-NEXT: [[TMP11:%.*]] = load float*, float** [[PTR]], align 8
|
||||
; CHECK-NEXT: [[TMP12:%.*]] = getelementptr inbounds float, float* [[TMP11]], i64 [[IV_2]]
|
||||
; CHECK-NEXT: [[TMP13:%.*]] = load float, float* [[TMP12]], align 4
|
||||
; CHECK-NEXT: [[IV_2_NEXT]] = add nuw nsw i64 [[IV_2]], 1
|
||||
; CHECK-NEXT: [[C_2:%.*]] = icmp ne i64 [[IV_2_NEXT]], 100
|
||||
; CHECK-NEXT: br i1 [[C_2]], label [[LOOP_2]], label [[LOOP_0_LATCH_LOOPEXIT:%.*]]
|
||||
; CHECK: loop.0.latch.loopexit:
|
||||
; CHECK-NEXT: br label [[LOOP_0_LATCH:%.*]]
|
||||
; CHECK: loop.0.latch.loopexit1:
|
||||
; CHECK-NEXT: br label [[LOOP_0_LATCH]]
|
||||
; CHECK: loop.0.latch:
|
||||
; CHECK-NEXT: [[C_0:%.*]] = call i1 @cond()
|
||||
; CHECK-NEXT: br i1 [[C_0]], label [[LOOP_0]], label [[END:%.*]]
|
||||
; CHECK: end:
|
||||
; CHECK-NEXT: ret void
|
||||
;
|
||||
entry:
|
||||
br label %loop.0
|
||||
|
||||
loop.0: ; preds = %loop.0.latch, %entry
|
||||
%tmp = load float*, float** %ptr, align 8
|
||||
br i1 %c, label %loop.2, label %loop.1
|
||||
|
||||
loop.1: ; preds = %loop.1, %loop.0
|
||||
%iv.1 = phi i64 [ %iv.1.next, %loop.1 ], [ 0, %loop.0 ]
|
||||
%tmp4 = getelementptr inbounds float, float* %tmp, i64 %iv.1
|
||||
store float 0.000000e+00, float* %tmp4, align 4
|
||||
%iv.1.next = add nuw nsw i64 %iv.1, 1
|
||||
%c.1 = icmp ne i64 %iv.1.next, 100
|
||||
br i1 %c.1, label %loop.1, label %loop.0.latch
|
||||
|
||||
loop.2: ; preds = %loop.2, %loop.0
|
||||
%iv.2 = phi i64 [ %iv.2.next, %loop.2 ], [ 0, %loop.0 ]
|
||||
%tmp10 = getelementptr inbounds float, float* %tmp, i64 %iv.2
|
||||
store float 0.000000e+00, float* %tmp10, align 4
|
||||
%tmp11 = load float*, float** %ptr, align 8
|
||||
%tmp12 = getelementptr inbounds float, float* %tmp11, i64 %iv.2
|
||||
%tmp13 = load float, float* %tmp12, align 4
|
||||
%iv.2.next = add nuw nsw i64 %iv.2, 1
|
||||
%c.2 = icmp ne i64 %iv.2.next, 100
|
||||
br i1 %c.2, label %loop.2, label %loop.0.latch
|
||||
|
||||
loop.0.latch: ; preds = %loop.2, %loop.1
|
||||
%c.0 = call i1 @cond()
|
||||
br i1 %c.0, label %loop.0, label %end
|
||||
|
||||
end: ; preds = %loop.0.latch
|
||||
ret void
|
||||
}
|
||||
|
||||
declare i1 @cond()
|
||||
|
||||
declare void @use.i8(i8*)
|
||||
|
||||
declare void @use.i1(i1)
|
||||
|
||||
define void @reuse_cast_2(i32 %x, i32* %ptr.1.start) {
|
||||
; CHECK-LABEL: @reuse_cast_2(
|
||||
; CHECK-NEXT: entry:
|
||||
; CHECK-NEXT: [[STACK:%.*]] = alloca [2 x i32], align 4
|
||||
; CHECK-NEXT: [[CAST_TO_REUSE:%.*]] = bitcast [2 x i32]* [[STACK]] to i8*
|
||||
; CHECK-NEXT: [[C_0:%.*]] = icmp sgt i32 [[X:%.*]], 0
|
||||
; CHECK-NEXT: [[TMP0:%.*]] = bitcast [2 x i32]* [[STACK]] to i8*
|
||||
; CHECK-NEXT: [[PTR_2_START:%.*]] = getelementptr inbounds [2 x i32], [2 x i32]* [[STACK]], i64 0, i64 0
|
||||
; CHECK-NEXT: call void @use.i8(i8* [[CAST_TO_REUSE]])
|
||||
; CHECK-NEXT: br label [[LOOP:%.*]]
|
||||
; CHECK: loop:
|
||||
; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
|
||||
; CHECK-NEXT: [[PTR_1:%.*]] = phi i32* [ [[PTR_1_START:%.*]], [[ENTRY]] ], [ [[PTR_1_NEXT:%.*]], [[LOOP]] ]
|
||||
; CHECK-NEXT: [[PTR_2:%.*]] = phi i32* [ [[PTR_2_START]], [[ENTRY]] ], [ [[PTR_2_NEXT:%.*]], [[LOOP]] ]
|
||||
; CHECK-NEXT: [[PTR_1_NEXT]] = getelementptr inbounds i32, i32* [[PTR_1]], i64 1
|
||||
; CHECK-NEXT: [[LV:%.*]] = load i32, i32* [[PTR_1]], align 4
|
||||
; CHECK-NEXT: [[PTR_2_NEXT]] = getelementptr inbounds i32, i32* [[PTR_2]], i64 1
|
||||
; CHECK-NEXT: store i32 [[LV]], i32* [[PTR_2]], align 4
|
||||
; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
|
||||
; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[IV]], 0
|
||||
; CHECK-NEXT: br i1 [[C_1]], label [[LOOP]], label [[EXIT:%.*]]
|
||||
; CHECK: exit:
|
||||
; CHECK-NEXT: call void @use.i1(i1 [[C_0]])
|
||||
; CHECK-NEXT: ret void
|
||||
;
|
||||
entry:
|
||||
%stack = alloca [2 x i32], align 4
|
||||
%c.0 = icmp sgt i32 %x, 0
|
||||
%cast.to.reuse = bitcast [2 x i32]* %stack to i8*
|
||||
%ptr.2.start = getelementptr inbounds [2 x i32], [2 x i32]* %stack, i64 0, i64 0
|
||||
call void @use.i8(i8* %cast.to.reuse)
|
||||
br label %loop
|
||||
|
||||
loop: ; preds = %loop, %entry
|
||||
%iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
|
||||
%ptr.1 = phi i32* [ %ptr.1.start, %entry ], [ %ptr.1.next, %loop ]
|
||||
%ptr.2 = phi i32* [ %ptr.2.start, %entry ], [ %ptr.2.next, %loop ]
|
||||
%ptr.1.next = getelementptr inbounds i32, i32* %ptr.1, i64 1
|
||||
%lv = load i32, i32* %ptr.1, align 4
|
||||
%ptr.2.next = getelementptr inbounds i32, i32* %ptr.2, i64 1
|
||||
store i32 %lv, i32* %ptr.2, align 4
|
||||
%iv.next = add nuw nsw i32 %iv, 1
|
||||
%c.1 = icmp eq i32 %iv, 0
|
||||
br i1 %c.1, label %loop, label %exit
|
||||
|
||||
exit: ; preds = %loop
|
||||
call void @use.i1(i1 %c.0)
|
||||
ret void
|
||||
}
|
Loading…
Reference in New Issue
Block a user