Home | History | Annotate | Download | only in InstCombine
      1 ; RUN: opt < %s -instcombine -S | FileCheck %s
      2 
      3 define void @f(i64 %val, i32  %limit, i32 *%ptr) {
      4 ; CHECK-LABEL: @f
      5 ; CHECK: %0 = trunc i64 %val to i32
      6 ; CHECK: %1 = phi i32 [ %0, %entry ], [ {{.*}}, %loop ]
      7 entry:
      8   %tempvector = insertelement <16 x i64> undef, i64 %val, i32 0
      9   %vector = shufflevector <16 x i64> %tempvector, <16 x i64> undef, <16 x i32> zeroinitializer
     10   %0 = add <16 x i64> %vector, <i64 0, i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7, i64 8, i64 9, i64 10, i64 11, i64 12, i64 13, i64 14, i64 15>
     11   %1 = trunc <16 x i64> %0 to <16 x i32>
     12   br label %loop
     13 
     14 loop:
     15   %2 = phi <16 x i32> [ %1, %entry ], [ %inc, %loop ]
     16   %elt = extractelement <16 x i32> %2, i32 0
     17   %end = icmp ult i32 %elt, %limit
     18   %3 = add i32 10, %elt
     19   %4 = sext i32 %elt to i64
     20   %5 = getelementptr i32, i32* %ptr, i64 %4
     21   store i32 %3, i32* %5
     22   %inc = add <16 x i32> %2, <i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16>
     23   br i1 %end, label %loop, label %ret
     24 
     25 ret:
     26   ret void
     27 }
     28 
     29 define void @copy(i64 %val, i32  %limit, i32 *%ptr) {
     30 ; CHECK-LABEL: @copy
     31 ; CHECK: %0 = trunc i64 %val to i32
     32 ; CHECK: %1 = phi i32 [ %0, %entry ], [ {{.*}}, %loop ]
     33 entry:
     34   %tempvector = insertelement <16 x i64> undef, i64 %val, i32 0
     35   %vector = shufflevector <16 x i64> %tempvector, <16 x i64> undef, <16 x i32> zeroinitializer
     36   %0 = add <16 x i64> %vector, <i64 0, i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7, i64 8, i64 9, i64 10, i64 11, i64 12, i64 13, i64 14, i64 15>
     37   %1 = trunc <16 x i64> %0 to <16 x i32>
     38   br label %loop
     39 
     40 loop:
     41   %2 = phi <16 x i32> [ %1, %entry ], [ %inc, %loop ]
     42   %elt = extractelement <16 x i32> %2, i32 0
     43   %eltcopy = extractelement <16 x i32> %2, i32 0
     44   %end = icmp ult i32 %elt, %limit
     45   %3 = add i32 10, %eltcopy
     46   %4 = sext i32 %elt to i64
     47   %5 = getelementptr i32, i32* %ptr, i64 %4
     48   store i32 %3, i32* %5
     49   %inc = add <16 x i32> %2, <i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16>
     50   br i1 %end, label %loop, label %ret
     51 
     52 ret:
     53   ret void
     54 }
     55 
     56 define void @nocopy(i64 %val, i32  %limit, i32 *%ptr) {
     57 ; CHECK-LABEL: @nocopy
     58 ; CHECK-NOT: phi i32
     59 ; CHECK: phi <16 x i32> [ %1, %entry ], [ %inc, %loop ]
     60 entry:
     61   %tempvector = insertelement <16 x i64> undef, i64 %val, i32 0
     62   %vector = shufflevector <16 x i64> %tempvector, <16 x i64> undef, <16 x i32> zeroinitializer
     63   %0 = add <16 x i64> %vector, <i64 0, i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7, i64 8, i64 9, i64 10, i64 11, i64 12, i64 13, i64 14, i64 15>
     64   %1 = trunc <16 x i64> %0 to <16 x i32>
     65   br label %loop
     66 
     67 loop:
     68   %2 = phi <16 x i32> [ %1, %entry ], [ %inc, %loop ]
     69   %elt = extractelement <16 x i32> %2, i32 0
     70   %eltcopy = extractelement <16 x i32> %2, i32 1
     71   %end = icmp ult i32 %elt, %limit
     72   %3 = add i32 10, %eltcopy
     73   %4 = sext i32 %elt to i64
     74   %5 = getelementptr i32, i32* %ptr, i64 %4
     75   store i32 %3, i32* %5
     76   %inc = add <16 x i32> %2, <i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16>
     77   br i1 %end, label %loop, label %ret
     78 
     79 ret:
     80   ret void
     81 }
     82 
     83 define i1 @g(<3 x i32> %input_2) {
     84 ; CHECK-LABEL: @g
     85 ; CHECK: extractelement <3 x i32> %input_2, i32 0
     86 entry:
     87   br label %for.cond
     88 
     89 for.cond:
     90   %input_2.addr.0 = phi <3 x i32> [ %input_2, %entry ], [ %div45, %for.body ]
     91   %input_1.addr.1 = phi <3 x i32> [ undef, %entry ], [ %dec43, %for.body ]
     92   br i1 undef, label %for.end, label %for.body
     93 
     94 ; CHECK: extractelement <3 x i32> %{{.*}}, i32 0
     95 for.body:
     96   %dec43 = add <3 x i32> %input_1.addr.1, <i32 -1, i32 -1, i32 -1>
     97   %sub44 = sub <3 x i32> <i32 -1, i32 -1, i32 -1>, %dec43
     98   %div45 = sdiv <3 x i32> %input_2.addr.0, %sub44
     99   br label %for.cond
    100 
    101 for.end:
    102   %0 = extractelement <3 x i32> %input_2.addr.0, i32 0
    103   %.89 = select i1 false, i32 0, i32 %0
    104   %tobool313 = icmp eq i32 %.89, 0
    105   ret i1 %tobool313
    106 }
    107 
    108