Home | History | Annotate | Download | only in X86
      1 ; RUN: llc < %s -o - -mcpu=generic -mtriple=x86_64-apple-darwin -mattr=+sse2 | FileCheck %s
      2 ; RUN: llc < %s -o - -mcpu=generic -mtriple=x86_64-apple-darwin -mattr=+sse4.2 | FileCheck %s
      3 
      4 ; For a setult against a constant, turn it into a setule and lower via psubusw.
      5 
      6 define void @loop_no_const_reload(<2 x i64>*  %in, <2 x i64>* %out, i32 %n) {
      7 ; CHECK: .short 25
      8 ; CHECK-NEXT: .short 25
      9 ; CHECK-NEXT: .short 25
     10 ; CHECK-NEXT: .short 25
     11 ; CHECK-NEXT: .short 25
     12 ; CHECK-NEXT: .short 25
     13 ; CHECK-NEXT: .short 25
     14 ; CHECK-NEXT: .short 25
     15 ; CHECK-LABEL: loop_no_const_reload:
     16 ; CHECK: psubusw
     17 
     18 ; Constant is no longer clobbered so no need to reload it in the loop.
     19 
     20 ; CHECK-NOT: movdqa {{%xmm[0-9]+}}, {{%xmm[0-9]+}}
     21 
     22 entry:
     23   %cmp9 = icmp eq i32 %n, 0
     24   br i1 %cmp9, label %for.end, label %for.body
     25 
     26 for.body:                                         ; preds = %for.body, %entry
     27   %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
     28   %arrayidx1 = getelementptr inbounds <2 x i64>, <2 x i64>* %in, i64 %indvars.iv
     29   %arrayidx1.val = load <2 x i64>, <2 x i64>* %arrayidx1, align 16
     30   %0 = bitcast <2 x i64> %arrayidx1.val to <8 x i16>
     31   %cmp.i.i = icmp ult <8 x i16> %0, <i16 26, i16 26, i16 26, i16 26, i16 26, i16 26, i16 26, i16 26>
     32   %sext.i.i = sext <8 x i1> %cmp.i.i to <8 x i16>
     33   %1 = bitcast <8 x i16> %sext.i.i to <2 x i64>
     34   %arrayidx5 = getelementptr inbounds <2 x i64>, <2 x i64>* %out, i64 %indvars.iv
     35   store <2 x i64> %1, <2 x i64>* %arrayidx5, align 16
     36   %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
     37   %lftr.wideiv = trunc i64 %indvars.iv.next to i32
     38   %exitcond = icmp eq i32 %lftr.wideiv, %n
     39   br i1 %exitcond, label %for.end, label %for.body
     40 
     41 for.end:                                          ; preds = %for.body, %entry
     42   ret void
     43 }
     44 
     45 ; Be careful if decrementing the constant would undeflow.
     46 
     47 define void @loop_const_folding_underflow(<2 x i64>*  %in, <2 x i64>* %out, i32 %n) {
     48 ; CHECK-NOT: .short 25
     49 ; CHECK-LABEL: loop_const_folding_underflow:
     50 ; CHECK-NOT: psubusw
     51 entry:
     52   %cmp9 = icmp eq i32 %n, 0
     53   br i1 %cmp9, label %for.end, label %for.body
     54 
     55 for.body:                                         ; preds = %for.body, %entry
     56   %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
     57   %arrayidx1 = getelementptr inbounds <2 x i64>, <2 x i64>* %in, i64 %indvars.iv
     58   %arrayidx1.val = load <2 x i64>, <2 x i64>* %arrayidx1, align 16
     59   %0 = bitcast <2 x i64> %arrayidx1.val to <8 x i16>
     60   %cmp.i.i = icmp ult <8 x i16> %0, <i16 0, i16 26, i16 26, i16 26, i16 26, i16 26, i16 26, i16 26>
     61   %sext.i.i = sext <8 x i1> %cmp.i.i to <8 x i16>
     62   %1 = bitcast <8 x i16> %sext.i.i to <2 x i64>
     63   %arrayidx5 = getelementptr inbounds <2 x i64>, <2 x i64>* %out, i64 %indvars.iv
     64   store <2 x i64> %1, <2 x i64>* %arrayidx5, align 16
     65   %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
     66   %lftr.wideiv = trunc i64 %indvars.iv.next to i32
     67   %exitcond = icmp eq i32 %lftr.wideiv, %n
     68   br i1 %exitcond, label %for.end, label %for.body
     69 
     70 for.end:                                          ; preds = %for.body, %entry
     71   ret void
     72 }
     73 
     74 ; Test for PSUBUSB
     75 
     76 define <16 x i8> @test_ult_byte(<16 x i8> %a) {
     77 ; CHECK: .space 16,10
     78 ; CHECK-LABEL: test_ult_byte:
     79 ; CHECK: psubus
     80 entry:
     81   %icmp = icmp ult <16 x i8> %a, <i8 11, i8 11, i8 11, i8 11, i8 11, i8 11, i8 11, i8 11, i8 11, i8 11, i8 11, i8 11, i8 11, i8 11, i8 11, i8 11>
     82   %sext = sext <16 x i1> %icmp to <16 x i8>
     83   ret <16 x i8> %sext
     84 }
     85 
     86 ; Only do this when we can turn the comparison into a setule.  I.e. not for
     87 ; register operands.
     88 
     89 define <8 x i16> @test_ult_register(<8 x i16> %a, <8 x i16> %b) {
     90 ; CHECK-LABEL: test_ult_register:
     91 ; CHECK-NOT: psubus
     92 entry:
     93   %icmp = icmp ult <8 x i16> %a, %b
     94   %sext = sext <8 x i1> %icmp to <8 x i16>
     95   ret <8 x i16> %sext
     96 }
     97