1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00
llvm-mirror/test/Analysis/ScalarEvolution/implied-via-addition.ll
Max Kazantsev ccddc942de [ScalarEvolution] Re-enable Predicate implication from operations
The patch rL298481 was reverted due to crash on clang-with-lto-ubuntu build.
The reason of the crash was type mismatch between either a or b and RHS in the following situation:

  LHS = sext(a +nsw b) > RHS.

This is quite rare, but still possible situation. Normally we need to cast all {a, b, RHS} to their widest type.
But we try to avoid creation of new SCEV that are not constants to avoid initiating recursive analysis that
can take a lot of time and/or cache a bad value for iterations number. To deal with this, in this patch we
reject this case and will not try to analyze it if the type of sum doesn't match with the type of RHS. In this
situation we don't need to create any non-constant SCEVs.

This patch also adds an assertion to the method IsProvedViaContext so that we could fail on it and not
go further into range analysis etc (because in some situations these analyzes succeed even when the passed
arguments have wrong types, what should not normally happen).

The patch also contains a fix for a problem with too narrow scope of the analysis caused by wrong
usage of predicates in recursive invocations.

The regression test on the said failure: test/Analysis/ScalarEvolution/implied-via-addition.ll

Reviewers: reames, apilipenko, anna, sanjoy

Reviewed By: sanjoy

Subscribers: mzolotukhin, mehdi_amini, llvm-commits

Differential Revision: https://reviews.llvm.org/D31238

llvm-svn: 299205
2017-03-31 12:05:30 +00:00

51 lines
1.1 KiB
LLVM

; RUN: opt -indvars -S < %s | FileCheck %s
declare void @use(i1)
declare void @llvm.experimental.guard(i1, ...)
define void @test_01(i8 %t) {
; CHECK-LABEL: test_01
entry:
%st = sext i8 %t to i16
%cmp1 = icmp slt i16 %st, 42
call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
br label %loop
loop:
; CHECK-LABEL: loop
%idx = phi i8 [ %t, %entry ], [ %idx.inc, %loop ]
%idx.inc = add i8 %idx, 1
%c = icmp slt i8 %idx, 42
; CHECK: call void @use(i1 true)
call void @use(i1 %c)
%be = icmp slt i8 %idx.inc, 42
br i1 %be, label %loop, label %exit
exit:
ret void
}
define void @test_02(i8 %t) {
; CHECK-LABEL: test_02
entry:
%t.ptr = inttoptr i8 %t to i8*
%p.42 = inttoptr i8 42 to i8*
%cmp1 = icmp slt i8* %t.ptr, %p.42
call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
br label %loop
loop:
; CHECK-LABEL: loop
%idx = phi i8* [ %t.ptr, %entry ], [ %snext, %loop ]
%snext = getelementptr inbounds i8, i8* %idx, i64 1
%c = icmp slt i8* %idx, %p.42
; CHECK: call void @use(i1 true)
call void @use(i1 %c)
%be = icmp slt i8* %snext, %p.42
br i1 %be, label %loop, label %exit
exit:
ret void
}