• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -indvars -S | FileCheck %s
2
3; This is regression test for the bug in ScalarEvolution::isKnownPredicate.
4; It does not check whether SCEV is available at loop entry before invoking
5; and utility function isLoopEntryGuardedByCond and that leads to miscompile.
6
7target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128-ni:1"
8target triple = "x86_64-unknown-linux-gnu"
9
10declare void @foo(i64)
11declare void @bar(i32)
12
13define void @test(i8* %arr) {
14entry:
15  br label %outer_header
16
17outer_header:
18  %i = phi i32 [40, %entry], [%i.next, %outer_latch]
19  %i.64 = sext i32 %i to i64
20  br label %inner_header
21
22inner_header:
23  %j = phi i32 [27, %outer_header], [%j.next, %inner_backedge]
24  %j1 = zext i32 %j to i64
25; The next 4 lines are required for avoid widening of %j and
26; SCEV at %cmp would not be AddRec.
27  %gep = getelementptr inbounds i8, i8*  %arr, i64 %j1
28  %ld = load i8, i8* %gep
29  %ec = icmp eq i8 %ld, 0
30  br i1 %ec, label %return, label %inner_backedge
31
32inner_backedge:
33  %cmp = icmp ult i32 %j, %i
34  %s = select i1 %cmp, i32 %i, i32 %j
35; Select should not be simplified because if
36; %i == 26 and %j == 27, %s should be equal to %j.
37; In case of a bug the instruction is simplified to
38; %s = select i1 true, i32 %0, i32 %j
39; CHECK-NOT: %s = select i1 true
40  call void @bar(i32 %s)
41  %j.next = add nsw i32 %j, -2
42  %cond = icmp ult i32 %j, 3
43  br i1 %cond, label %outer_latch, label %inner_header
44
45outer_latch:
46  %i.next = add i32 %i, -1
47  %cond2 = icmp sgt i32 %i.next, 13
48; This line is just for forcing widening of %i
49  call void @foo(i64 %i.64)
50  br i1 %cond2, label %outer_header, label %return
51
52return:
53  ret void
54}
55