1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00

[LoopIdiom,LSR] Add additional tests for SCEVExpander cleanups.

This commit is contained in:
Florian Hahn 2020-08-21 12:48:05 +01:00
parent a3ade83a86
commit 5440177a2e
2 changed files with 129 additions and 0 deletions

View File

@ -0,0 +1,64 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -loop-idiom -S %s | FileCheck %s
; Make sure we do not delete instructions not inserted during expansion, e.g.
; because the expande re-used existing instructions.
define void @test(i64 %init, float* %ptr) {
; CHECK-LABEL: @test(
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[OUTER_HEADER:%.*]]
; CHECK: outer.header:
; CHECK-NEXT: [[J_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[OUTER_LATCH:%.*]] ]
; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[ADD:%.*]], [[OUTER_LATCH]] ]
; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds float, float* [[PTR:%.*]], i32 [[I_0]]
; CHECK-NEXT: br label [[INNER:%.*]]
; CHECK: inner:
; CHECK-NEXT: [[INNER_IV:%.*]] = phi i64 [ [[INNER_IV_NEXT:%.*]], [[INNER]] ], [ [[INIT:%.*]], [[OUTER_HEADER]] ]
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, float* [[PTR]], i64 [[INNER_IV]]
; CHECK-NEXT: [[TMP0:%.*]] = bitcast float* [[ARRAYIDX]] to i32*
; CHECK-NEXT: [[TMP1:%.*]] = load i32, i32* [[TMP0]], align 4
; CHECK-NEXT: [[ARRAYIDX3:%.*]] = getelementptr inbounds float, float* [[ADD_PTR]], i64 [[INNER_IV]]
; CHECK-NEXT: [[TMP2:%.*]] = bitcast float* [[ARRAYIDX3]] to i32*
; CHECK-NEXT: store i32 [[TMP1]], i32* [[TMP2]], align 4
; CHECK-NEXT: [[INNER_IV_NEXT]] = add nsw i64 [[INNER_IV]], 1
; CHECK-NEXT: [[EC_1:%.*]] = icmp eq i64 [[INNER_IV_NEXT]], 0
; CHECK-NEXT: br i1 [[EC_1]], label [[OUTER_LATCH]], label [[INNER]]
; CHECK: outer.latch:
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[J_0]], 1
; CHECK-NEXT: [[ADD]] = add nuw nsw i32 [[I_0]], [[INC]]
; CHECK-NEXT: [[EC_2:%.*]] = icmp eq i32 [[ADD]], 4000
; CHECK-NEXT: br i1 [[EC_2]], label [[EXIT:%.*]], label [[OUTER_HEADER]]
; CHECK: exit:
; CHECK-NEXT: ret void
;
entry:
br label %outer.header
outer.header:
%j.0 = phi i32 [ 0, %entry ], [ %inc, %outer.latch ]
%i.0 = phi i32 [ 0, %entry ], [ %add, %outer.latch ]
%add.ptr = getelementptr inbounds float, float* %ptr, i32 %i.0
br label %inner
inner:
%inner.iv = phi i64 [ %inner.iv.next, %inner ], [ %init, %outer.header ]
%arrayidx = getelementptr inbounds float, float* %ptr, i64 %inner.iv
%0 = bitcast float* %arrayidx to i32*
%1 = load i32, i32* %0, align 4
%arrayidx3 = getelementptr inbounds float, float* %add.ptr, i64 %inner.iv
%2 = bitcast float* %arrayidx3 to i32*
store i32 %1, i32* %2, align 4
%inner.iv.next = add nsw i64 %inner.iv, 1
%ec.1 = icmp eq i64 %inner.iv.next, 0
br i1 %ec.1, label %outer.latch, label %inner
outer.latch:
%inc = add nuw nsw i32 %j.0, 1
%add = add nuw nsw i32 %i.0, %inc
%ec.2 = icmp eq i32 %add, 4000
br i1 %ec.2, label %exit, label %outer.header
exit:
ret void
}

