Teach IndVarSimplify how to eliminate comparisons involving induction
[oota-llvm.git] / test / Transforms / IndVarSimplify / eliminate-comparison.ll
1 ; RUN: opt -indvars -S < %s | FileCheck %s
2
3 ; Indvars should be able to simplify simple comparisons involving
4 ; induction variables.
5
6 ; CHECK: %cond = and i1 %tobool.not, true
7
8 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
9
10 @X = external global [0 x double]
11
12 define void @foo(i64 %n, i32* nocapture %p) nounwind {
13 entry:
14   %cmp9 = icmp sgt i64 %n, 0
15   br i1 %cmp9, label %pre, label %return
16
17 pre:
18   %t3 = load i32* %p
19   %tobool.not = icmp ne i32 %t3, 0
20   br label %loop
21
22 loop:
23   %i = phi i64 [ 0, %pre ], [ %inc, %for.inc ]
24   %cmp6 = icmp slt i64 %i, %n
25   %cond = and i1 %tobool.not, %cmp6
26   br i1 %cond, label %if.then, label %for.inc
27
28 if.then:
29   %arrayidx = getelementptr [0 x double]* @X, i64 0, i64 %i
30   store double 3.200000e+00, double* %arrayidx
31   br label %for.inc
32
33 for.inc:
34   %inc = add nsw i64 %i, 1
35   %exitcond = icmp sge i64 %inc, %n
36   br i1 %exitcond, label %return, label %loop
37
38 return:
39   ret void
40 }