Home | History | Annotate | Download | only in X86
      1 ; RUN: llc < %s -march=x86-64 -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.
      4 
      5 @M = common global i32 0, align 4
      6 @total = common global i32 0, align 4
      7 @g = common global i32 0, align 4
      8 
      9 ; Function Attrs: nounwind uwtable
     10 define void @foo() {
     11 entry:
     12   %0 = load i32, i32* @M, align 4
     13   %cmp3 = icmp sgt i32 %0, 0
     14   br i1 %cmp3, label %for.body.lr.ph, label %for.end
     15 
     16 for.body.lr.ph:                                   ; preds = %entry
     17   %total.promoted = load i32, i32* @total, align 4
     18   br label %for.body
     19 
     20 ; Check that only one mov will be generated in the kernel loop.
     21 ; CHECK-LABEL: foo:
     22 ; CHECK: [[LOOP1:^[a-zA-Z0-9_.]+]]: {{#.*}} %for.body
     23 ; CHECK-NOT: mov
     24 ; CHECK: movl {{.*}}, [[REG1:%[a-z0-9]+]]
     25 ; CHECK-NOT: mov
     26 ; CHECK: shrl $31, [[REG1]]
     27 ; CHECK-NOT: mov
     28 ; CHECK: jl [[LOOP1]]
     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
     37 
     38 for.cond.for.end_crit_edge:                       ; preds = %for.body
     39   store i32 %add, i32* @total, align 4
     40   br label %for.end
     41 
     42 for.end:                                          ; preds = %for.cond.for.end_crit_edge, %entry
     43   ret void
     44 }
     45 
     46 ; Function Attrs: nounwind uwtable
     47 define void @goo() {
     48 entry:
     49   %0 = load i32, i32* @M, align 4
     50   %cmp3 = icmp sgt i32 %0, 0
     51   br i1 %cmp3, label %for.body.lr.ph, label %for.end
     52 
     53 for.body.lr.ph:                                   ; preds = %entry
     54   %total.promoted = load i32, i32* @total, align 4
     55   br label %for.body
     56 
     57 ; Check that only two mov will be generated in the kernel loop.
     58 ; CHECK-LABEL: goo:
     59 ; CHECK: [[LOOP2:^[a-zA-Z0-9_.]+]]: {{#.*}} %for.body
     60 ; CHECK-NOT: mov
     61 ; CHECK: movl {{.*}}, [[REG2:%[a-z0-9]+]]
     62 ; CHECK-NOT: mov
     63 ; CHECK: shrl $31, [[REG2]]
     64 ; CHECK-NOT: mov
     65 ; CHECK: movl {{.*}}
     66 ; CHECK: jl [[LOOP2]]
     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, i32* @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
     76 
     77 for.cond.for.end_crit_edge:                       ; preds = %for.body
     78   store i32 %add, i32* @total, align 4
     79   br label %for.end
     80 
     81 for.end:                                          ; preds = %for.cond.for.end_crit_edge, %entry
     82   ret void
     83 }
     84 
     85