Add early if-conversion support to X86.
[oota-llvm.git] / test / CodeGen / X86 / early-ifcvt.ll
1 ; RUN: llc < %s -enable-early-ifcvt -stress-early-ifcvt | FileCheck %s
2 target triple = "x86_64-apple-macosx10.8.0"
3
4 ; CHECK: mm2
5 define i32 @mm2(i32* nocapture %p, i32 %n) nounwind uwtable readonly ssp {
6 entry:
7   br label %do.body
8
9 ; CHECK: do.body
10 ; Loop body has no branches before the backedge.
11 ; CHECK-NOT: LBB
12 do.body:
13   %max.0 = phi i32 [ 0, %entry ], [ %max.1, %do.cond ]
14   %min.0 = phi i32 [ 0, %entry ], [ %min.1, %do.cond ]
15   %n.addr.0 = phi i32 [ %n, %entry ], [ %dec, %do.cond ]
16   %p.addr.0 = phi i32* [ %p, %entry ], [ %incdec.ptr, %do.cond ]
17   %incdec.ptr = getelementptr inbounds i32* %p.addr.0, i64 1
18   %0 = load i32* %p.addr.0, align 4
19   %cmp = icmp sgt i32 %0, %max.0
20   br i1 %cmp, label %do.cond, label %if.else
21
22 if.else:
23   %cmp1 = icmp slt i32 %0, %min.0
24   %.min.0 = select i1 %cmp1, i32 %0, i32 %min.0
25   br label %do.cond
26
27 do.cond:
28   %max.1 = phi i32 [ %0, %do.body ], [ %max.0, %if.else ]
29   %min.1 = phi i32 [ %min.0, %do.body ], [ %.min.0, %if.else ]
30 ; CHECK: decl %esi
31 ; CHECK: jne LBB
32   %dec = add i32 %n.addr.0, -1
33   %tobool = icmp eq i32 %dec, 0
34   br i1 %tobool, label %do.end, label %do.body
35
36 do.end:
37   %sub = sub nsw i32 %max.1, %min.1
38   ret i32 %sub
39 }