1 ; RUN: opt -indvars -S < %s | FileCheck %s
3 define void @test0(i32* %x) {
7 for.inc: ; preds = %for.inc, %entry
8 %i.01 = phi i32 [ 0, %entry ], [ %add, %for.inc ]
9 %and = and i32 %i.01, 3
10 %cmp1 = icmp eq i32 %and, 0
11 %cond = select i1 %cmp1, i32 0, i32 1
12 store i32 %cond, i32* %x, align 4
13 %add = add i32 %i.01, 4
14 %cmp = icmp ult i32 %add, 8
15 br i1 %cmp, label %for.inc, label %for.end
17 for.end: ; preds = %for.inc
21 ; Should fold the condition of the select into constant
22 ; CHECK-LABEL: void @test0(
23 ; CHECK: icmp eq i32 0, 0
25 define void @test1(i32* %a) {
29 for.body: ; preds = %entry, %for.body
30 %i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
31 %mul = mul nsw i32 %i.01, 64
32 %rem = srem i32 %mul, 8
33 %idxprom = sext i32 %rem to i64
34 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom
35 store i32 %i.01, i32* %arrayidx, align 4
36 %inc = add nsw i32 %i.01, 1
37 %cmp = icmp slt i32 %inc, 64
38 br i1 %cmp, label %for.body, label %for.end
40 for.end: ; preds = %for.body
44 ; Should fold the rem since %mul is multiple of 8
45 ; CHECK-LABEL: @test1(
47 ; CHECK: sext i32 0 to i64