1 ; RUN: llc -mtriple=arm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-ARM --check-prefix=CHECK-CMP
2 ; RUN: llc -mtriple=thumb-eabi %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-T --check-prefix=CHECK-CMP
3 ; RUN: llc -mtriple=thumb-eabi -mcpu=arm1156t2-s -mattr=+thumb2 %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-T2 --check-prefix=CHECK-CMP
6 ; Check for clipping against 0 that should result in bic
8 ; Base tests with different bit widths
13 define i32 @sat0_base_32bit(i32 %x) #0 {
14 ; CHECK-LABEL: sat0_base_32bit:
16 ; CHECK-ARM: bic {{r[0-9]}}, [[INPUT:r[0-9]]], [[INPUT]], asr #31
17 ; CHECK-T2: bic.w {{r[0-9]}}, [[INPUT:r[0-9]]], [[INPUT]], asr #31
18 ; CHECK-T: asrs [[IM:r[0-9]]], {{r[0-9]}}, #31
19 ; CHECK-T-NEXT: bics {{r[0-9]}}, [[IM]]
21 %cmpLow = icmp slt i32 %x, 0
22 %saturateLow = select i1 %cmpLow, i32 0, i32 %x
28 define i16 @sat0_base_16bit(i16 %x) #0 {
29 ; CHECK-LABEL: sat0_base_16bit:
35 %cmpLow = icmp slt i16 %x, 0
36 %saturateLow = select i1 %cmpLow, i16 0, i16 %x
42 define i8 @sat0_base_8bit(i8 %x) #0 {
43 ; CHECK-LABEL: sat0_base_8bit:
48 %cmpLow = icmp slt i8 %x, 0
49 %saturateLow = select i1 %cmpLow, i8 0, i8 %x
53 ; Test where the conditional is formed in a different way
56 define i32 @sat0_lower_1(i32 %x) #0 {
57 ; CHECK-LABEL: sat0_lower_1:
59 ; CHECK-ARM: bic {{r[0-9]}}, [[INPUT:r[0-9]]], [[INPUT]], asr #31
60 ; CHECK-T2: bic.w {{r[0-9]}}, [[INPUT:r[0-9]]], [[INPUT]], asr #31
61 ; CHECK-T: asrs [[IM:r[0-9]]], {{r[0-9]}}, #31
62 ; CHECK-T-NEXT: bics {{r[0-9]}}, [[IM]]
64 %cmpGt = icmp sgt i32 %x, 0
65 %saturateLow = select i1 %cmpGt, i32 %x, i32 0
70 ; Check for clipping against -1 that should result in orr
72 ; Base tests with different bit widths
77 define i32 @sat1_base_32bit(i32 %x) #0 {
78 ; CHECK-LABEL: sat1_base_32bit:
80 ; CHECK-ARM: orr {{r[0-9]}}, [[INPUT:r[0-9]]], [[INPUT]], asr #31
81 ; CHECK-T2: orr.w {{r[0-9]}}, [[INPUT:r[0-9]]], [[INPUT]], asr #31
82 ; CHECK-T: asrs [[IM:r[0-9]]], {{r[0-9]}}, #31
83 ; CHECK-T-NEXT: orrs {{r[0-9]}}, [[IM]]
85 %cmpLow = icmp slt i32 %x, -1
86 %saturateLow = select i1 %cmpLow, i32 -1, i32 %x
92 define i16 @sat1_base_16bit(i16 %x) #0 {
93 ; CHECK-LABEL: sat1_base_16bit:
98 %cmpLow = icmp slt i16 %x, -1
99 %saturateLow = select i1 %cmpLow, i16 -1, i16 %x
105 define i8 @sat1_base_8bit(i8 %x) #0 {
106 ; CHECK-LABEL: sat1_base_8bit:
111 %cmpLow = icmp slt i8 %x, -1
112 %saturateLow = select i1 %cmpLow, i8 -1, i8 %x
116 ; Test where the conditional is formed in a different way
119 define i32 @sat1_lower_1(i32 %x) #0 {
120 ; CHECK-LABEL: sat1_lower_1:
121 ; CHECK-ARM: orr {{r[0-9]}}, [[INPUT:r[0-9]]], [[INPUT]], asr #31
122 ; CHECK-T2: orr.w {{r[0-9]}}, [[INPUT:r[0-9]]], [[INPUT]], asr #31
123 ; CHECK-T: asrs [[IM:r[0-9]]], {{r[0-9]}}, #31
124 ; CHECK-T-NEXT: orrs {{r[0-9]}}, [[IM]]
127 %cmpGt = icmp sgt i32 %x, -1
128 %saturateLow = select i1 %cmpGt, i32 %x, i32 -1
132 ; The following tests for patterns that should not transform into bitops
133 ; but that are similar enough that could confuse the selector.
135 ; x < 0 ? 0 : y where x and y does not properly match
136 define i32 @no_sat0_incorrect_variable(i32 %x, i32 %y) #0 {
137 ; CHECK-LABEL: no_sat0_incorrect_variable:
142 %cmpLow = icmp slt i32 %x, 0
143 %saturateLow = select i1 %cmpLow, i32 0, i32 %y
148 define i32 @no_sat0_incorrect_constant(i32 %x) #0 {
149 ; CHECK-LABEL: no_sat0_incorrect_constant:
154 %cmpLow = icmp slt i32 %x, 0
155 %saturateLow = select i1 %cmpLow, i32 -1, i32 %x