1 ; RUN: llc < %s -mtriple=i686-- -relocation-model=pic | FileCheck %s
2 ; This test is to ensure the TwoAddrInstruction pass chooses the proper operands to
3 ; merge and generates fewer mov insns.
5 @M = common global i32 0, align 4
6 @total = common global i32 0, align 4
7 @g = common global i32 0, align 4
9 ; Function Attrs: nounwind uwtable
12 %0 = load i32, ptr @M, align 4
13 %cmp3 = icmp sgt i32 %0, 0
14 br i1 %cmp3, label %for.body.lr.ph, label %for.end
16 for.body.lr.ph: ; preds = %entry
17 %total.promoted = load i32, ptr @total, align 4
20 ; Check that only one mov will be generated in the kernel loop.
22 ; CHECK: [[LOOP1:^[a-zA-Z0-9_.]+]]: {{#.*}} %for.body{{$}}
24 ; CHECK: movl {{.*}}, [[REG1:%[a-z0-9]+]]
26 ; CHECK: shrl $31, [[REG1]]
29 for.body: ; preds = %for.body.lr.ph, %for.body
30 %add5 = phi i32 [ %total.promoted, %for.body.lr.ph ], [ %add, %for.body ]
31 %i.04 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
32 %div = sdiv i32 %i.04, 2
33 %add = add nsw i32 %div, %add5
34 %inc = add nuw nsw i32 %i.04, 1
35 %cmp = icmp slt i32 %inc, %0
36 br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
38 for.cond.for.end_crit_edge: ; preds = %for.body
39 store i32 %add, ptr @total, align 4
42 for.end: ; preds = %for.cond.for.end_crit_edge, %entry
46 ; Function Attrs: nounwind uwtable
49 %0 = load i32, ptr @M, align 4
50 %cmp3 = icmp sgt i32 %0, 0
51 br i1 %cmp3, label %for.body.lr.ph, label %for.end
53 for.body.lr.ph: ; preds = %entry
54 %total.promoted = load i32, ptr @total, align 4
57 ; Check that only two mov will be generated in the kernel loop.
59 ; CHECK: [[LOOP2:^[a-zA-Z0-9_.]+]]: {{#.*}} %for.body{{$}}
61 ; CHECK: movl {{.*}}, [[REG2:%[a-z0-9]+]]
63 ; CHECK: shrl $31, [[REG2]]
67 for.body: ; preds = %for.body.lr.ph, %for.body
68 %add5 = phi i32 [ %total.promoted, %for.body.lr.ph ], [ %add, %for.body ]
69 %i.04 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
70 %div = sdiv i32 %i.04, 2
71 %add = add nsw i32 %div, %add5
72 store volatile i32 %add, ptr @g, align 4
73 %inc = add nuw nsw i32 %i.04, 1
74 %cmp = icmp slt i32 %inc, %0
75 br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
77 for.cond.for.end_crit_edge: ; preds = %for.body
78 store i32 %add, ptr @total, align 4
81 for.end: ; preds = %for.cond.for.end_crit_edge, %entry