View File

@ -0,0 +1,65 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -loop-reduce -S %s | FileCheck %s
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.15.0"
declare void @use(double) readnone
; Make sure re-used instructions do not impact the insertion points for SCEV
; expansion.
define void @test(double* %ioptr, i32 %X, double* %start, double* %end) {
; CHECK-LABEL: @test(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[IDX_EXT32:%.*]] = sext i32 [[X:%.*]] to i64
; CHECK-NEXT: [[TMP0:%.*]] = shl nsw i64 [[IDX_EXT32]], 3
; CHECK-NEXT: [[TMP1:%.*]] = add nsw i64 [[TMP0]], 8
; CHECK-NEXT: br label [[FOR_BODY15:%.*]]
; CHECK: for.body15:
; CHECK-NEXT: br label [[FOR_BODY37:%.*]]
; CHECK: for.body37:
; CHECK-NEXT: [[P0R_0335:%.*]] = phi double* [ [[ADD_PTR94:%.*]], [[FOR_BODY37]] ], [ [[START:%.*]], [[FOR_BODY15]] ]
; CHECK-NEXT: [[ADD_PTR94]] = getelementptr inbounds double, double* [[P0R_0335]], i64 1
; CHECK-NEXT: [[P0R_03351:%.*]] = bitcast double* [[P0R_0335]] to i8*
; CHECK-NEXT: [[UGLYGEP:%.*]] = getelementptr i8, i8* [[P0R_03351]], i64 [[TMP1]]
; CHECK-NEXT: [[UGLYGEP2:%.*]] = bitcast i8* [[UGLYGEP]] to double*
; CHECK-NEXT: [[F1I_0:%.*]] = load double, double* [[UGLYGEP2]], align 8
; CHECK-NEXT: call void @use(double [[F1I_0]])
; CHECK-NEXT: [[EC0:%.*]] = icmp eq double* [[END:%.*]], [[ADD_PTR94]]
; CHECK-NEXT: br i1 [[EC0]], label [[FOR_BODY37]], label [[FOR_END_LOOPEXIT:%.*]]
; CHECK: for.end.loopexit:
; CHECK-NEXT: br label [[FOR_END:%.*]]
; CHECK: for.end:
; CHECK-NEXT: [[P0R_0_LCSSA:%.*]] = phi double* [ [[ADD_PTR94]], [[FOR_END_LOOPEXIT]] ]
; CHECK-NEXT: [[EC1:%.*]] = icmp eq double* [[P0R_0_LCSSA]], [[END]]
; CHECK-NEXT: br i1 [[EC1]], label [[FOR_BODY15]], label [[FOR_INC133:%.*]]
; CHECK: for.inc133:
; CHECK-NEXT: ret void
;
entry:
%idx.ext32 = sext i32 %X to i64
br label %for.body15
for.body15: ; preds = %for.end, %for.body15.lr.ph
br label %for.body37
for.body37: ; preds = %for.body37, %for.body37.preheader
%p0r.0335 = phi double* [ %add.ptr94, %for.body37 ], [ %start, %for.body15 ]
%add.ptr94 = getelementptr inbounds double, double* %p0r.0335, i64 1
%f1i.0.in = getelementptr inbounds double, double* %add.ptr94, i64 %idx.ext32
%f1i.0 = load double, double* %f1i.0.in, align 8
call void @use(double %f1i.0)
%ec0 = icmp eq double* %add.ptr94, %end
br i1 %ec0, label %for.body37, label %for.end.loopexit
for.end.loopexit: ; preds = %for.body37
br label %for.end
for.end: ; preds = %for.end.loopexit, %for.body15
%p0r.0.lcssa = phi double* [ %add.ptr94, %for.end.loopexit ]
%ec1 = icmp eq double* %p0r.0.lcssa, %end
br i1 %ec1, label %for.body15, label %for.inc133
for.inc133: ; preds = %for.end
ret void
}