1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-24 21:42:54 +02:00
llvm-mirror/test/Transforms/IndVarSimplify/ult-sub-to-eq.ll
Ehsan Amiri 05c5b8d72c Extend trip count instead of truncating IV in LFTR, when legal
When legal, extending trip count in the loop control logic generates better code compared to truncating IV. This is because

(1) extending trip count is a loop invariant operation (see genLoopLimit where we prove trip count is loop invariant).
(2) Scalar Evolution seems to have problems understanding trunc when computing loop trip count. So removing them allows better analysis performed in Scalar Evolution. (In particular this fixes PR 28363 which is the motivation for this change).

I am not going to perform any performance test. Any degradation caused by this should be an indication of a bug elsewhere.

To prove legality, we rely on SCEV to prove zext(trunc(IV)) == IV (or similarly for sext). If this holds, we can prove equivalence of trunc(IV)==ExitCnt (1) and IV == zext(ExitCnt). Simply take zext of boths sides of (1) and apply the proven equivalence.

This commit contains changes in a newly added testcase which was not included in the previous commit (which was reverted later on).

https://reviews.llvm.org/D23075

llvm-svn: 278421
2016-08-11 21:31:40 +00:00

42 lines
1.5 KiB
LLVM

; RUN: opt -S -indvars < %s | FileCheck %s
; Provide legal integer types.
target datalayout = "n8:16:32:64"
define void @test1(float* nocapture %autoc, float* nocapture %data, float %d, i32 %data_len, i32 %sample) nounwind {
entry:
%sub = sub i32 %data_len, %sample
%cmp4 = icmp eq i32 %data_len, %sample
br i1 %cmp4, label %for.end, label %for.body
for.body: ; preds = %entry, %for.body
%indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
%0 = trunc i64 %indvars.iv to i32
%add = add i32 %0, %sample
%idxprom = zext i32 %add to i64
%arrayidx = getelementptr inbounds float, float* %data, i64 %idxprom
%1 = load float, float* %arrayidx, align 4
%mul = fmul float %1, %d
%arrayidx2 = getelementptr inbounds float, float* %autoc, i64 %indvars.iv
%2 = load float, float* %arrayidx2, align 4
%add3 = fadd float %2, %mul
store float %add3, float* %arrayidx2, align 4
%indvars.iv.next = add i64 %indvars.iv, 1
%3 = trunc i64 %indvars.iv.next to i32
%cmp = icmp ult i32 %3, %sub
br i1 %cmp, label %for.body, label %for.end
for.end: ; preds = %for.body, %entry
ret void
; CHECK-LABEL: @test1(
; check that we turn the IV test into an eq.
; CHECK: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
; CHECK: %wide.trip.count = zext i32 %sub to i64
; CHECK: %exitcond = icmp ne i64 %indvars.iv.next, %wide.trip.count
; CHECK: br i1 %exitcond, label %for.body, label %for.end.loopexit
}